add getShopBySignLocation(Location signLocation) to api

This commit is contained in:
Len
2022-07-09 18:48:37 +02:00
parent 226aaa2ba2
commit 016b24987a
7 changed files with 80 additions and 52 deletions
@@ -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<Block> 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();
}
}
}
}