Java Code Examples for org.bukkit.event.block.BlockFromToEvent#isCancelled()

The following examples show how to use org.bukkit.event.block.BlockFromToEvent#isCancelled() . 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: WorldListener.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onLiquidFlow(BlockFromToEvent event) {
    if (event.isCancelled()) {
        return;
    }

    for (String gameName : Main.getGameNames()) {
        Game game = Main.getGame(gameName);
        if (GameCreator.isInArea(event.getBlock().getLocation(), game.getPos1(), game.getPos2())) {
            if (game.getStatus() == GameStatus.RUNNING || game.getStatus() == GameStatus.GAME_END_CELEBRATING) {
                Block block = event.getToBlock();
                if (block.getType() == Material.AIR
                        || game.getRegion().isBlockAddedDuringGame(block.getLocation())) {
                    game.getRegion().addBuiltDuringGame(block.getLocation());
                } else {
                    event.setCancelled(true);
                }
            } else if (game.getStatus() != GameStatus.DISABLED) {
                event.setCancelled(true);
            }
        }
    }

}
 
Example 2
Source File: WorldListener.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onLiquidFlow(BlockFromToEvent event) {
    if (event.isCancelled()) {
        return;
    }

    for (String gameName : Main.getGameNames()) {
        Game game = Main.getGame(gameName);
        if (GameCreator.isInArea(event.getBlock().getLocation(), game.getPos1(), game.getPos2())) {
            if (game.getStatus() == GameStatus.RUNNING || game.getStatus() == GameStatus.GAME_END_CELEBRATING) {
                Block block = event.getToBlock();
                if (block.getType() == Material.AIR
                        || game.getRegion().isBlockAddedDuringGame(block.getLocation())) {
                    game.getRegion().addBuiltDuringGame(block.getLocation());
                } else {
                    event.setCancelled(true);
                }
            } else if (game.getStatus() != GameStatus.DISABLED) {
                event.setCancelled(true);
            }
        }
    }

}
 
Example 3
Source File: ChunkEventHelper.java    From ClaimChunk with MIT License 6 votes vote down vote up
public static void handleToFromEvent(@Nonnull BlockFromToEvent e) {
    if (e.isCancelled()) return;

    // Only continue if we should stop the spread from the config.
    if (!config.getBool("protection", "blockFluidSpreadIntoClaims")) return;

    // If the block isn't water or lava, we don't protect it.
    Material blockType = e.getBlock().getType();
    if (blockType != Material.WATER && blockType != Material.LAVA) return;

    Chunk from = e.getBlock().getChunk();
    Chunk to = e.getToBlock().getChunk();

    // If the from and to chunks have the same owner or if the to chunk is
    // unclaimed, the flow is allowed.
    final ChunkHandler CHUNK = ClaimChunk.getInstance().getChunkHandler();
    if (getChunksSameOwner(CHUNK, from, to) || !CHUNK.isClaimed(to)) return;

    // Cancel the flow
    e.setCancelled(true);
}
 
Example 4
Source File: CoreObjective.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onBlockFromTo(BlockFromToEvent event) {
    if (lava.contains(event.getToBlock())){
        event.setCancelled(true);
    }
    if (!event.isCancelled()) {
        Block to = event.getToBlock();
        Block from = event.getBlock();
        if (CoreObjective.getClosestCore(to.getX(), to.getY(), to.getZ()).equals(this)) {
            if ((from.getType().equals(Material.LAVA) || from.getType().equals(Material.STATIONARY_LAVA)) && to.getType().equals(Material.AIR)) {
                double minY = 256;
                for (Block block : getCore()) {
                    if (block.getY() < minY)
                        minY = block.getY();
                }
                if (minY - to.getY() >= leak && !this.complete) {
                    this.complete = true;
                    event.setCancelled(false);
                    if (this.show)
                        ChatUtil.getGlobalChannel().sendLocalizedMessage(new UnlocalizedChatMessage(ChatColor.RED + "{0}", new LocalizedChatMessage(ChatConstant.UI_OBJECTIVE_LEAKED, team.getCompleteName() + ChatColor.RED, name)));
                    ObjectiveCompleteEvent compEvent = new ObjectiveCompleteEvent(this, null);
                    Bukkit.getServer().getPluginManager().callEvent(compEvent);
                }
            }
        }
    }
}
 
Example 5
Source File: BlockPlaceRegion.java    From CardinalPGM with MIT License 4 votes vote down vote up
@EventHandler
public void onBLiquidFlow(BlockFromToEvent event) {
    if (!event.isCancelled() && region.contains(new BlockRegion(null, event.getToBlock().getLocation().toVector())) && filter.evaluate(event.getToBlock(), event).equals(FilterState.DENY)) {
        event.setCancelled(true);
    }
}