From ae7d394ae2bb90b4bd5ad0a811a9a87a4f9b1eb3 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Thu, 17 Apr 2025 15:45:25 +0200 Subject: [PATCH 1/2] Enable clicking 'Ready' in inventory --- .../steamwar/fightsystem/fight/HotbarKit.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/HotbarKit.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/HotbarKit.java index 5bc1d844..6567fe87 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/HotbarKit.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/HotbarKit.java @@ -34,6 +34,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; +import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; @@ -117,5 +118,22 @@ public class HotbarKit extends Kit { ((HotbarKit)activeKit).onClicks[slot].accept(player); } + + @EventHandler + public void onInventoryClick(InventoryClickEvent event) { + int slot = event.getSlot(); + if (slot < 0 || slot >= HOTBAR_SIZE) return; + + Player player = (Player) event.getWhoClicked(); + Kit activeKit = activeKits.get(player); + if(!(activeKit instanceof HotbarKit) || PersonalKitCreator.inKitCreator(player) || activeKit.getInventory()[slot] == null) + return; + + event.setCancelled(true); + if(!clicked.add(player)) + return; + + ((HotbarKit)activeKit).onClicks[slot].accept(player); + } } } From ca35ab92340befab77261285d9d1eb3bbac16978 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sun, 20 Apr 2025 20:41:47 +0200 Subject: [PATCH 2/2] Remove code Duplication HotbarKit --- .../de/steamwar/fightsystem/fight/HotbarKit.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/HotbarKit.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/HotbarKit.java index 6567fe87..193d14ea 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/HotbarKit.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/HotbarKit.java @@ -31,6 +31,7 @@ import de.steamwar.fightsystem.states.StateDependentTask; import de.steamwar.fightsystem.utils.ItemBuilder; import org.bukkit.Material; import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; @@ -108,15 +109,7 @@ public class HotbarKit extends Kit { Player player = event.getPlayer(); int slot = player.getInventory().getHeldItemSlot(); - Kit activeKit = activeKits.get(player); - if(!(activeKit instanceof HotbarKit) || PersonalKitCreator.inKitCreator(player) || activeKit.getInventory()[slot] == null) - return; - - event.setCancelled(true); - if(!clicked.add(player)) - return; - - ((HotbarKit)activeKit).onClicks[slot].accept(player); + click(player, slot, event); } @EventHandler @@ -125,6 +118,10 @@ public class HotbarKit extends Kit { if (slot < 0 || slot >= HOTBAR_SIZE) return; Player player = (Player) event.getWhoClicked(); + click(player, slot, event); + } + + private void click(Player player, int slot, Cancellable event) { Kit activeKit = activeKits.get(player); if(!(activeKit instanceof HotbarKit) || PersonalKitCreator.inKitCreator(player) || activeKit.getInventory()[slot] == null) return;