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

The following examples show how to use org.bukkit.event.block.BlockPistonExtendEvent#getBlocks() . 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: ShopItemListener.java    From ShopChest with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void onPistonExtend(BlockPistonExtendEvent e) {
    // If the piston would only move itself
    Block airAfterPiston = e.getBlock().getRelative(e.getDirection());
    Block belowAir = airAfterPiston.getRelative(BlockFace.DOWN);
    if (shopUtils.isShop(belowAir.getLocation())) {
        e.setCancelled(true);
        return;
    }

    for (Block b : e.getBlocks()) {
        Block newBlock = b.getRelative(e.getDirection());
        Block belowNewBlock = newBlock.getRelative(BlockFace.DOWN);
        if (shopUtils.isShop(belowNewBlock.getLocation())) e.setCancelled(true);
    }
}
 
Example 3
Source File: IslandGuard.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOW)
public void onPistonExtend(BlockPistonExtendEvent e) {
    if (DEBUG) {
        plugin.getLogger().info(e.getEventName());
    }
    Location pistonLoc = e.getBlock().getLocation();
    if (Settings.allowPistonPush || !inWorld(pistonLoc)) {
        //plugin.getLogger().info("DEBUG: Not in world");
        return;
    }
    Island island = plugin.getGrid().getProtectedIslandAt(pistonLoc);
    if (island == null || !island.onIsland(pistonLoc)) {
        //plugin.getLogger().info("DEBUG: Not on is island protection zone");
        return;
    }
    // We need to check where the blocks are going to go, not where they are
    for (Block b : e.getBlocks()) {
        if (!island.onIsland(b.getRelative(e.getDirection()).getLocation())) {
            //plugin.getLogger().info("DEBUG: Block is outside protected area");
            e.setCancelled(true);
            return;
        }
    }
}
 
Example 4
Source File: IslandGuard.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
@EventHandler(priority=EventPriority.LOW)
public void onEvent(BlockPistonExtendEvent event)
{
    if (!Settings.allowTNTPushing) {
        // Check world
        if (!inWorld(event.getBlock())) {
            return;
        }

        for (Block block: event.getBlocks()) {
            if (block.getType() == Material.TNT) {
                event.setCancelled(true);
                break;
            }
        }
    }
    /* JAVA 8
    if (event.getBlocks()..stream().anyMatch(it->it.getType()==Material.TNT))
        event.setCancelled(true);
     */
}
 
Example 5
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 6
Source File: CoreObjective.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPistonPush(BlockPistonExtendEvent event) {
    for (Block block : event.getBlocks()) {
        if (core.contains(block) && partOfObjective(block)) {
            event.setCancelled(true);
        }
    }
}
 
Example 7
Source File: DestroyableObjective.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPistonPush(BlockPistonExtendEvent event) {
    for (Block block : event.getBlocks()) {
        if (monument.contains(block) && partOfObjective(block)) {
            event.setCancelled(true);
        }
    }
}
 
Example 8
Source File: BlockEventRegion.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler
public void onBlockPistonExtend(BlockPistonExtendEvent event) {
    if (region.contains(event.getBlock().getRelative(event.getDirection()).getLocation().toVector()) && filter.evaluate(event.getBlock().getRelative(event.getDirection()), event).equals(FilterState.DENY)) {
        event.setCancelled(true);
    } else {
        for (Block block : event.getBlocks()) {
            if ((region.contains(block.getLocation().toVector()) && filter.evaluate(block, event).equals(FilterState.DENY)) || (region.contains(block.getRelative(event.getDirection()).getLocation().toVector()) && filter.evaluate(block.getRelative(event.getDirection()), event).equals(FilterState.DENY))) {
                event.setCancelled(true);
                break;
            }
        }
    }
}
 
Example 9
Source File: BlockPlaceRegion.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler
public void onBlockPistonExtend(BlockPistonExtendEvent event) {
    if (region.contains(event.getBlock().getRelative(event.getDirection()).getLocation().toVector()) && filter.evaluate(event.getBlock().getRelative(event.getDirection()), event).equals(FilterState.DENY)) {
        event.setCancelled(true);
    } else {
        for (Block block : event.getBlocks()) {
            if (region.contains(block.getRelative(event.getDirection()).getLocation().toVector()) && filter.evaluate(block.getRelative(event.getDirection()), event).equals(FilterState.DENY)) {
                event.setCancelled(true);
                break;
            }
        }
    }
}
 
