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;
|
|
|
|
|
2022-05-06 12:57:45 +08:00
|
|
|
import static emu.grasscutter.utils.Language.translate;
|
|
|
|
|
2022-05-06 16:06:13 +08:00
|
|
|
@Command(label = "killall", usage = "killall [sceneId]", permission = "server.killall", permissionTargeted = "server.killall.others", description = "commands.kill.description")
|
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-05-10 20:33:45 +08:00
|
|
|
CommandHandler.sendMessage(sender, translate(sender, "commands.kill.usage"));
|
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-10 20:33:45 +08:00
|
|
|
CommandHandler.sendMessage(sender, translate(sender, "commands.kill.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()
|
|
|
|
.filter(entity -> entity instanceof EntityMonster)
|
|
|
|
.toList();
|
2022-05-06 12:57:45 +08:00
|
|
|
toKill.forEach(entity -> sceneF.killEntity(entity, 0));
|
2022-05-10 20:33:45 +08:00
|
|
|
CommandHandler.sendMessage(sender, translate(sender, "commands.kill.kill_monsters_in_scene", Integer.toString(toKill.size()), Integer.toString(scene.getId())));
|
2022-04-21 06:48:24 +08:00
|
|
|
}
|
|
|
|
}
|