From b1634f9460e01bf294128bde33558a122dd874fd Mon Sep 17 00:00:00 2001 From: Andreas Troelsen Date: Sun, 22 Apr 2018 20:12:31 +0200 Subject: [PATCH] Return early from forceEnd() if there are no players in the arena. This means that the cleanup code will only run if there are players in the lobby, arena, or spectator area. This fixes the first part of #435 where the cleanup code is taking too long for large/many arenas. Originally, the force end command was meant as a way to circumvent any condition keeping players from leaving the arena and cleaning it up. In retrospect, the main reason for using force end is to "get people out of there", but since there's plenty of stuff that can go wrong when a player leaves, this isn't really that helpful, as exceptions will just cause the command to break at the same point anyway. --- src/main/java/com/garbagemule/MobArena/ArenaImpl.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/garbagemule/MobArena/ArenaImpl.java b/src/main/java/com/garbagemule/MobArena/ArenaImpl.java index 2da4cee..f8b6c44 100644 --- a/src/main/java/com/garbagemule/MobArena/ArenaImpl.java +++ b/src/main/java/com/garbagemule/MobArena/ArenaImpl.java @@ -642,10 +642,12 @@ public class ArenaImpl implements Arena @Override public void forceEnd() { - for (Player p : getAllPlayers()) { - playerLeave(p); + List players = getAllPlayers(); + if (players.isEmpty()) { + return; } + players.forEach(this::playerLeave); cleanup(); }