Search in sources :

Example 1 with Switch

use of org.bukkit.block.data.type.Switch in project TARDIS by eccentricdevotion.

the class TARDISJunkControlListener method onJunkBrakeUse.

@EventHandler(priority = EventPriority.MONITOR)
public void onJunkBrakeUse(PlayerInteractEvent event) {
    if (event.getHand() == null || event.getHand().equals(EquipmentSlot.OFF_HAND)) {
        return;
    }
    if (plugin.getGeneralKeeper().isJunkTravelling()) {
        return;
    }
    Block block = event.getClickedBlock();
    if (block != null) {
        Material blockType = block.getType();
        Location controlLoc = block.getLocation();
        String c_loc = controlLoc.toString();
        HashMap<String, Object> where = new HashMap<>();
        where.put("location", c_loc);
        if (blockType == Material.LEVER) {
            // Checks handbrake location against the database.
            where.put("type", 0);
            ResultSetControls rsh = new ResultSetControls(plugin, where, false);
            if (rsh.resultSet()) {
                int id = rsh.getTardis_id();
                // is it the Junk TARDIS?
                ResultSetTardisPreset rs = new ResultSetTardisPreset(plugin);
                if (rs.fromID(id) && rs.getPreset().equals(PRESET.JUNK)) {
                    Player player = event.getPlayer();
                    if (!TARDISPermission.hasPermission(player, "tardis.junk")) {
                        TARDISMessage.send(player, "JUNK_NO_PERM");
                        return;
                    }
                    // get the destination
                    getDestination(id, player);
                    if (plugin.getGeneralKeeper().getJunkDestination() != null) {
                        // get the current location
                        Location junkloc = null;
                        HashMap<String, Object> wherecl = new HashMap<>();
                        wherecl.put("tardis_id", id);
                        ResultSetCurrentLocation rsc = new ResultSetCurrentLocation(plugin, wherecl);
                        if (rsc.resultSet()) {
                            junkloc = new Location(rsc.getWorld(), rsc.getX(), rsc.getY(), rsc.getZ());
                        }
                        if (junkloc == null) {
                            TARDISMessage.send(player, "JUNK_NOT_FOUND");
                            return;
                        }
                        Switch lever = (Switch) block.getBlockData();
                        lever.setPowered(!lever.isPowered());
                        block.setBlockData(lever);
                        // destroy junk TARDIS
                        DestroyData dd = new DestroyData();
                        dd.setPlayer(player);
                        dd.setDirection(COMPASS.SOUTH);
                        dd.setLocation(junkloc);
                        dd.setHide(false);
                        dd.setOutside(false);
                        dd.setSubmarine(rsc.isSubmarine());
                        dd.setTardisID(id);
                        dd.setThrottle(SpaceTimeThrottle.JUNK);
                        plugin.getPresetDestroyer().destroyPreset(dd);
                        // fly my pretties
                        plugin.getGeneralKeeper().setJunkTravelling(true);
                    } else {
                        TARDISMessage.send(event.getPlayer(), "JUNK_NO_DEST");
                        return;
                    }
                }
            }
        }
        if (blockType == Material.TRIPWIRE_HOOK) {
            // 4
            where.put("type", 4);
            ResultSetControls rst = new ResultSetControls(plugin, where, false);
            if (rst.resultSet()) {
                int id = rst.getTardis_id();
                // is it the Junk TARDIS?
                ResultSetTardisPreset rs = new ResultSetTardisPreset(plugin);
                if (rs.fromID(id) && rs.getPreset().equals(PRESET.JUNK)) {
                    Player player = event.getPlayer();
                    if (!TARDISPermission.hasPermission(player, "tardis.junk")) {
                        TARDISMessage.send(player, "JUNK_NO_PERM");
                        return;
                    }
                    setSignWorld(id, player.getUniqueId());
                }
            }
        }
        if (blockType == Material.STONE_BUTTON) {
            // 1
            where.put("type", 1);
            ResultSetControls rsh = new ResultSetControls(plugin, where, false);
            if (rsh.resultSet()) {
                int id = rsh.getTardis_id();
                // is it the Junk TARDIS?
                ResultSetTardisPreset rs = new ResultSetTardisPreset(plugin);
                if (rs.fromID(id) && rs.getPreset().equals(PRESET.JUNK)) {
                    Player player = event.getPlayer();
                    if (!TARDISPermission.hasPermission(player, "tardis.junk")) {
                        TARDISMessage.send(player, "JUNK_NO_PERM");
                        return;
                    }
                    setSignCoords(id, 2);
                }
            }
        }
        if (blockType == Material.OAK_BUTTON) {
            // 6
            where.put("type", 6);
            ResultSetControls rsh = new ResultSetControls(plugin, where, false);
            if (rsh.resultSet()) {
                int id = rsh.getTardis_id();
                // is it the Junk TARDIS?
                ResultSetTardisPreset rs = new ResultSetTardisPreset(plugin);
                if (rs.fromID(id) && rs.getPreset().equals(PRESET.JUNK)) {
                    Player player = event.getPlayer();
                    if (!TARDISPermission.hasPermission(player, "tardis.junk")) {
                        TARDISMessage.send(player, "JUNK_NO_PERM");
                        return;
                    }
                    setSignCoords(id, 3);
                }
            }
        }
    }
}
Also used : ResultSetControls(me.eccentric_nz.TARDIS.database.resultset.ResultSetControls) Player(org.bukkit.entity.Player) HashMap(java.util.HashMap) ResultSetCurrentLocation(me.eccentric_nz.TARDIS.database.resultset.ResultSetCurrentLocation) Switch(org.bukkit.block.data.type.Switch) Block(org.bukkit.block.Block) ResultSetTardisPreset(me.eccentric_nz.TARDIS.database.resultset.ResultSetTardisPreset) DestroyData(me.eccentric_nz.TARDIS.destroyers.DestroyData) ResultSetCurrentLocation(me.eccentric_nz.TARDIS.database.resultset.ResultSetCurrentLocation) EventHandler(org.bukkit.event.EventHandler)

