diff --git a/src/main/java/xyz/nucleoid/plasmid/command/GameCommand.java b/src/main/java/xyz/nucleoid/plasmid/command/GameCommand.java index dfbc4703..04b2fcd7 100644 --- a/src/main/java/xyz/nucleoid/plasmid/command/GameCommand.java +++ b/src/main/java/xyz/nucleoid/plasmid/command/GameCommand.java @@ -84,6 +84,12 @@ public static void register(CommandDispatcher dispatcher) { .executes(GameCommand::stopGameConfirmed) ) ) + .then(literal("kick") + .requires(source -> source.hasPermissionLevel(2)) + .then(argument("targets", EntityArgumentType.players()) + .executes(GameCommand::kickPlayers) + ) + ) .then(literal("join") .executes(GameCommand::joinGame) .then(GameSpaceArgument.argument("game_space") @@ -400,4 +406,29 @@ private static int listGames(CommandContext context) { return Command.SINGLE_SUCCESS; } + + private static int kickPlayers(CommandContext context) throws CommandSyntaxException { + var source = context.getSource(); + var playerManager = source.getServer().getPlayerManager(); + + var targets = EntityArgumentType.getPlayers(context, "targets"); + + int successes = 0; + + for (var target : targets) { + var gameSpace = GameSpaceManager.get().byPlayer(target); + if (gameSpace != null) { + var message = GameTexts.Kick.kick(source, target).formatted(Formatting.GRAY); + playerManager.broadcast(message, false); + + Scheduler.INSTANCE.submit(server -> { + gameSpace.getPlayers().kick(target); + }); + + successes += 1; + } + } + + return successes; + } } diff --git a/src/main/java/xyz/nucleoid/plasmid/game/GameTexts.java b/src/main/java/xyz/nucleoid/plasmid/game/GameTexts.java index 66dbbc7d..0716a08e 100644 --- a/src/main/java/xyz/nucleoid/plasmid/game/GameTexts.java +++ b/src/main/java/xyz/nucleoid/plasmid/game/GameTexts.java @@ -145,4 +145,18 @@ public static MutableText inOtherGame() { ); } } + + public static final class Kick { + public static MutableText kick(ServerCommandSource source, ServerPlayerEntity target) { + return source.isExecutedByPlayer() ? kickBy(source.getPlayer(), target) : kick(target); + } + + public static MutableText kickBy(ServerPlayerEntity source, ServerPlayerEntity target) { + return Text.translatable("text.plasmid.game.kick.by", target.getDisplayName(), source.getDisplayName()); + } + + public static MutableText kick(ServerPlayerEntity target) { + return Text.translatable("text.plasmid.game.kick", target.getDisplayName()); + } + } } diff --git a/src/main/resources/data/plasmid/lang/en_us.json b/src/main/resources/data/plasmid/lang/en_us.json index 056c3b77..5423070e 100644 --- a/src/main/resources/data/plasmid/lang/en_us.json +++ b/src/main/resources/data/plasmid/lang/en_us.json @@ -34,6 +34,8 @@ "text.plasmid.game.join.error": "An unexpected exception occurred while joining game!", "text.plasmid.game.join.no_game_open": "No games are open!", "text.plasmid.game.join.party.error": "%s players were unable to join this game!", + "text.plasmid.game.kick": "%s was kicked from the game!", + "text.plasmid.game.kick.by": "%s was kicked from the game by %s!", "text.plasmid.game.list": "Registered games:", "text.plasmid.game.locate.located": "%s is currently in the %s game. ", "text.plasmid.game.locate.player_not_in_game": "%s is not in a game!",