TotalFreedomMod/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_orbit.java

72 lines
2.5 KiB
Java

package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.command.handling.CommandParameters;
import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions;
import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand;
import me.totalfreedom.totalfreedommod.command.handling.SourceType;
import me.totalfreedom.totalfreedommod.player.FPlayer;
import me.totalfreedom.totalfreedommod.punishments.Punishment;
import me.totalfreedom.totalfreedommod.punishments.PunishmentType;
import me.totalfreedom.totalfreedommod.util.FUtil;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import org.bukkit.GameMode;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
@CommandPermissions(permission = "orbit", source = SourceType.BOTH)
@CommandParameters(description = "POW!!! Right in the kisser! One of these days Alice, straight to the Moon - Sends the specified player into orbit.",
usage = "/<command> <target> [<<power> | stop>]")
public class Command_orbit extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length == 0)
{
return false;
}
Player player = getPlayer(args[0]);
if (player == null)
{
msg(PLAYER_NOT_FOUND);
return true;
}
FPlayer playerdata = plugin.pl.getPlayer(player);
double strength = 10.0;
if (args.length >= 2)
{
if (args[1].equalsIgnoreCase("stop"))
{
msgNew("Stopped orbiting <player>", Placeholder.unparsed("player", player.getName()));
playerdata.stopOrbiting();
return true;
}
try
{
strength = Math.max(1.0, Math.min(150.0, Double.parseDouble(args[1])));
} catch (NumberFormatException ex)
{
msgNew("<red>" + ex.getMessage());
return true;
}
}
FUtil.adminAction(sender.getName(), "Orbiting " + player.getName(), false);
player.setGameMode(GameMode.SURVIVAL);
playerdata.startOrbiting(strength);
player.setVelocity(new Vector(0, strength, 0));
plugin.pul.logPunishment(new Punishment(player.getName(), FUtil.getIp(player), sender.getName(), PunishmentType.ORBIT, null));
return true;
}
}