2022-04-21 06:48:24 +08:00
|
|
|
package emu.grasscutter.command.commands;
|
|
|
|
|
|
|
|
import emu.grasscutter.Grasscutter;
|
|
|
|
import emu.grasscutter.command.Command;
|
|
|
|
import emu.grasscutter.command.CommandHandler;
|
|
|
|
import emu.grasscutter.game.entity.EntityMonster;
|
2022-04-28 01:42:59 +08:00
|
|
|
import emu.grasscutter.game.entity.GameEntity;
|
2022-04-27 12:24:25 +08:00
|
|
|
import emu.grasscutter.game.player.Player;
|
|
|
|
import emu.grasscutter.game.world.Scene;
|
2022-04-21 06:48:24 +08:00
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
@Command(label = "killall", usage = "killall [playerUid] [sceneId]",
|
|
|
|
description = "Kill all entities", permission = "server.killall")
|
|
|
|
public final class KillAllCommand implements CommandHandler {
|
|
|
|
|
|
|
|
@Override
|
2022-04-27 12:21:57 +08:00
|
|
|
public void execute(Player sender, List<String> args) {
|
|
|
|
Scene mainScene;
|
|
|
|
Player targetPlayer;
|
2022-04-21 06:48:24 +08:00
|
|
|
|
|
|
|
try {
|
|
|
|
switch (args.size()) {
|
|
|
|
case 0: // *No args*
|
|
|
|
if (sender == null) {
|
|
|
|
CommandHandler.sendMessage(null, "Usage: killall [playerUid] [sceneId]");
|
|
|
|
return;
|
|
|
|
}
|
2022-04-27 12:21:57 +08:00
|
|
|
mainScene = sender.getScene();
|
2022-04-21 06:48:24 +08:00
|
|
|
break;
|
|
|
|
case 1: // [playerUid]
|
2022-04-27 12:21:57 +08:00
|
|
|
targetPlayer = Grasscutter.getGameServer().getPlayerByUid(Integer.parseInt(args.get(0)));
|
|
|
|
if (targetPlayer == null) {
|
2022-04-21 06:48:24 +08:00
|
|
|
CommandHandler.sendMessage(sender, "Player not found or offline.");
|
|
|
|
return;
|
|
|
|
}
|
2022-04-27 12:21:57 +08:00
|
|
|
mainScene = targetPlayer.getScene();
|
2022-04-21 06:48:24 +08:00
|
|
|
break;
|
|
|
|
case 2: // [playerUid] [sceneId]
|
2022-04-27 12:21:57 +08:00
|
|
|
targetPlayer = Grasscutter.getGameServer().getPlayerByUid(Integer.parseInt(args.get(0)));
|
|
|
|
if (targetPlayer == null) {
|
2022-04-21 06:48:24 +08:00
|
|
|
CommandHandler.sendMessage(sender, "Player not found or offline.");
|
|
|
|
return;
|
|
|
|
}
|
2022-04-27 12:21:57 +08:00
|
|
|
Scene scene = sender.getWorld().getSceneById(Integer.parseInt(args.get(1)));
|
|
|
|
if (scene == null) {
|
2022-04-21 06:48:24 +08:00
|
|
|
CommandHandler.sendMessage(sender, "Scene not found in player world");
|
|
|
|
return;
|
|
|
|
}
|
2022-04-27 12:21:57 +08:00
|
|
|
mainScene = scene;
|
2022-04-21 06:48:24 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
CommandHandler.sendMessage(sender, "Usage: killall [playerUid] [sceneId]");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-04-28 01:42:59 +08:00
|
|
|
// Separate into list to avoid concurrency issue
|
|
|
|
List<GameEntity> toKill = mainScene.getEntities().values().stream()
|
2022-04-21 06:48:24 +08:00
|
|
|
.filter(entity -> entity instanceof EntityMonster)
|
2022-04-28 01:42:59 +08:00
|
|
|
.toList();
|
|
|
|
toKill.stream().forEach(entity -> mainScene.killEntity(entity, 0));
|
|
|
|
CommandHandler.sendMessage(sender, "Killing " + toKill.size() + " monsters in scene " + mainScene.getId());
|
2022-04-21 06:48:24 +08:00
|
|
|
} catch (NumberFormatException ignored) {
|
|
|
|
CommandHandler.sendMessage(sender, "Invalid arguments.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|