mirror of
https://github.com/amalthea-mc/ShopChest.git
synced 2024-11-10 04:31:06 +00:00
parent
5a975661eb
commit
ade20c8255
@ -5,16 +5,17 @@ import de.epiceric.shopchest.language.LanguageUtils;
|
|||||||
import de.epiceric.shopchest.language.LocalizedMessage;
|
import de.epiceric.shopchest.language.LocalizedMessage;
|
||||||
import de.epiceric.shopchest.shop.Shop;
|
import de.epiceric.shopchest.shop.Shop;
|
||||||
import de.epiceric.shopchest.utils.ShopUtils;
|
import de.epiceric.shopchest.utils.ShopUtils;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.block.Chest;
|
import org.bukkit.block.Chest;
|
||||||
import org.bukkit.block.DoubleChest;
|
import org.bukkit.block.DoubleChest;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
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.BlockExplodeEvent;
|
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||||
import org.bukkit.event.inventory.InventoryMoveItemEvent;
|
import org.bukkit.event.inventory.InventoryMoveItemEvent;
|
||||||
@ -35,7 +36,43 @@ public class ChestProtectListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onBlockBreak(BlockBreakEvent e) {
|
public void onBlockBreak(BlockBreakEvent e) {
|
||||||
if (shopUtils.isShop(e.getBlock().getLocation())) {
|
final Block b = e.getBlock();
|
||||||
|
|
||||||
|
if (shopUtils.isShop(b.getLocation())) {
|
||||||
|
final Shop shop = shopUtils.getShop(e.getBlock().getLocation());
|
||||||
|
Player p = e.getPlayer();
|
||||||
|
|
||||||
|
if (p.isSneaking()) {
|
||||||
|
if (shop.getVendor().getUniqueId().equals(p.getUniqueId())) {
|
||||||
|
shopUtils.removeShop(shop, true);
|
||||||
|
|
||||||
|
if (shop.getInventoryHolder() instanceof DoubleChest) {
|
||||||
|
DoubleChest dc = (DoubleChest) shop.getInventoryHolder();
|
||||||
|
final Chest l = (Chest) dc.getLeftSide();
|
||||||
|
final Chest r = (Chest) dc.getRightSide();
|
||||||
|
|
||||||
|
Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Shop newShop = null;
|
||||||
|
|
||||||
|
if (b.getLocation().equals(l.getLocation()))
|
||||||
|
newShop = new Shop(shop.getID(), plugin, shop.getVendor(), shop.getProduct(), r.getLocation(), shop.getBuyPrice(), shop.getSellPrice(), shop.getShopType());
|
||||||
|
else if (b.getLocation().equals(r.getLocation()))
|
||||||
|
newShop = new Shop(shop.getID(), plugin, shop.getVendor(), shop.getProduct(), l.getLocation(), shop.getBuyPrice(), shop.getSellPrice(), shop.getShopType());
|
||||||
|
|
||||||
|
shopUtils.addShop(newShop, true);
|
||||||
|
}
|
||||||
|
}, 1L);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
plugin.debug(p.getName() + " broke his shop (#" + shop.getID() + ")");
|
||||||
|
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_REMOVED));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
e.getPlayer().sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.CANNOT_BREAK_SHOP));
|
e.getPlayer().sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.CANNOT_BREAK_SHOP));
|
||||||
}
|
}
|
||||||
|
@ -209,6 +209,9 @@ public class ShopInteractListener implements Listener {
|
|||||||
} else if (e.getAction() == Action.LEFT_CLICK_BLOCK) {
|
} else if (e.getAction() == Action.LEFT_CLICK_BLOCK) {
|
||||||
|
|
||||||
if (shopUtils.isShop(b.getLocation())) {
|
if (shopUtils.isShop(b.getLocation())) {
|
||||||
|
if (p.isSneaking())
|
||||||
|
return;
|
||||||
|
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
Shop shop = shopUtils.getShop(b.getLocation());
|
Shop shop = shopUtils.getShop(b.getLocation());
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user