diff --git a/plugin.yml b/plugin.yml index 6210e02..d6c427a 100644 --- a/plugin.yml +++ b/plugin.yml @@ -2,7 +2,7 @@ name: ShopChest main: de.epiceric.shopchest.ShopChest -version: 1.4.9 +version: 1.4.10 author: EpicEric website: https://www.spigotmc.org/resources/shopchest.11431/ depend: [Vault] diff --git a/src/de/epiceric/shopchest/event/ProtectChest.java b/src/de/epiceric/shopchest/event/ProtectChest.java index ae094a6..c2f413c 100644 --- a/src/de/epiceric/shopchest/event/ProtectChest.java +++ b/src/de/epiceric/shopchest/event/ProtectChest.java @@ -1,10 +1,18 @@ package de.epiceric.shopchest.event; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.Chest; +import org.bukkit.block.DoubleChest; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.inventory.InventoryHolder; +import de.epiceric.shopchest.ShopChest; import de.epiceric.shopchest.config.Config; +import de.epiceric.shopchest.shop.Shop; import de.epiceric.shopchest.utils.ShopUtils; public class ProtectChest implements Listener { @@ -19,4 +27,42 @@ public class ProtectChest implements Listener { } } + @EventHandler + public void onBlockPlace(BlockPlaceEvent e) { + Block b = e.getBlockPlaced(); + if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) { + + Chest c = (Chest) b.getState(); + InventoryHolder ih = c.getInventory().getHolder(); + + if (ih instanceof DoubleChest) { + DoubleChest dc = (DoubleChest) ih; + Chest r = (Chest) dc.getRightSide(); + Chest l = (Chest) dc.getLeftSide(); + + if (ShopUtils.isShop(r.getLocation()) || ShopUtils.isShop(l.getLocation())) { + Shop shop; + + if (b.getLocation().equals(r.getLocation())) { + shop = ShopUtils.getShop(l.getLocation()); + ShopUtils.removeShop(shop); + } else if (b.getLocation().equals(l.getLocation())) { + shop = ShopUtils.getShop(r.getLocation()); + ShopUtils.removeShop(shop); + } else { + return; + } + + shop.getItem().remove(); + + Shop newShop = new Shop(ShopChest.getInstance(), shop.getVendor(), shop.getProduct(), shop.getLocation(), shop.getBuyPrice(), shop.getSellPrice(), shop.isInfinite()); + ShopUtils.addShop(newShop); + + } + + } + + } + } + }