From 05627a4b33eb3bad65dc36967ab0549dfe681da4 Mon Sep 17 00:00:00 2001 From: ChronosX88 Date: Wed, 4 Aug 2021 01:30:29 +0300 Subject: [PATCH] Fix incorrect sending of error message when item is command --- .../oremarket/Listeners/InventoryEvents.java | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/olliejw/oremarket/Listeners/InventoryEvents.java b/src/main/java/com/olliejw/oremarket/Listeners/InventoryEvents.java index 316e904..3f57bd2 100644 --- a/src/main/java/com/olliejw/oremarket/Listeners/InventoryEvents.java +++ b/src/main/java/com/olliejw/oremarket/Listeners/InventoryEvents.java @@ -87,6 +87,25 @@ public class InventoryEvents implements Listener { clickedItem = new ItemStack(Objects.requireNonNull(Material.matchMaterial(itemConfig))); // Item that user clicked int slot = event.getSlot(); + if (OreMarket.main().getGuiConfig().contains("items." + event.getSlot() + ".commands")) { + assert keySection != null; + for (String command : Objects.requireNonNull(OreMarket.main().getGuiConfig().getStringList("items." + event.getSlot() + ".commands"))) { + if (command != null) { + String toSend = plh.format(command, player, keySection); + if (toSend.equals("[close]")) { + player.closeInventory(); + } + else if (toSend.contains("[msg]")) { + player.sendMessage(toSend.replace("[msg] ", "")); + } + else { + Bukkit.dispatchCommand(player, toSend); + } + } + } + return; + } + if ((event.getClick() == ClickType.LEFT)) { // Sell Mode if (!OreMarket.main().getGuiConfig().getBoolean("items." + event.getSlot() + ".buyonly")) { double value = OreMarket.main().getGuiConfig().getDouble("items." + slot + ".value"); @@ -148,22 +167,6 @@ public class InventoryEvents implements Listener { player.sendMessage(ChatColor.translateAlternateColorCodes('&', message)); } } - - assert keySection != null; - for (String command : Objects.requireNonNull(OreMarket.main().getGuiConfig().getStringList("items." + event.getSlot() + ".commands"))) { - if (command != null) { - String toSend = plh.format(command, player, keySection); - if (toSend.equals("[close]")) { - player.closeInventory(); - } - else if (toSend.contains("[msg]")) { - player.sendMessage(toSend.replace("[msg] ", "")); - } - else { - Bukkit.dispatchCommand(player, toSend); - } - } - } } }