From 08c19e6a85355fd382b8d8244a36d1156cac9af1 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 22 Jun 2020 08:58:37 +0200 Subject: [PATCH] Staggered kick to prevent a lobby crash Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/IFightSystem.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/FightSystem_API/src/de/steamwar/fightsystem/IFightSystem.java b/FightSystem_API/src/de/steamwar/fightsystem/IFightSystem.java index 87856b8..bf79398 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/IFightSystem.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/IFightSystem.java @@ -46,7 +46,17 @@ public class IFightSystem { public static void shutdown(String reason){ if(reason != null) Bukkit.broadcastMessage(reason); - Bukkit.getOnlinePlayers().forEach(player -> player.kickPlayer(null)); - Bukkit.shutdown(); + //Staggered kick to prevent lobby overloading + kickNext(); + } + + private static void kickNext(){ + if(Bukkit.getOnlinePlayers().isEmpty()){ + Bukkit.shutdown(); + return; + } + + Bukkit.getOnlinePlayers().iterator().next().kickPlayer(null); + Bukkit.getScheduler().runTaskLater(plugin, IFightSystem::kickNext, 10); } }