From 2a8897397ca367ba01ac6ebd20eb3de620bad6c6 Mon Sep 17 00:00:00 2001
From: Len <40720638+destro174@users.noreply.github.com>
Date: Sat, 9 Jul 2022 16:34:38 +0200
Subject: [PATCH] add getShopBySignLocation(Location signLocation) to api
---
.../alttd/playershops/api/ShopHandler.java | 8 +++++
.../playershops/listener/ShopListener.java | 31 +++++++++++++++++++
2 files changed, 39 insertions(+)
diff --git a/api/src/main/java/com/alttd/playershops/api/ShopHandler.java b/api/src/main/java/com/alttd/playershops/api/ShopHandler.java
index 92d1fcf..a122406 100644
--- a/api/src/main/java/com/alttd/playershops/api/ShopHandler.java
+++ b/api/src/main/java/com/alttd/playershops/api/ShopHandler.java
@@ -19,6 +19,14 @@ public interface ShopHandler { // TODO finish docs
*/
Shop getShop(Location location);
+ /**
+ * Get the shop at a given location
+ *
+ * @param signLocation Location of the shopSign
+ * @return Shop at the given location or null if no shop is found there
+ */
+ Shop getShopBySignLocation(Location signLocation);
+
/**
* Checks whether there is a shop at a given location
* @param location Location to check
diff --git a/plugin/src/main/java/com/alttd/playershops/listener/ShopListener.java b/plugin/src/main/java/com/alttd/playershops/listener/ShopListener.java
index 287a632..1420e52 100644
--- a/plugin/src/main/java/com/alttd/playershops/listener/ShopListener.java
+++ b/plugin/src/main/java/com/alttd/playershops/listener/ShopListener.java
@@ -1,6 +1,15 @@
package com.alttd.playershops.listener;
import com.alttd.playershops.PlayerShops;
+import com.alttd.playershops.api.Shop;
+import com.alttd.playershops.config.Config;
+import org.bukkit.Location;
+import org.bukkit.Tag;
+import org.bukkit.block.Block;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.entity.EntityExplodeEvent;
+
+import java.util.Iterator;
public class ShopListener extends EventListener {
@@ -10,4 +19,26 @@ public class ShopListener extends EventListener {
this.plugin = plugin;
this.register(this.plugin);
}
+
+ @EventHandler(ignoreCancelled = true)
+ public void onEntityExplosion(EntityExplodeEvent event) {
+ if(!this.isRegistered) return;
+
+ Iterator blockIterator = event.blockList().iterator();
+ Shop shop = null;
+ while (blockIterator.hasNext()) {
+
+ Block block = blockIterator.next();
+ Location location = block.getLocation();
+ if (Tag.WALL_SIGNS.isTagged(block.getType())) {
+ shop = plugin.getShopHandler().getShopBySignLocation(location);
+ } else if (plugin.getShopHandler().isShopMaterial(block)) {
+ shop = plugin.getShopHandler().getShop(location);
+ }
+
+ if (shop != null) {
+ blockIterator.remove();
+ }
+ }
+ }
}