Fixed issue that the shop gets mad if a player place a chest next a shop

This commit is contained in:
Eric 2015-09-03 21:16:40 +02:00
parent 5e54d4c356
commit 56967951da
2 changed files with 47 additions and 1 deletions

View File

@ -2,7 +2,7 @@
name: ShopChest name: ShopChest
main: de.epiceric.shopchest.ShopChest main: de.epiceric.shopchest.ShopChest
version: 1.4.9 version: 1.4.10
author: EpicEric author: EpicEric
website: https://www.spigotmc.org/resources/shopchest.11431/ website: https://www.spigotmc.org/resources/shopchest.11431/
depend: [Vault] depend: [Vault]

View File

@ -1,10 +1,18 @@
package de.epiceric.shopchest.event; 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.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent; 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.config.Config;
import de.epiceric.shopchest.shop.Shop;
import de.epiceric.shopchest.utils.ShopUtils; import de.epiceric.shopchest.utils.ShopUtils;
public class ProtectChest implements Listener { 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);
}
}
}
}
} }