2016-03-02 19:28:01 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.command;
|
2012-11-03 01:03:12 +00:00
|
|
|
|
2016-03-06 15:56:15 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.rank.Rank;
|
2012-11-03 01:03:12 +00:00
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Minecart;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2016-03-06 15:56:15 +00:00
|
|
|
@CommandPermissions(level = Rank.NON_OP, source = SourceType.BOTH)
|
2013-04-10 02:05:24 +00:00
|
|
|
@CommandParameters(description = "Sit in nearest minecart. If target is in a minecart already, they will disembark.", usage = "/<command> [partialname]")
|
2015-10-19 17:43:46 +00:00
|
|
|
public class Command_cartsit extends FreedomCommand
|
2012-11-03 01:03:12 +00:00
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
|
2012-11-03 01:03:12 +00:00
|
|
|
@Override
|
2015-11-22 18:26:47 +00:00
|
|
|
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
2012-11-03 01:03:12 +00:00
|
|
|
{
|
2015-11-22 18:26:47 +00:00
|
|
|
Player targetPlayer = playerSender;
|
2012-11-03 01:03:12 +00:00
|
|
|
|
|
|
|
if (args.length == 1)
|
|
|
|
{
|
2014-04-26 11:55:24 +00:00
|
|
|
|
|
|
|
targetPlayer = getPlayer(args[0]);
|
|
|
|
|
|
|
|
if (targetPlayer == null)
|
2012-11-03 01:03:12 +00:00
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND);
|
2012-11-03 01:03:12 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (senderIsConsole)
|
|
|
|
{
|
2013-08-14 14:55:37 +00:00
|
|
|
if (targetPlayer == null)
|
2012-11-03 01:03:12 +00:00
|
|
|
{
|
|
|
|
sender.sendMessage("When used from the console, you must define a target player: /cartsit <player>");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2015-11-22 18:26:47 +00:00
|
|
|
else if (targetPlayer != playerSender && !isAdmin(sender))
|
2012-11-03 01:03:12 +00:00
|
|
|
{
|
2018-03-10 20:51:19 +00:00
|
|
|
sender.sendMessage("Only admins can select another player as a /cartsit target.");
|
2012-11-03 01:03:12 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-14 14:55:37 +00:00
|
|
|
if (targetPlayer.isInsideVehicle())
|
2012-11-03 01:03:12 +00:00
|
|
|
{
|
2013-08-14 14:55:37 +00:00
|
|
|
targetPlayer.getVehicle().eject();
|
2012-11-03 01:03:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Minecart nearest_cart = null;
|
2013-08-14 14:55:37 +00:00
|
|
|
for (Minecart cart : targetPlayer.getWorld().getEntitiesByClass(Minecart.class))
|
2012-11-03 01:03:12 +00:00
|
|
|
{
|
2012-11-03 19:03:38 +00:00
|
|
|
if (cart.isEmpty())
|
2012-11-03 01:03:12 +00:00
|
|
|
{
|
2012-11-03 19:03:38 +00:00
|
|
|
if (nearest_cart == null)
|
2012-11-03 01:03:12 +00:00
|
|
|
{
|
|
|
|
nearest_cart = cart;
|
|
|
|
}
|
2012-11-03 19:03:38 +00:00
|
|
|
else
|
|
|
|
{
|
2013-08-14 14:55:37 +00:00
|
|
|
if (cart.getLocation().distanceSquared(targetPlayer.getLocation()) < nearest_cart.getLocation().distanceSquared(targetPlayer.getLocation()))
|
2012-11-03 19:03:38 +00:00
|
|
|
{
|
|
|
|
nearest_cart = cart;
|
|
|
|
}
|
|
|
|
}
|
2012-11-03 01:03:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nearest_cart != null)
|
|
|
|
{
|
2018-03-10 20:51:19 +00:00
|
|
|
nearest_cart.addPassenger(targetPlayer);
|
2012-11-03 01:03:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-03-10 20:51:19 +00:00
|
|
|
msg("There are no empty minecarts in the target world.");
|
2012-11-03 01:03:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|