add getShopBySignLocation(Location signLocation) to api
This commit is contained in:
parent
226aaa2ba2
commit
2a8897397c
|
|
@ -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 <b>null</b> 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
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user