From 53a9bb02743947a400222bd16da7ebe4724407b0 Mon Sep 17 00:00:00 2001 From: Eric Date: Wed, 26 Apr 2017 16:38:33 +0200 Subject: [PATCH] Show WorldGuard permission message when trying to create a shop (e.g. when not allowed to open the chest) This also has the effect that the original event won't be un-cancelled anymore, so the flag "chest-access" now also has to be allowed! --- .../shopchest/listeners/WorldGuardListener.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/epiceric/shopchest/listeners/WorldGuardListener.java b/src/main/java/de/epiceric/shopchest/listeners/WorldGuardListener.java index 68db8e2..7d7a49d 100644 --- a/src/main/java/de/epiceric/shopchest/listeners/WorldGuardListener.java +++ b/src/main/java/de/epiceric/shopchest/listeners/WorldGuardListener.java @@ -148,7 +148,13 @@ public class WorldGuardListener implements Listener { if (type == Material.CHEST || type == Material.TRAPPED_CHEST) { if (isAllowed(player, orig.getClickedBlock().getLocation(), orig.getAction())) { event.setAllowed(true); - orig.setCancelled(false); + + ClickType ct = ClickType.getPlayerClickType(player); + if (!(ct != null && ct.getClickType() == ClickType.EnumClickType.CREATE)) { + // Don't un-cancel original event when trying to create shop. + // Flag "chest-access" has to be allowed too, so the original event won't be cancelled. + orig.setCancelled(false); + } } } } @@ -158,7 +164,13 @@ public class WorldGuardListener implements Listener { if (orig.getInventory().getHolder() instanceof Chest) { if (isAllowed(player, ((Chest)orig.getInventory().getHolder()).getLocation(), Action.RIGHT_CLICK_BLOCK)) { event.setAllowed(true); - orig.setCancelled(false); + + ClickType ct = ClickType.getPlayerClickType(player); + if (!(ct != null && ct.getClickType() == ClickType.EnumClickType.CREATE)) { + // Don't un-cancel original event when trying to create shop. + // Flag "chest-access" has to be allowed too, so the original event won't be cancelled. + orig.setCancelled(false); + } } } }