mirror of
https://github.com/amalthea-mc/ShopChest.git
synced 2024-11-09 20:21:07 +00:00
Fixed issue that the shop gets mad if a player place a chest next a shop
This commit is contained in:
parent
5e54d4c356
commit
56967951da
@ -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]
|
||||||
|
@ -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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user