Search in sources :

Example 21 with Craft

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

the class DescendSign method onSignClick.

@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onSignClick(@NotNull PlayerInteractEvent event) {
    if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
        return;
    }
    BlockState state = event.getClickedBlock().getState();
    if (!(state instanceof Sign)) {
        return;
    }
    Sign sign = (Sign) state;
    if (ChatColor.stripColor(sign.getLine(0)).equalsIgnoreCase("Descend: 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, true, false);
        sign.setLine(0, "Descend: ON");
        sign.update(true);
        c.setCruiseDirection(CruiseDirection.DOWN);
        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("Descend: ON")) {
        Craft c = CraftManager.getInstance().getCraftByPlayer(event.getPlayer());
        if (c != null && c.getType().getBoolProperty(CraftType.CAN_CRUISE)) {
            sign.setLine(0, "Descend: OFF");
            sign.update(true);
            c.setCruising(false);
            c.resetSigns(sign);
        }
    }
}
Also used : BlockState(org.bukkit.block.BlockState) Craft(net.countercraft.movecraft.craft.Craft) Sign(org.bukkit.block.Sign) EventHandler(org.bukkit.event.EventHandler)

Example 22 with Craft

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

the class HelmSign method onSignClick.

@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onSignClick(@NotNull PlayerInteractEvent event) {
    MovecraftRotation rotation;
    if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
        rotation = MovecraftRotation.CLOCKWISE;
    } else if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
        rotation = MovecraftRotation.ANTICLOCKWISE;
    } else {
        return;
    }
    BlockState state = event.getClickedBlock().getState();
    if (!(state instanceof Sign)) {
        return;
    }
    Sign sign = (Sign) state;
    if (!(ChatColor.stripColor(sign.getLine(0)).equals("\\  ||  /") && ChatColor.stripColor(sign.getLine(1)).equals("==      ==") && ChatColor.stripColor(sign.getLine(2)).equals("/  ||  \\"))) {
        return;
    }
    Craft craft = CraftManager.getInstance().getCraftByPlayer(event.getPlayer());
    if (craft == null) {
        return;
    }
    if (!event.getPlayer().hasPermission("movecraft." + craft.getType().getStringProperty(CraftType.NAME) + ".rotate")) {
        event.getPlayer().sendMessage(I18nSupport.getInternationalisedString("Insufficient Permissions"));
        return;
    }
    if (!MathUtils.locIsNearCraftFast(craft, MathUtils.bukkit2MovecraftLoc(event.getPlayer().getLocation())))
        return;
    if (craft.getType().getBoolProperty(CraftType.ROTATE_AT_MIDPOINT)) {
        CraftManager.getInstance().getCraftByPlayer(event.getPlayer()).rotate(rotation, craft.getHitBox().getMidPoint());
    } else {
        CraftManager.getInstance().getCraftByPlayer(event.getPlayer()).rotate(rotation, MathUtils.bukkit2MovecraftLoc(sign.getLocation()));
    }
    // timeMap.put(event.getPlayer(), System.currentTimeMillis());
    event.setCancelled(true);
// TODO: Lower speed while turning
/*int curTickCooldown = CraftManager.getInstance().getCraftByPlayer(event.getPlayer()).getCurTickCooldown();
            int baseTickCooldown = CraftManager.getInstance().getCraftByPlayer(event.getPlayer()).getType().getCruiseTickCooldown();
            if (curTickCooldown * 2 > baseTickCooldown)
                curTickCooldown = baseTickCooldown;
            else
                curTickCooldown = curTickCooldown * 2;*/
// CraftManager.getInstance().getCraftByPlayer(event.getPlayer()).setCurTickCooldown(curTickCooldown); // lose half your speed when turning
}
Also used : BlockState(org.bukkit.block.BlockState) Craft(net.countercraft.movecraft.craft.Craft) Sign(org.bukkit.block.Sign) MovecraftRotation(net.countercraft.movecraft.MovecraftRotation) EventHandler(org.bukkit.event.EventHandler)

Example 23 with Craft

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

the class ReleaseSign method onSignClick.

@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onSignClick(@NotNull PlayerInteractEvent event) {
    if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
        return;
    }
    BlockState state = event.getClickedBlock().getState();
    if (!(state instanceof Sign)) {
        return;
    }
    Sign sign = (Sign) state;
    if (!ChatColor.stripColor(sign.getLine(0)).equalsIgnoreCase(HEADER)) {
        return;
    }
    Craft craft = CraftManager.getInstance().getCraftByPlayer(event.getPlayer());
    if (craft == null) {
        return;
    }
    CraftManager.getInstance().release(craft, CraftReleaseEvent.Reason.PLAYER, false);
}
Also used : BlockState(org.bukkit.block.BlockState) Craft(net.countercraft.movecraft.craft.Craft) Sign(org.bukkit.block.Sign) EventHandler(org.bukkit.event.EventHandler)

Example 24 with Craft

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

the class BlockListener method onRedstoneEvent.

// process certain redstone on cruising crafts
@EventHandler(priority = EventPriority.HIGHEST)
public void onRedstoneEvent(BlockRedstoneEvent event) {
    Block block = event.getBlock();
    CraftManager.getInstance().getCraftsInWorld(block.getWorld());
    for (Craft tcraft : CraftManager.getInstance().getCraftsInWorld(block.getWorld())) {
        MovecraftLocation mloc = new MovecraftLocation(block.getX(), block.getY(), block.getZ());
        if (MathUtils.locIsNearCraftFast(tcraft, mloc) && tcraft.getCruising() && (block.getType() == Material.STICKY_PISTON || block.getType() == Material.PISTON || block.getType() == Material.DISPENSER && !tcraft.isNotProcessing())) {
            // don't allow piston movement on cruising crafts
            event.setNewCurrent(event.getOldCurrent());
            return;
        }
    }
}
Also used : Craft(net.countercraft.movecraft.craft.Craft) Block(org.bukkit.block.Block) MovecraftLocation(net.countercraft.movecraft.MovecraftLocation) EventHandler(org.bukkit.event.EventHandler)

Example 25 with Craft

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

the class BlockListener method onIceForm.

@EventHandler
public void onIceForm(BlockFormEvent e) {
    if (e.isCancelled() || !Settings.DisableIceForm)
        return;
    if (e.getBlock().getType() != Material.WATER)
        return;
    MovecraftLocation loc = MathUtils.bukkit2MovecraftLoc(e.getBlock().getLocation());
    Craft craft = MathUtils.fastNearestCraftToLoc(CraftManager.getInstance().getCrafts(), e.getBlock().getLocation());
    if (craft != null && craft.getHitBox().contains((loc)))
        e.setCancelled(true);
}
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