Example 2 with Switch

use of org.bukkit.block.data.type.Switch in project SignShop by wargamer.

the class SignShopBlockListener method getAttachables.

private List<Block> getAttachables(Block originalBlock) {
    List<Block> attachables = new ArrayList<>();
    List<BlockFace> checkFaces = new ArrayList<>();
    checkFaces.add(BlockFace.UP);
    checkFaces.add(BlockFace.NORTH);
    checkFaces.add(BlockFace.EAST);
    checkFaces.add(BlockFace.SOUTH);
    checkFaces.add(BlockFace.WEST);
    Block relativeBlock;
    BlockData relativeBlockData;
    for (BlockFace face : checkFaces) {
        relativeBlock = originalBlock.getRelative(face);
        relativeBlockData = relativeBlock.getBlockData();
        if (relativeBlockData instanceof Switch) {
            Switch switchData = (Switch) relativeBlockData;
            if (switchData.getFace() == Switch.Face.FLOOR && relativeBlock.getRelative(BlockFace.DOWN).equals(originalBlock)) {
                attachables.add(relativeBlock);
            }
        } else if (relativeBlockData instanceof WallSign) {
            WallSign wallSign = (WallSign) relativeBlockData;
            if (relativeBlock.getRelative(wallSign.getFacing().getOppositeFace()).equals(originalBlock)) {
                // may need to add getOppositeFace
                attachables.add(relativeBlock);
            }
        } else if (relativeBlockData instanceof Sign)
            if (relativeBlock.getRelative(BlockFace.DOWN).equals(originalBlock)) {
                attachables.add(relativeBlock);
            }
    }
    return attachables;
}
Also used : WallSign(org.bukkit.block.data.type.WallSign) Switch(org.bukkit.block.data.type.Switch) BlockFace(org.bukkit.block.BlockFace) ArrayList(java.util.ArrayList) Block(org.bukkit.block.Block) WallSign(org.bukkit.block.data.type.WallSign) Sign(org.bukkit.block.data.type.Sign) BlockData(org.bukkit.block.data.BlockData)

Example 3 with Switch

use of org.bukkit.block.data.type.Switch in project SignShop by wargamer.

