From 857d616d54b0ec3e2280759ae3c5c149e9dee440 Mon Sep 17 00:00:00 2001 From: Sparkling Comet Date: Tue, 7 Sep 2021 10:08:16 +0200 Subject: [PATCH 1/3] Add tentative fix to hopper protection NPE --- pom.xml | 2 +- .../listeners/ShopProtectionListener.java | 95 ++++++++++--------- 2 files changed, 52 insertions(+), 45 deletions(-) diff --git a/pom.xml b/pom.xml index d93036ea..27c7d3df 100644 --- a/pom.xml +++ b/pom.xml @@ -31,7 +31,7 @@ org.shanerx tradeshop - 2.3.0-STABLE + 2.3.1-DEV jar TradeShop https://tradeshop.github.io/ diff --git a/src/main/java/org/shanerx/tradeshop/listeners/ShopProtectionListener.java b/src/main/java/org/shanerx/tradeshop/listeners/ShopProtectionListener.java index e89d4f5d..5431b28c 100644 --- a/src/main/java/org/shanerx/tradeshop/listeners/ShopProtectionListener.java +++ b/src/main/java/org/shanerx/tradeshop/listeners/ShopProtectionListener.java @@ -26,6 +26,7 @@ package org.shanerx.tradeshop.listeners; import org.bukkit.Bukkit; +import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.Sign; @@ -86,10 +87,16 @@ public void onInventoryMoveItem(InventoryMoveItemEvent event) { boolean fromHopper; - if (plugin.getListManager().isInventory(Objects.requireNonNull(event.getSource().getLocation()).getBlock())) { + Location srcLoc = event.getSource().getLocation(); + Location destLoc = event.getDestination().getLocation(); + + if (srcLoc == null || destLoc == null) { + return; + } + else if (plugin.getListManager().isInventory(srcLoc.getBlock())) { fromHopper = false; } - else if (plugin.getListManager().isInventory(Objects.requireNonNull(event.getDestination().getLocation()).getBlock())) { + else if (plugin.getListManager().isInventory(destLoc.getBlock())) { fromHopper = true; } else { @@ -126,56 +133,56 @@ else if (plugin.getListManager().isInventory(Objects.requireNonNull(event.getDes } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onEntityExplodeItem(EntityExplodeEvent event) { + public void onEntityExplodeItem(EntityExplodeEvent event) { if (event.isCancelled()) return; - List toRemove = new ArrayList<>(); - for (Iterator i = event.blockList().iterator(); i.hasNext(); ) { - Block b = i.next(); - if (ShopChest.isShopChest(b)) { - Shop shop = Shop.loadShop((new ShopChest(b.getLocation())).getShopSign()); - if (shop != null) { + List toRemove = new ArrayList<>(); + for (Iterator i = event.blockList().iterator(); i.hasNext(); ) { + Block b = i.next(); + if (ShopChest.isShopChest(b)) { + Shop shop = Shop.loadShop((new ShopChest(b.getLocation())).getShopSign()); + if (shop != null) { if (!Setting.findSetting((shop.getShopType().name() + "SHOP_EXPLODE").toUpperCase()).getBoolean()) - i.remove(); - else { - if (shop.getStorage() != null) - shop.getChestAsSC().resetName(); - shop.remove(); - } + i.remove(); + else { + if (shop.getStorage() != null) + shop.getChestAsSC().resetName(); + shop.remove(); + } - } + } - } else if (ShopType.isShop(b)) { + } else if (ShopType.isShop(b)) { if (!Setting.findSetting(ShopType.getType((Sign) b.getState()).name() + "SHOP_EXPLODE".toUpperCase()).getBoolean()) { - i.remove(); - - if (plugin.getVersion().isBelow(1, 14)) { - org.bukkit.material.Sign s = (org.bukkit.material.Sign) b.getState().getData(); - toRemove.add(b.getRelative(s.getAttachedFace())); - } else if (b.getType().toString().contains("WALL_SIGN")) { - BlockData data = b.getBlockData(); - if (data instanceof Directional) - toRemove.add(b.getRelative(((Directional) data).getFacing().getOppositeFace())); - } else { - toRemove.add(b.getRelative(BlockFace.DOWN)); - } - } else { - Shop shop = Shop.loadShop((Sign) b.getState()); - if (shop != null) { - - if (shop.getStorage() != null) - shop.getChestAsSC().resetName(); - - shop.remove(); - } - } - } - } - - event.blockList().removeAll(toRemove); - } + i.remove(); + + if (plugin.getVersion().isBelow(1, 14)) { + org.bukkit.material.Sign s = (org.bukkit.material.Sign) b.getState().getData(); + toRemove.add(b.getRelative(s.getAttachedFace())); + } else if (b.getType().toString().contains("WALL_SIGN")) { + BlockData data = b.getBlockData(); + if (data instanceof Directional) + toRemove.add(b.getRelative(((Directional) data).getFacing().getOppositeFace())); + } else { + toRemove.add(b.getRelative(BlockFace.DOWN)); + } + } else { + Shop shop = Shop.loadShop((Sign) b.getState()); + if (shop != null) { + + if (shop.getStorage() != null) + shop.getChestAsSC().resetName(); + + shop.remove(); + } + } + } + } + + event.blockList().removeAll(toRemove); + } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBlockBreak(BlockBreakEvent event) { From be9cbb0a1f0e61e656bb0da3bcea1f124efe2d52 Mon Sep 17 00:00:00 2001 From: Nathan Thor Date: Tue, 7 Sep 2021 09:12:46 -0700 Subject: [PATCH 2/3] Fix for NPE from Shop object in ShopProtectionListener --- .../shanerx/tradeshop/listeners/ShopProtectionListener.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/shanerx/tradeshop/listeners/ShopProtectionListener.java b/src/main/java/org/shanerx/tradeshop/listeners/ShopProtectionListener.java index 5431b28c..d5bc776c 100644 --- a/src/main/java/org/shanerx/tradeshop/listeners/ShopProtectionListener.java +++ b/src/main/java/org/shanerx/tradeshop/listeners/ShopProtectionListener.java @@ -55,7 +55,6 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import java.util.Objects; public class ShopProtectionListener extends Utils implements Listener { @@ -268,6 +267,11 @@ public void onChestOpen(PlayerInteractEvent e) { Shop shop = new ShopChest(block.getLocation()).getShop(); PlayerShopInventoryOpenEvent openEvent = new PlayerShopInventoryOpenEvent(e.getPlayer(), shop, e.getAction(), e.getItem(), e.getClickedBlock(), e.getBlockFace()); + if (shop == null) { + new ShopChest(block.getLocation()).resetName(); + return; + } + if (!Permissions.hasPermission(e.getPlayer(), Permissions.ADMIN) && !shop.getUsersUUID().contains(e.getPlayer().getUniqueId())) { openEvent.setCancelled(true); } From 43e14e88cc94a345aab7dd0db2fe2159bd9d1593 Mon Sep 17 00:00:00 2001 From: Sparkling Comet Date: Thu, 9 Sep 2021 17:04:22 +0200 Subject: [PATCH 3/3] Mark 2.3.1 as STABLE --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 27c7d3df..d6832020 100644 --- a/pom.xml +++ b/pom.xml @@ -31,7 +31,7 @@ org.shanerx tradeshop - 2.3.1-DEV + 2.3.1-STABLE jar TradeShop https://tradeshop.github.io/