TFM-4.3-Reloaded/src/main/java/me/StevenLawson/TotalFreedomMod/commands/Command_cartsit.java

77 lines
2.4 KiB
Java
Raw Normal View History

2022-03-20 12:35:43 +00:00
package me.StevenLawson.TotalFreedomMod.commands;
2022-03-20 12:35:43 +00:00
import me.StevenLawson.TotalFreedomMod.admin.AdminList;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Minecart;
import org.bukkit.entity.Player;
@CommandPermissions(level = AdminLevel.ALL, source = SourceType.BOTH)
2022-03-20 12:35:43 +00:00
public class Command_cartsit extends FreedomCommand {
@Override
2022-03-20 12:35:43 +00:00
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
2013-08-14 14:55:37 +00:00
Player targetPlayer = sender_p;
2022-03-20 12:35:43 +00:00
if (args.length == 1) {
targetPlayer = getPlayer(args[0]);
2022-03-20 12:35:43 +00:00
if (targetPlayer == null) {
sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND);
return true;
}
}
if (senderIsConsole)
{
2013-08-14 14:55:37 +00:00
if (targetPlayer == null)
{
sender.sendMessage("When used from the console, you must define a target player: /cartsit <player>");
return true;
}
}
2022-03-20 12:35:43 +00:00
else if (targetPlayer != sender_p && !AdminList.isSuperAdmin(sender))
{
sender.sendMessage("Only superadmins can select another player as a /cartsit target.");
return true;
}
2013-08-14 14:55:37 +00:00
if (targetPlayer.isInsideVehicle())
{
2013-08-14 14:55:37 +00:00
targetPlayer.getVehicle().eject();
}
else
{
Minecart nearest_cart = null;
2013-08-14 14:55:37 +00:00
for (Minecart cart : targetPlayer.getWorld().getEntitiesByClass(Minecart.class))
{
if (cart.isEmpty())
{
if (nearest_cart == null)
{
nearest_cart = cart;
}
else
{
2013-08-14 14:55:37 +00:00
if (cart.getLocation().distanceSquared(targetPlayer.getLocation()) < nearest_cart.getLocation().distanceSquared(targetPlayer.getLocation()))
{
nearest_cart = cart;
}
}
}
}
if (nearest_cart != null)
{
2013-08-14 14:55:37 +00:00
nearest_cart.setPassenger(targetPlayer);
}
else
{
sender.sendMessage("There are no empty minecarts in the target world.");
}
}
return true;
}
}