From 368f96c51eb90f81299ff94190005c1ef52fd092 Mon Sep 17 00:00:00 2001 From: isokissa3 Date: Sun, 22 Jan 2017 17:21:40 +0200 Subject: [PATCH] Fixed build flag & block-place and block-break incompatiblity --- .../listeners/BlockListener.java | 46 +++++++++---------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/src/main/java/net/goldtreeservers/worldguardextraflags/listeners/BlockListener.java b/src/main/java/net/goldtreeservers/worldguardextraflags/listeners/BlockListener.java index 30457aa..95cf55e 100644 --- a/src/main/java/net/goldtreeservers/worldguardextraflags/listeners/BlockListener.java +++ b/src/main/java/net/goldtreeservers/worldguardextraflags/listeners/BlockListener.java @@ -91,38 +91,36 @@ public class BlockListener implements Listener @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false) public void onBlockBreakEvent(BreakBlockEvent event) { - if (event.getResult() == Result.DEFAULT) + Result originalResult = event.getResult(); + Object cause = event.getCause().getRootCause(); + + if (cause instanceof Player) { - Object cause = event.getCause().getRootCause(); - - if (cause instanceof Player) - { - Player player = (Player)cause; + Player player = (Player)cause; - if (!WorldGuardExtraFlagsPlugin.getWorldGuard().getSessionManager().hasBypass(player, player.getWorld())) + if (!WorldGuardExtraFlagsPlugin.getWorldGuard().getSessionManager().hasBypass(player, player.getWorld())) + { + for(Block block : event.getBlocks()) { - for(Block block : event.getBlocks()) + ApplicableRegionSet regions = WorldGuardExtraFlagsPlugin.getWorldGuard().getRegionContainer().createQuery().getApplicableRegions(block.getLocation()); + + Set state = regions.queryValue(WorldGuardExtraFlagsPlugin.getWorldGuard().wrapPlayer(player), WorldGuardExtraFlagsPlugin.allowBlockBreak); + if (state != null && state.contains(block.getType())) { - ApplicableRegionSet regions = WorldGuardExtraFlagsPlugin.getWorldGuard().getRegionContainer().createQuery().getApplicableRegions(block.getLocation()); - - Set state = regions.queryValue(WorldGuardExtraFlagsPlugin.getWorldGuard().wrapPlayer(player), WorldGuardExtraFlagsPlugin.allowBlockBreak); - if (state != null && state.contains(block.getType())) + event.setResult(Result.ALLOW); + } + else + { + Set state2 = regions.queryValue(WorldGuardExtraFlagsPlugin.getWorldGuard().wrapPlayer(player), WorldGuardExtraFlagsPlugin.denyBlockBreak); + if (state2 != null && state2.contains(block.getType())) { - event.setResult(Result.ALLOW); + event.setResult(Result.DENY); + return; } else { - Set state2 = regions.queryValue(WorldGuardExtraFlagsPlugin.getWorldGuard().wrapPlayer(player), WorldGuardExtraFlagsPlugin.denyBlockBreak); - if (state2 != null && state2.contains(block.getType())) - { - event.setResult(Result.DENY); - return; - } - else - { - event.setResult(Result.DEFAULT); - return; - } + event.setResult(originalResult); + return; } } }