the class setRedstoneOff method checkRequirements.

@Override
public Boolean checkRequirements(SignShopArguments ssArgs, Boolean activeCheck) {
    if (!setupOperation(ssArgs))
        return false;
    boolean bReturn = false;
    Block bLever;
    for (int i = 0; i < ssArgs.getActivatables().get().size(); i++) {
        bLever = ssArgs.getActivatables().get().get(i);
        if (bLever.getType() == Material.getMaterial("LEVER") && bLever.getBlockData() instanceof Switch) {
            Switch switchLever = (Switch) bLever.getBlockData();
            if (switchLever.isPowered())
                bReturn = true;
        }
    }
    if (!bReturn)
        ssArgs.sendFailedRequirementsMessage("already_off");
    return bReturn;
}
Also used : Switch(org.bukkit.block.data.type.Switch) Block(org.bukkit.block.Block)

Example 4 with Switch

use of org.bukkit.block.data.type.Switch in project SignShop by wargamer.

the class setRedstoneOff method runOperation.

@Override
public Boolean runOperation(SignShopArguments ssArgs) {
    if (!setupOperation(ssArgs))
        return false;
    Block bLever;
    for (int i = 0; i < ssArgs.getActivatables().get().size(); i++) {
        bLever = ssArgs.getActivatables().get().get(i);
        if (bLever.getType() == Material.getMaterial("LEVER") && bLever.getBlockData() instanceof Switch) {
            Switch switchLever = (Switch) bLever.getBlockData();
            if (switchLever.isPowered()) {
                switchLever.setPowered(false);
                bLever.setBlockData(switchLever);
                signshopUtil.generateInteractEvent(bLever, ssArgs.getPlayer().get().getPlayer(), ssArgs.getBlockFace().get());
            }
        }
    }
    return true;
}
Also used : Switch(org.bukkit.block.data.type.Switch) Block(org.bukkit.block.Block)

Example 5 with Switch

use of org.bukkit.block.data.type.Switch in project SignShop by wargamer.

the class setRedstoneOn method checkRequirements.

@Override
public Boolean checkRequirements(SignShopArguments ssArgs, Boolean activeCheck) {
    if (!setupOperation(ssArgs))
        return false;
    boolean bReturn = false;
    Block bLever;
    for (int i = 0; i < ssArgs.getActivatables().get().size(); i++) {
        bLever = ssArgs.getActivatables().get().get(i);
        if (bLever.getType() == Material.getMaterial("LEVER") && bLever.getBlockData() instanceof Switch) {
            Switch switchLever = (Switch) bLever.getBlockData();
            if (!switchLever.isPowered())
                bReturn = true;
        }
    }
    if (!bReturn)
        ssArgs.sendFailedRequirementsMessage("already_on");
    return bReturn;
}
Also used : Switch(org.bukkit.block.data.type.Switch) Block(org.bukkit.block.Block)

Aggregations

Switch (org.bukkit.block.data.type.Switch)11 Block (org.bukkit.block.Block)9 Player (org.bukkit.entity.Player)2 EventHandler (org.bukkit.event.EventHandler)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ResultSetControls (me.eccentric_nz.TARDIS.database.resultset.ResultSetControls)1 ResultSetCurrentLocation (me.eccentric_nz.TARDIS.database.resultset.ResultSetCurrentLocation)1 ResultSetTardisPreset (me.eccentric_nz.TARDIS.database.resultset.ResultSetTardisPreset)1 DestroyData (me.eccentric_nz.TARDIS.destroyers.DestroyData)1 PlayerCraft (net.countercraft.movecraft.craft.PlayerCraft)1 CraftType (net.countercraft.movecraft.craft.type.CraftType)1 BlockFace (org.bukkit.block.BlockFace)1 BlockState (org.bukkit.block.BlockState)1 BlockData (org.bukkit.block.data.BlockData)1 Sign (org.bukkit.block.data.type.Sign)1 WallSign (org.bukkit.block.data.type.WallSign)1 Seller (org.wargamer2010.signshop.Seller)1 org.wargamer2010.signshop.util.lagSetter (org.wargamer2010.signshop.util.lagSetter)1