Search in sources :

Example 6 with Craft

use of net.countercraft.movecraft.craft.Craft 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)

Example 7 with Craft

use of net.countercraft.movecraft.craft.Craft in project Movecraft by APDevTeam.

the class PilotCommand method onCommand.

@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
    if (!command.getName().equalsIgnoreCase("pilot"))
        return false;
    if (!(commandSender instanceof Player)) {
        commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Pilot - Must Be Player"));
        return true;
    }
    Player player = (Player) commandSender;
    if (!player.hasPermission("movecraft.commands") || !player.hasPermission("movecraft.commands.pilot")) {
        player.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Insufficient Permissions"));
        return true;
    }
    if (args.length < 1) {
        player.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Pilot - No Craft Type"));
        return true;
    }
    if (!player.hasPermission("movecraft." + args[0] + ".pilot")) {
        player.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Insufficient Permissions"));
        return true;
    }
    CraftType craftType = CraftManager.getInstance().getCraftTypeFromString(args[0]);
    if (craftType == null) {
        player.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Pilot - Invalid Craft Type"));
        return true;
    }
    final World world = player.getWorld();
    MovecraftLocation startPoint = MathUtils.bukkit2MovecraftLoc(player.getLocation());
    CraftManager.getInstance().detect(startPoint, craftType, (type, w, p, parents) -> {
        // Note: This only passes in a non-null player.
        assert p != null;
        if (parents.size() > 0)
            return new Pair<>(Result.failWithMessage(I18nSupport.getInternationalisedString("Detection - Failed - Already commanding a craft")), null);
        return new Pair<>(Result.succeed(), new PlayerCraftImpl(type, w, p));
    }, world, player, Movecraft.getAdventure().player(player), craft -> () -> {
        // Release old craft if it exists
        Craft oldCraft = CraftManager.getInstance().getCraftByPlayer(player);
        if (oldCraft != null)
            CraftManager.getInstance().release(oldCraft, CraftReleaseEvent.Reason.PLAYER, false);
    });
    return true;
}
Also used : Player(org.bukkit.entity.Player) PlayerCraftImpl(net.countercraft.movecraft.craft.PlayerCraftImpl) CruiseOnPilotCraft(net.countercraft.movecraft.craft.CruiseOnPilotCraft) CruiseOnPilotSubCraft(net.countercraft.movecraft.craft.CruiseOnPilotSubCraft) Craft(net.countercraft.movecraft.craft.Craft) World(org.bukkit.World) MovecraftLocation(net.countercraft.movecraft.MovecraftLocation) CraftType(net.countercraft.movecraft.craft.type.CraftType) Pair(net.countercraft.movecraft.util.Pair)

Example 8 with Craft

use of net.countercraft.movecraft.craft.Craft in project Movecraft by APDevTeam.

the class PlayerListener method onPlayerMove.

@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
    Player p = event.getPlayer();
    final Craft c = CraftManager.getInstance().getCraftByPlayer(p);
    if (c == null) {
        return;
    }
    highlights.computeIfAbsent(c, (craft) -> new LinkedList<>());
    if (MathUtils.locationNearHitBox(c.getHitBox(), p.getLocation(), 2)) {
        timeToReleaseAfter.remove(c);
        clearHighlights(c, p);
        return;
    }
    if (timeToReleaseAfter.containsKey(c) && timeToReleaseAfter.get(c) < System.currentTimeMillis()) {
        CraftManager.getInstance().release(c, CraftReleaseEvent.Reason.PLAYER, false);
        timeToReleaseAfter.remove(c);
        clearHighlights(c, p);
        return;
    }
    if (c.isNotProcessing() && c.getType().getBoolProperty(CraftType.MOVE_ENTITIES) && !timeToReleaseAfter.containsKey(c)) {
        if (Settings.ManOverboardTimeout != 0) {
            c.getAudience().sendActionBar(I18nSupport.getInternationalisedComponent("Manoverboard - Player has left craft"));
            CraftManager.getInstance().addOverboard(p);
        } else {
            p.sendMessage(I18nSupport.getInternationalisedString("Release - Player has left craft"));
        }
        var mergePoints = checkCraftBorders(c);
        if (!mergePoints.isEmpty())
            p.sendMessage(I18nSupport.getInternationalisedString("Manoverboard - Craft May Merge"));
        for (var location : mergePoints) {
            highlights.get(c).add(BlockHighlight.highlightBlockAt(location, p));
        }
        timeToReleaseAfter.put(c, System.currentTimeMillis() + c.getType().getIntProperty(CraftType.RELEASE_TIMEOUT) * 1000L);
    }
}
Also used : Player(org.bukkit.entity.Player) PlayerCraft(net.countercraft.movecraft.craft.PlayerCraft) Craft(net.countercraft.movecraft.craft.Craft) EventHandler(org.bukkit.event.EventHandler)

Example 9 with Craft

