mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-24 03:38:04 +00:00
Fixed concurrency issue in killall
This commit is contained in:
parent
e34ab885a3
commit
fcb50414f0
@ -4,6 +4,7 @@ import emu.grasscutter.Grasscutter;
|
|||||||
import emu.grasscutter.command.Command;
|
import emu.grasscutter.command.Command;
|
||||||
import emu.grasscutter.command.CommandHandler;
|
import emu.grasscutter.command.CommandHandler;
|
||||||
import emu.grasscutter.game.entity.EntityMonster;
|
import emu.grasscutter.game.entity.EntityMonster;
|
||||||
|
import emu.grasscutter.game.entity.GameEntity;
|
||||||
import emu.grasscutter.game.player.Player;
|
import emu.grasscutter.game.player.Player;
|
||||||
import emu.grasscutter.game.world.Scene;
|
import emu.grasscutter.game.world.Scene;
|
||||||
|
|
||||||
@ -53,10 +54,12 @@ public final class KillAllCommand implements CommandHandler {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mainScene.getEntities().values().stream()
|
// Separate into list to avoid concurrency issue
|
||||||
|
List<GameEntity> toKill = mainScene.getEntities().values().stream()
|
||||||
.filter(entity -> entity instanceof EntityMonster)
|
.filter(entity -> entity instanceof EntityMonster)
|
||||||
.forEach(entity -> mainScene.killEntity(entity, 0));
|
.toList();
|
||||||
CommandHandler.sendMessage(sender, "Killing all monsters in scene " + mainScene.getId());
|
toKill.stream().forEach(entity -> mainScene.killEntity(entity, 0));
|
||||||
|
CommandHandler.sendMessage(sender, "Killing " + toKill.size() + " monsters in scene " + mainScene.getId());
|
||||||
} catch (NumberFormatException ignored) {
|
} catch (NumberFormatException ignored) {
|
||||||
CommandHandler.sendMessage(sender, "Invalid arguments.");
|
CommandHandler.sendMessage(sender, "Invalid arguments.");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user