From f09d57b2a2ef3989287a8e310b02541ed5f065d1 Mon Sep 17 00:00:00 2001 From: Eric Date: Mon, 29 Apr 2019 20:24:07 +0200 Subject: [PATCH] Fix error when WorldGuard not installed --- .../listeners/ShopInteractListener.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java b/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java index 1e5dabd..7069dbe 100644 --- a/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java +++ b/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java @@ -88,14 +88,12 @@ public class ShopInteractListener implements Listener { private Economy econ; private Database database; private ShopUtils shopUtils; - private WorldGuardWrapper wgWrapper; public ShopInteractListener(ShopChest plugin) { this.plugin = plugin; this.econ = plugin.getEconomy(); this.database = plugin.getShopDatabase(); this.shopUtils = plugin.getShopUtils(); - this.wgWrapper = WorldGuardWrapper.getInstance(); } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @@ -165,14 +163,17 @@ public class ShopInteractListener implements Listener { if (plugin.hasWorldGuard() && Config.enableWorldGuardIntegration) { plugin.debug("Checking if WorldGuard allows shop creation..."); - - for (Location loc : chestLocations) { - if (loc != null) { - Optional> flag = wgWrapper.getFlag("create-shop", WrappedState.class); - if (!flag.isPresent()) plugin.debug("WorldGuard flag 'create-shop' is not present!"); - WrappedState state = flag.map(f -> wgWrapper.queryFlag(p, loc, f).orElse(WrappedState.DENY)).orElse(WrappedState.DENY); - externalPluginsAllowed = state == WrappedState.ALLOW; + WorldGuardWrapper wgWrapper = WorldGuardWrapper.getInstance(); + Optional> flag = wgWrapper.getFlag("create-shop", WrappedState.class); + if (flag.isPresent()) { + for (Location loc : chestLocations) { + if (loc != null) { + WrappedState state = wgWrapper.queryFlag(p, loc, flag.get()).orElse(WrappedState.DENY); + externalPluginsAllowed = state == WrappedState.ALLOW; + } } + } else { + plugin.debug("WorldGuard flag 'create-shop' is not present!"); } if (!externalPluginsAllowed) denyReason = "WorldGuard"; @@ -467,6 +468,7 @@ public class ShopInteractListener implements Listener { if (externalPluginsAllowed && plugin.hasWorldGuard() && Config.enableWorldGuardIntegration) { String flagName = (shop.getShopType() == ShopType.ADMIN ? "use-admin-shop" : "use-shop"); + WorldGuardWrapper wgWrapper = WorldGuardWrapper.getInstance(); Optional> flag = wgWrapper.getFlag(flagName, WrappedState.class); if (!flag.isPresent()) plugin.debug("WorldGuard flag '" + flagName + "' is not present!"); WrappedState state = flag.map(f -> wgWrapper.queryFlag(p, b.getLocation(), f).orElse(WrappedState.DENY)).orElse(WrappedState.DENY); @@ -580,6 +582,7 @@ public class ShopInteractListener implements Listener { if (externalPluginsAllowed && plugin.hasWorldGuard() && Config.enableWorldGuardIntegration) { String flagName = (shop.getShopType() == ShopType.ADMIN ? "use-admin-shop" : "use-shop"); + WorldGuardWrapper wgWrapper = WorldGuardWrapper.getInstance(); Optional> flag = wgWrapper.getFlag(flagName, WrappedState.class); if (!flag.isPresent()) plugin.debug("WorldGuard flag '" + flagName + "' is not present!"); WrappedState state = flag.map(f -> wgWrapper.queryFlag(p, b.getLocation(), f).orElse(WrappedState.DENY)).orElse(WrappedState.DENY);