Skip to content

Commit

Permalink
Merge pull request #103 from Tradeshop/2.3.1
Browse files Browse the repository at this point in the history
Add tentative fix to hopper protection NPE
  • Loading branch information
SparklingComet authored Sep 9, 2021
2 parents d228079 + 43e14e8 commit 12cb3be
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 46 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

<groupId>org.shanerx</groupId>
<artifactId>tradeshop</artifactId>
<version>2.3.0-STABLE</version>
<version>2.3.1-STABLE</version>
<packaging>jar</packaging>
<name>TradeShop</name>
<url>https://tradeshop.github.io/</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -54,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 {

Expand Down Expand Up @@ -86,10 +86,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 {
Expand Down Expand Up @@ -126,56 +132,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<Block> toRemove = new ArrayList<>();
for (Iterator<Block> 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<Block> toRemove = new ArrayList<>();
for (Iterator<Block> 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) {
Expand Down Expand Up @@ -261,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);
}
Expand Down

0 comments on commit 12cb3be

Please sign in to comment.