Example 10
Source File: BuildHeight.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler
public void onBlockPistonExtend(BlockPistonExtendEvent event) {
    if (event.getBlock().getRelative(event.getDirection()).getY() >= height){
        event.setCancelled(true);
    } else {
        for (Block block : event.getBlocks()) {
            if (block.getRelative(event.getDirection()).getY() >= height) {
                event.setCancelled(true);
            }
        }
    }
}
 
Example 11
Source File: WoolObjective.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onPistonPush(BlockPistonExtendEvent event) {
    if (!event.isCancelled()) {
        if (event.getBlock().getRelative(event.getDirection()).equals(place.getBlock())) {
            event.setCancelled(true);
        } else {
            for (Block block : event.getBlocks()) {
                if (block.equals(place.getBlock()) || block.equals(place.getBlock().getRelative(event.getDirection().getOppositeFace()))) {
                    event.setCancelled(true);
                }
            }
        }
    }
}
 
Example 12
Source File: GuildHeartProtectionHandler.java    From FunnyGuilds with Apache License 2.0 5 votes vote down vote up
@EventHandler
public void onPistonExtend(BlockPistonExtendEvent event) {
    for (Block block : event.getBlocks()) {
        if (isGuildHeart(block)) {
            event.setCancelled(true);
        }
    }
}
 
Example 13
Source File: BlockPhysicsListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onPistonExtend(BlockPistonExtendEvent e) {
    for (Block b : e.getBlocks()) {
        if (BlockStorage.hasBlockInfo(b) || (b.getRelative(e.getDirection()).getType() == Material.AIR && BlockStorage.hasBlockInfo(b.getRelative(e.getDirection())))) {
            e.setCancelled(true);
            return;
        }
    }
}
 
Example 14
Source File: LoggingManager.java    From Survival-Games with GNU General Public License v3.0 5 votes vote down vote up
public void blockChange(BlockPistonExtendEvent e){
	if(e.isCancelled())return;

	for(Block b: e.getBlocks()){
		logBlockCreated(b);
	}
	i.put("BPISTION", i.get("BPISTION")+1);

}
 
Example 15
Source File: LWCBlockListener.java    From Modern-LWC with MIT License 5 votes vote down vote up
@EventHandler
public void onBlockPistonExtend(BlockPistonExtendEvent event) {
    if (!LWC.ENABLED || event.isCancelled()) {
        return;
    }
    LWC lwc = this.plugin.getLWC();
    for (Block block : event.getBlocks()) {
        Protection protection = lwc.findProtection(block);
        if (protection != null) {
            event.setCancelled(true);
            return;
        }
    }
}
 
Example 16
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));
    }
}
 
Example 17
Source File: BlockListener.java    From civcraft with GNU General Public License v2.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST) 
	public void onBlockPistonExtendEvent(BlockPistonExtendEvent event) {

		/* UGH. If we extend into 'air' it doesnt count them as blocks...
		 * we need to check air to prevent breaking of item frames...
		 */
		final int PISTON_EXTEND_LENGTH = 13;
		Block currentBlock = event.getBlock().getRelative(event.getDirection());
		for (int i = 0; i < PISTON_EXTEND_LENGTH; i++) {
			if(ItemManager.getId(currentBlock) == CivData.AIR) {
				if (!allowPistonAction(currentBlock.getLocation())) {
					event.setCancelled(true);
					return;
				}
			}

			currentBlock = currentBlock.getRelative(event.getDirection());
		}
		
		if (War.isWarTime()) {
			event.setCancelled(true);
			return;
		}

//		if (event.getBlocks().size() == 0) {
//			Block extendInto = event.getBlock().getRelative(event.getDirection());
//			if (!allowPistonAction(extendInto.getLocation())) {
//				event.setCancelled(true);
//				return;
//			}
//		}
		coord.setFromLocation(event.getBlock().getLocation());
		FarmChunk fc = CivGlobal.getFarmChunk(coord);
		if (fc == null) {
			event.setCancelled(true);
			
		}
		
		for (Block block : event.getBlocks()) {
			if (!allowPistonAction(block.getLocation())) {
				event.setCancelled(true);
				break;

			}
		}

	}