2012-11-03 01:03:12 +00:00
|
|
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
|
|
|
|
2012-11-13 01:42:30 +00:00
|
|
|
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
|
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;
|
|
|
|
|
2013-03-19 22:05:20 +00:00
|
|
|
@CommandPermissions(level = AdminLevel.ALL, 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]")
|
2012-11-03 01:03:12 +00:00
|
|
|
public class Command_cartsit extends TFM_Command
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
|
|
|
{
|
|
|
|
Player target_player = sender_p;
|
|
|
|
|
|
|
|
if (args.length == 1)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
target_player = getPlayer(args[0]);
|
|
|
|
}
|
2013-08-14 13:12:30 +00:00
|
|
|
catch (PlayerNotFoundException e)
|
2012-11-03 01:03:12 +00:00
|
|
|
{
|
2013-08-14 13:12:30 +00:00
|
|
|
sender.sendMessage(e.getMessage());
|
2012-11-03 01:03:12 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (senderIsConsole)
|
|
|
|
{
|
|
|
|
if (target_player == null)
|
|
|
|
{
|
|
|
|
sender.sendMessage("When used from the console, you must define a target player: /cartsit <player>");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2012-11-13 01:42:30 +00:00
|
|
|
else if (target_player != sender_p && !TFM_SuperadminList.isUserSuperadmin(sender))
|
2012-11-03 01:03:12 +00:00
|
|
|
{
|
|
|
|
sender.sendMessage("Only superadmins can select another player as a /cartsit target.");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (target_player.isInsideVehicle())
|
|
|
|
{
|
|
|
|
target_player.getVehicle().eject();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Minecart nearest_cart = null;
|
|
|
|
for (Minecart cart : target_player.getWorld().getEntitiesByClass(Minecart.class))
|
|
|
|
{
|
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
|
|
|
|
{
|
|
|
|
if (cart.getLocation().distanceSquared(target_player.getLocation()) < nearest_cart.getLocation().distanceSquared(target_player.getLocation()))
|
|
|
|
{
|
|
|
|
nearest_cart = cart;
|
|
|
|
}
|
|
|
|
}
|
2012-11-03 01:03:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nearest_cart != null)
|
|
|
|
{
|
|
|
|
nearest_cart.setPassenger(target_player);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-03 19:03:38 +00:00
|
|
|
sender.sendMessage("There are no empty minecarts in the target world.");
|
2012-11-03 01:03:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|