From ae78d6277931f29324889c78612f33af205dc270 Mon Sep 17 00:00:00 2001 From: Eric Date: Sat, 21 Mar 2020 22:16:04 +0100 Subject: [PATCH] Fix shop interaction --- .../listener/ChestInteractListener.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/de/epiceric/shopchest/listener/ChestInteractListener.java b/core/src/main/java/de/epiceric/shopchest/listener/ChestInteractListener.java index 616378d..9dc4d33 100644 --- a/core/src/main/java/de/epiceric/shopchest/listener/ChestInteractListener.java +++ b/core/src/main/java/de/epiceric/shopchest/listener/ChestInteractListener.java @@ -17,11 +17,14 @@ import de.epiceric.shopchest.api.ShopChest; import de.epiceric.shopchest.api.config.Config; import de.epiceric.shopchest.api.event.ShopBuySellEvent; import de.epiceric.shopchest.api.event.ShopCreateEvent; +import de.epiceric.shopchest.api.event.ShopEditEvent; import de.epiceric.shopchest.api.event.ShopInfoEvent; import de.epiceric.shopchest.api.event.ShopOpenEvent; import de.epiceric.shopchest.api.event.ShopRemoveEvent; import de.epiceric.shopchest.api.event.ShopBuySellEvent.Type; import de.epiceric.shopchest.api.flag.CreateFlag; +import de.epiceric.shopchest.api.flag.EditFlag; +import de.epiceric.shopchest.api.flag.Flag; import de.epiceric.shopchest.api.flag.InfoFlag; import de.epiceric.shopchest.api.flag.OpenFlag; import de.epiceric.shopchest.api.flag.RemoveFlag; @@ -57,7 +60,8 @@ public class ChestInteractListener implements Listener { if (shopOpt.isPresent()) { Shop shop = shopOpt.get(); if (e.getAction() == Action.RIGHT_CLICK_BLOCK) { - player.getFlag().ifPresent(flag -> { + if (player.getFlag().isPresent()) { + Flag flag = player.getFlag().get(); if (flag instanceof InfoFlag) { plugin.getServer().getPluginManager().callEvent(new ShopInfoEvent(player, shop)); e.setCancelled(true); @@ -68,15 +72,21 @@ public class ChestInteractListener implements Listener { ShopOpenEvent event = new ShopOpenEvent(player, shop); plugin.getServer().getPluginManager().callEvent(event); e.setCancelled(event.isCancelled()); + } else if (flag instanceof EditFlag) { + EditFlag editFlag = (EditFlag) flag; + plugin.getServer().getPluginManager().callEvent(new ShopEditEvent(player, shop, editFlag.getItemStack(), + editFlag.getAmount(), editFlag.getBuyPrice(), editFlag.getSellPrice())); + e.setCancelled(true); } else if (flag instanceof CreateFlag) { e.setCancelled(true); player.sendMessage("§cThis chest already is a shop."); // TODO: i18n } player.removeFlag(); - }); - } else if (e.hasItem() && e.getItem().getType() == Config.CORE_SHOP_INFO_ITEM.get()) { - plugin.getServer().getPluginManager().callEvent(new ShopInfoEvent(player, shopOpt.get())); - e.setCancelled(true); + } else if (e.hasItem() && e.getItem().getType() == Config.CORE_SHOP_INFO_ITEM.get()) { + plugin.getServer().getPluginManager().callEvent(new ShopInfoEvent(player, shopOpt.get())); + e.setCancelled(true); + return; + } } else { if (player.ownsShop(shop)) { return; // vendors cannot buy at their own shops