mirror of
https://github.com/TheDeus-Group/TFM-4.3-Reloaded.git
synced 2024-11-01 01:19:26 +00:00
78 lines
2.2 KiB
Java
78 lines
2.2 KiB
Java
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
||
|
|
||
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||
|
import org.bukkit.command.Command;
|
||
|
import org.bukkit.command.CommandSender;
|
||
|
import org.bukkit.entity.Minecart;
|
||
|
import org.bukkit.entity.Player;
|
||
|
|
||
|
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]);
|
||
|
}
|
||
|
catch (CantFindPlayerException ex)
|
||
|
{
|
||
|
sender.sendMessage(ex.getMessage());
|
||
|
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;
|
||
|
}
|
||
|
}
|
||
|
else if (target_player != sender_p && !TFM_Util.isUserSuperadmin(sender))
|
||
|
{
|
||
|
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))
|
||
|
{
|
||
|
if (nearest_cart == null)
|
||
|
{
|
||
|
nearest_cart = cart;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (cart.getLocation().distance(target_player.getLocation()) < nearest_cart.getLocation().distance(target_player.getLocation()))
|
||
|
{
|
||
|
nearest_cart = cart;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (nearest_cart != null)
|
||
|
{
|
||
|
nearest_cart.setPassenger(target_player);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
sender.sendMessage("There are no minecarts in the target world.");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
}
|