Java Code Examples for org.bukkit.event.block.BlockPistonExtendEvent#getDirection()

The following examples show how to use org.bukkit.event.block.BlockPistonExtendEvent#getDirection() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlockPistonListener.java    From IridiumSkyblock with GNU General Public License v2.0 6 votes vote down vote up
@EventHandler
public void onBlockPistonExtend(BlockPistonExtendEvent event) {
    try {
        final Block block = event.getBlock();
        final Location location = block.getLocation();
        final IslandManager islandManager = IridiumSkyblock.getIslandManager();
        final Island island = islandManager.getIslandViaLocation(location);
        if (island == null) return;

        final BlockFace face = event.getDirection();
        for (Block extendedBlock : event.getBlocks()) {
            final Location extendedBlockLocation = extendedBlock.getLocation();
            final int[] offset = offsets.get(face);
            extendedBlockLocation.add(offset[0], offset[1], offset[2]);
            if (!island.isInIsland(extendedBlockLocation)) {
                event.setCancelled(true);
                return;
            }
        }
    } catch (Exception e) {
        IridiumSkyblock.getInstance().sendErrorMessage(e);
    }
}
 
Example 2
Source File: BukkitPlotListener.java    From PlotMe-Core with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onBlockPistonExtend(BlockPistonExtendEvent event) {
    BukkitWorld world = BukkitUtil.adapt(event.getBlock().getWorld());
    if (manager.isPlotWorld(world)) {
        BlockFace face = event.getDirection();

        for (Block block : event.getBlocks()) {
            PlotId id = manager.getPlotId(new Location(world, BukkitUtil.locationToVector(
                    block.getLocation().add(face.getModX(), face.getModY(),
                            face.getModZ()))));
            if (id == null) {
                event.setCancelled(true);
            }
        }
    }
}
 
Example 3
Source File: LagCompensator.java    From Hawk with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void pistonExtend(BlockPistonExtendEvent e) {
    World world = e.getBlock().getWorld();
    BlockFace bf = e.getDirection();
    Vector offset = new Vector(0, 0, 0);
    switch (bf) {
        case UP:
            offset.setY(1);
            break;
        case DOWN:
            offset.setY(-1);
            break;
        case EAST:
            offset.setX(1);
            break;
        case WEST:
            offset.setX(-1);
            break;
        case NORTH:
            offset.setZ(-1);
            break;
        case SOUTH:
            offset.setZ(1);
    }

    long currTime = System.currentTimeMillis();

    pistonPushes.add(new PistonPush(world, e.getBlock().getLocation().toVector().add(offset), bf, currTime));

    for(Block b : e.getBlocks()) {
        pistonPushes.add(new PistonPush(world, b.getLocation().toVector().add(offset), bf, currTime));
    }
}