2022-04-21 06:48:24 +08:00
|
|
|
package emu.grasscutter.command.commands;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2022-05-06 12:57:45 +08:00
|
|
|
import static emu.grasscutter.utils.Language.translate;
|
|
|
|
|
2022-07-18 17:06:17 +08:00
|
|
|
@Command(label = "killall", usage = {"[<sceneId>]"}, permission = "server.killall", permissionTargeted = "server.killall.others")
|
2022-04-21 06:48:24 +08:00
|
|
|
public final class KillAllCommand implements CommandHandler {
|
|
|
|
|
|
|
|
@Override
|
2022-05-04 14:32:09 +08:00
|
|
|
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
2022-05-04 17:16:42 +08:00
|
|
|
Scene scene = targetPlayer.getScene();
|
2022-04-21 06:48:24 +08:00
|
|
|
try {
|
|
|
|
switch (args.size()) {
|
|
|
|
case 0: // *No args*
|
|
|
|
break;
|
2022-05-04 17:16:42 +08:00
|
|
|
case 1: // [sceneId]
|
|
|
|
scene = targetPlayer.getWorld().getSceneById(Integer.parseInt(args.get(0)));
|
2022-04-21 06:48:24 +08:00
|
|
|
break;
|
|
|
|
default:
|
2022-07-21 19:35:23 +08:00
|
|
|
sendUsageMessage(sender);
|
2022-04-21 06:48:24 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} catch (NumberFormatException ignored) {
|
2022-05-10 20:33:45 +08:00
|
|
|
CommandHandler.sendMessage(sender, translate(sender, "commands.execution.argument_error"));
|
2022-04-21 06:48:24 +08:00
|
|
|
}
|
2022-05-04 17:16:42 +08:00
|
|
|
if (scene == null) {
|
2022-05-22 22:20:13 +08:00
|
|
|
CommandHandler.sendMessage(sender, translate(sender, "commands.killall.scene_not_found_in_player_world"));
|
2022-05-04 17:16:42 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Separate into list to avoid concurrency issue
|
|
|
|
final Scene sceneF = scene;
|
|
|
|
List<GameEntity> toKill = sceneF.getEntities().values().stream()
|
2023-04-01 05:19:26 +08:00
|
|
|
.filter(entity -> entity instanceof EntityMonster)
|
|
|
|
.toList();
|
2022-05-06 12:57:45 +08:00
|
|
|
toKill.forEach(entity -> sceneF.killEntity(entity, 0));
|
2022-08-21 18:53:39 +08:00
|
|
|
CommandHandler.sendMessage(sender, translate(sender, "commands.killall.kill_monsters_in_scene", toKill.size(), scene.getId()));
|
2022-04-21 06:48:24 +08:00
|
|
|
}
|
|
|
|
}
|