From d5a30708a827887770321154e8b9f97bd293052f Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 21 May 2022 15:42:25 +0200 Subject: [PATCH] Fix HotbarKit Signed-off-by: Lixfel --- .../de/steamwar/fightsystem/FightSystem.java | 2 ++ .../steamwar/fightsystem/fight/HotbarKit.java | 29 +++++++++++-------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java index dc7a867..d137de1 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java @@ -28,6 +28,7 @@ import de.steamwar.fightsystem.event.Meteor; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.fight.FightWorld; +import de.steamwar.fightsystem.fight.HotbarKit; import de.steamwar.fightsystem.listener.Shutdown; import de.steamwar.fightsystem.listener.*; import de.steamwar.fightsystem.record.*; @@ -89,6 +90,7 @@ public class FightSystem extends JavaPlugin { new ArrowPickup(); new BlockFadeListener(); new LeaveableArena(); + new HotbarKit.HotbarKitListener(); new OneShotStateDependent(ArenaMode.All, FightState.PreSchemSetup, () -> Fight.playSound(SWSound.BLOCK_NOTE_PLING.getSound(), 100.0f, 2.0f)); new EnterHandler(); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/HotbarKit.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/HotbarKit.java index 6070945..4b2f00d 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/HotbarKit.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/HotbarKit.java @@ -27,7 +27,6 @@ import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; @@ -38,7 +37,7 @@ import java.util.Collection; import java.util.Objects; import java.util.function.Consumer; -public class HotbarKit extends Kit implements Listener { +public class HotbarKit extends Kit { private static final int HOTBAR_SIZE = 9; @@ -49,7 +48,6 @@ public class HotbarKit extends Kit implements Listener { super(name, inventory, armor, effects); this.nameTags = nameTags; this.onClicks = onClicks; - new StateDependentListener(ArenaMode.AntiReplay, FightState.Setup, this); } public HotbarKit() { @@ -78,15 +76,22 @@ public class HotbarKit extends Kit implements Listener { super.loadToPlayer(player); } - @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) - public void handlePlayerInteract(PlayerInteractEvent event) { - Player player = event.getPlayer(); - int slot = player.getInventory().getHeldItemSlot(); - Kit activeKit = activeKits.get(player); - if(activeKit != this || PersonalKitCreator.inKitCreator(player) || getInventory()[slot] == null) - return; + public static class HotbarKitListener implements Listener { - event.setCancelled(true); - onClicks[slot].accept(player); + public HotbarKitListener() { + new StateDependentListener(ArenaMode.AntiReplay, FightState.Setup, this); + } + + @EventHandler + public void handlePlayerInteract(PlayerInteractEvent event) { + 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); + ((HotbarKit)activeKit).onClicks[slot].accept(player); + } } }