use of net.countercraft.movecraft.craft.Craft in project Movecraft by APDevTeam.

the class AscendSign method onSignClickEvent.

@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onSignClickEvent(@NotNull PlayerInteractEvent event) {
    if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
        return;
    }
    Block block = event.getClickedBlock();
    if (!(block.getState() instanceof Sign)) {
        return;
    }
    Sign sign = (Sign) event.getClickedBlock().getState();
    if (ChatColor.stripColor(sign.getLine(0)).equalsIgnoreCase("Ascend: OFF")) {
        if (CraftManager.getInstance().getCraftByPlayer(event.getPlayer()) == null) {
            return;
        }
        Craft c = CraftManager.getInstance().getCraftByPlayer(event.getPlayer());
        if (!c.getType().getBoolProperty(CraftType.CAN_CRUISE)) {
            return;
        }
        // c.resetSigns(true, false, true);
        sign.setLine(0, "Ascend: ON");
        sign.update(true);
        c.setCruiseDirection(CruiseDirection.UP);
        c.setLastCruiseUpdate(System.currentTimeMillis());
        c.setCruising(true);
        c.resetSigns(sign);
        if (!c.getType().getBoolProperty(CraftType.MOVE_ENTITIES)) {
            CraftManager.getInstance().addReleaseTask(c);
        }
        return;
    }
    if (!ChatColor.stripColor(sign.getLine(0)).equalsIgnoreCase("Ascend: ON")) {
        return;
    }
    Craft c = CraftManager.getInstance().getCraftByPlayer(event.getPlayer());
    if (c == null || !c.getType().getBoolProperty(CraftType.CAN_CRUISE)) {
        return;
    }
    sign.setLine(0, "Ascend: OFF");
    sign.update(true);
    c.setCruising(false);
    c.resetSigns(sign);
}
Also used : Craft(net.countercraft.movecraft.craft.Craft) Block(org.bukkit.block.Block) Sign(org.bukkit.block.Sign) EventHandler(org.bukkit.event.EventHandler)

Example 10 with Craft

use of net.countercraft.movecraft.craft.Craft in project Movecraft by APDevTeam.

the class ContactsSign method onSignTranslateEvent.

@EventHandler
public final void onSignTranslateEvent(SignTranslateEvent event) {
    String[] lines = event.getLines();
    Craft craft = event.getCraft();
    if (!ChatColor.stripColor(lines[0]).equalsIgnoreCase("Contacts:")) {
        return;
    }
    int signLine = 1;
    for (Craft tcraft : craft.getContacts()) {
        MovecraftLocation center = craft.getHitBox().getMidPoint();
        MovecraftLocation tcenter = tcraft.getHitBox().getMidPoint();
        int distsquared = center.distanceSquared(tcenter);
        // craft has been detected
        String notification = ChatColor.BLUE + tcraft.getType().getStringProperty(CraftType.NAME);
        if (notification.length() > 9) {
            notification = notification.substring(0, 7);
        }
        notification += " " + (int) Math.sqrt(distsquared);
        int diffx = center.getX() - tcenter.getX();
        int diffz = center.getZ() - tcenter.getZ();
        if (Math.abs(diffx) > Math.abs(diffz)) {
            if (diffx < 0) {
                notification += " E";
            } else {
                notification += " W";
            }
        } else {
            if (diffz < 0) {
                notification += " S";
            } else {
                notification += " N";
            }
        }
        lines[signLine++] = notification;
        if (signLine >= 4) {
            break;
        }
    }
    if (signLine < 4) {
        for (int i = signLine; i < 4; i++) {
            lines[signLine] = "";
        }
    }
}
Also used : Craft(net.countercraft.movecraft.craft.Craft) MovecraftLocation(net.countercraft.movecraft.MovecraftLocation) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Craft (net.countercraft.movecraft.craft.Craft)42 EventHandler (org.bukkit.event.EventHandler)22 MovecraftLocation (net.countercraft.movecraft.MovecraftLocation)19 Player (org.bukkit.entity.Player)14 SinkingCraft (net.countercraft.movecraft.craft.SinkingCraft)13 Sign (org.bukkit.block.Sign)12 PilotedCraft (net.countercraft.movecraft.craft.PilotedCraft)11 BlockState (org.bukkit.block.BlockState)11 PlayerCraft (net.countercraft.movecraft.craft.PlayerCraft)9 World (org.bukkit.World)9 Location (org.bukkit.Location)6 Block (org.bukkit.block.Block)6 SubCraft (net.countercraft.movecraft.craft.SubCraft)4 CraftType (net.countercraft.movecraft.craft.type.CraftType)4 HitBox (net.countercraft.movecraft.util.hitboxes.HitBox)4 Material (org.bukkit.Material)4 NotNull (org.jetbrains.annotations.NotNull)4 ArrayList (java.util.ArrayList)3 Arrays (java.util.Arrays)3 HashSet (java.util.HashSet)3