From fcb50414f0676ba67f1cd2b8239f199721749811 Mon Sep 17 00:00:00 2001 From: Melledy <52122272+Melledy@users.noreply.github.com> Date: Wed, 27 Apr 2022 10:42:59 -0700 Subject: [PATCH] Fixed concurrency issue in killall --- .../emu/grasscutter/command/commands/KillAllCommand.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/emu/grasscutter/command/commands/KillAllCommand.java b/src/main/java/emu/grasscutter/command/commands/KillAllCommand.java index 3e2466686..9636fd845 100644 --- a/src/main/java/emu/grasscutter/command/commands/KillAllCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/KillAllCommand.java @@ -4,6 +4,7 @@ import emu.grasscutter.Grasscutter; import emu.grasscutter.command.Command; import emu.grasscutter.command.CommandHandler; import emu.grasscutter.game.entity.EntityMonster; +import emu.grasscutter.game.entity.GameEntity; import emu.grasscutter.game.player.Player; import emu.grasscutter.game.world.Scene; @@ -53,10 +54,12 @@ public final class KillAllCommand implements CommandHandler { return; } - mainScene.getEntities().values().stream() + // Separate into list to avoid concurrency issue + List toKill = mainScene.getEntities().values().stream() .filter(entity -> entity instanceof EntityMonster) - .forEach(entity -> mainScene.killEntity(entity, 0)); - CommandHandler.sendMessage(sender, "Killing all monsters in scene " + mainScene.getId()); + .toList(); + toKill.stream().forEach(entity -> mainScene.killEntity(entity, 0)); + CommandHandler.sendMessage(sender, "Killing " + toKill.size() + " monsters in scene " + mainScene.getId()); } catch (NumberFormatException ignored) { CommandHandler.sendMessage(sender, "Invalid arguments."); }