Search in sources :

Example 1 with ManOverboardEvent

use of net.countercraft.movecraft.events.ManOverboardEvent in project Movecraft by APDevTeam.

the class ManOverboardCommand method onCommand.

@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
    if (!command.getName().equalsIgnoreCase("manOverBoard"))
        return false;
    if (!(commandSender instanceof Player)) {
        commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("ManOverboard - Must Be Player"));
        return true;
    }
    Player player = (Player) commandSender;
    Craft craft = CraftManager.getInstance().getCraftByPlayerName(player.getName());
    if (craft == null) {
        player.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("ManOverboard - No Craft Found"));
        return true;
    }
    Location telPoint = getCraftTeleportPoint(craft);
    if (craft.getWorld() != player.getWorld()) {
        player.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("ManOverboard - Other World"));
        return true;
    }
    if ((System.currentTimeMillis() - CraftManager.getInstance().getTimeFromOverboard(player)) / 1_000 > Settings.ManOverboardTimeout && !MathUtils.locIsNearCraftFast(craft, MathUtils.bukkit2MovecraftLoc(player.getLocation()))) {
        player.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("ManOverboard - Timed Out"));
        return true;
    }
    if (telPoint.distanceSquared(player.getLocation()) > Settings.ManOverboardDistSquared) {
        player.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("ManOverboard - Distance Too Far"));
        return true;
    }
    if (craft.getDisabled() || craft instanceof SinkingCraft) {
        player.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("ManOverboard - Disabled"));
        return true;
    }
    ManOverboardEvent event = new ManOverboardEvent(craft, telPoint);
    Bukkit.getServer().getPluginManager().callEvent(event);
    player.setVelocity(new Vector(0, 0, 0));
    player.setFallDistance(0);
    player.teleport(telPoint);
    return true;
}
Also used : ManOverboardEvent(net.countercraft.movecraft.events.ManOverboardEvent) SinkingCraft(net.countercraft.movecraft.craft.SinkingCraft) Player(org.bukkit.entity.Player) SinkingCraft(net.countercraft.movecraft.craft.SinkingCraft) Craft(net.countercraft.movecraft.craft.Craft) PilotedCraft(net.countercraft.movecraft.craft.PilotedCraft) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

Aggregations

Craft (net.countercraft.movecraft.craft.Craft)1 PilotedCraft (net.countercraft.movecraft.craft.PilotedCraft)1 SinkingCraft (net.countercraft.movecraft.craft.SinkingCraft)1 ManOverboardEvent (net.countercraft.movecraft.events.ManOverboardEvent)1 Location (org.bukkit.Location)1 Player (org.bukkit.entity.Player)1 Vector (org.bukkit.util.Vector)1