From 8ffa6296b1e10698e4a123d33f1e0cb7a329baf1 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 17 Feb 2023 10:24:58 +0100 Subject: [PATCH] Prevent schem selection DOS Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/fight/HotbarKit.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/HotbarKit.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/HotbarKit.java index 09ca6a2..6cd59f9 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/HotbarKit.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/HotbarKit.java @@ -26,6 +26,7 @@ import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.listener.PersonalKitCreator; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; +import de.steamwar.fightsystem.states.StateDependentTask; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -37,7 +38,9 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.potion.PotionEffect; import java.util.Collection; +import java.util.HashSet; import java.util.Objects; +import java.util.Set; import java.util.function.Consumer; public class HotbarKit extends Kit { @@ -81,8 +84,11 @@ public class HotbarKit extends Kit { public static class HotbarKitListener implements Listener { + private static final Set clicked = new HashSet<>(); + public HotbarKitListener() { new StateDependentListener(ArenaMode.AntiReplay, FightState.Setup, this); + new StateDependentTask(ArenaMode.AntiReplay, FightState.Setup, clicked::clear, 1, 1); } @EventHandler @@ -93,11 +99,13 @@ public class HotbarKit extends Kit { Player player = event.getPlayer(); int slot = player.getInventory().getHeldItemSlot(); Kit activeKit = activeKits.get(player); - System.out.println(event.getAction().name()); 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); } }