From d34e5f809f43aff67318e4f85907956f773409fb Mon Sep 17 00:00:00 2001 From: Eric Date: Mon, 17 Apr 2017 18:29:15 +0200 Subject: [PATCH] Fixed NPE when chest is not on an island (ASkyBlock and uSkyBlock) --- .../shopchest/listeners/ChestProtectListener.java | 13 +++++++++---- .../shopchest/listeners/ShopInteractListener.java | 8 ++++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/epiceric/shopchest/listeners/ChestProtectListener.java b/src/main/java/de/epiceric/shopchest/listeners/ChestProtectListener.java index 622500a..8ad4192 100644 --- a/src/main/java/de/epiceric/shopchest/listeners/ChestProtectListener.java +++ b/src/main/java/de/epiceric/shopchest/listeners/ChestProtectListener.java @@ -178,7 +178,8 @@ public class ChestProtectListener implements Listener { } } } - } catch (Exception ignored) { + } catch (Exception ex) { + plugin.debug(ex); } } } @@ -192,12 +193,16 @@ public class ChestProtectListener implements Listener { if (plugin.hasUSkyBlock() && config.enable_uskyblock_integration) { IslandInfo islandInfo = plugin.getUSkyBlock().getIslandInfo(b.getLocation()); - externalPluginsAllowed &= islandInfo.getMembers().contains(p.getName()) || islandInfo.getLeader().equals(p.getName()); + if (islandInfo != null) { + externalPluginsAllowed &= islandInfo.getMembers().contains(p.getName()) || islandInfo.getLeader().equals(p.getName()); + } } if (plugin.hasASkyBlock() && config.enable_askyblock_integration) { Island island = ASkyBlockAPI.getInstance().getIslandAt(b.getLocation()); - externalPluginsAllowed &= island.getMembers().contains(p.getUniqueId()) || island.getOwner().equals(p.getUniqueId()); + if (island != null) { + externalPluginsAllowed &= island.getMembers().contains(p.getUniqueId()) || island.getOwner().equals(p.getUniqueId()); + } } if (plugin.hasIslandWorld() && config.enable_islandworld_integration && IslandWorldApi.isInitialized()) { @@ -211,7 +216,7 @@ public class ChestProtectListener implements Listener { if (b.getRelative(BlockFace.UP).getType() == Material.AIR) { shopUtils.removeShop(shop, true); - Shop newShop = new Shop(shop.getID(), ShopChest.getInstance(), shop.getVendor(), shop.getProduct(), shop.getLocation(), shop.getBuyPrice(), shop.getSellPrice(), shop.getShopType()); + Shop newShop = new Shop(shop.getID(), plugin, shop.getVendor(), shop.getProduct(), shop.getLocation(), shop.getBuyPrice(), shop.getSellPrice(), shop.getShopType()); newShop.create(true); shopUtils.addShop(newShop, true); plugin.debug(String.format("%s extended %s's shop (#%d)", p.getName(), shop.getVendor().getName(), shop.getID())); diff --git a/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java b/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java index 2af4532..d50093a 100644 --- a/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java +++ b/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java @@ -168,7 +168,9 @@ public class ShopInteractListener implements Listener { for (Location loc : chestLocations) { if (loc != null) { IslandInfo islandInfo = plugin.getUSkyBlock().getIslandInfo(loc); - externalPluginsAllowed &= islandInfo.getMembers().contains(p.getName()) || islandInfo.getLeader().equals(p.getName()); + if (islandInfo != null) { + externalPluginsAllowed &= islandInfo.getMembers().contains(p.getName()) || islandInfo.getLeader().equals(p.getName()); + } } } } @@ -177,7 +179,9 @@ public class ShopInteractListener implements Listener { for (Location loc : chestLocations) { if (loc != null) { Island island = ASkyBlockAPI.getInstance().getIslandAt(loc); - externalPluginsAllowed &= island.getMembers().contains(p.getUniqueId()) || island.getOwner().equals(p.getUniqueId()); + if (island != null) { + externalPluginsAllowed &= island.getMembers().contains(p.getUniqueId()) || island.getOwner().equals(p.getUniqueId()); + } } } }