From 4114b62bff6b0e1b97c1cd610241c76e36ee8de9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Kosman?= Date: Sat, 31 Aug 2024 13:35:56 +0200 Subject: feat: `role` command to replace the `moles` command --- .../java/world/anhgelus/molehunt/Molehunt.java | 28 +++++++++++++++++----- .../java/world/anhgelus/molehunt/game/Game.java | 4 +--- 2 files changed, 23 insertions(+), 9 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/world/anhgelus/molehunt/Molehunt.java b/src/main/java/world/anhgelus/molehunt/Molehunt.java index 9026dab..7fa924d 100644 --- a/src/main/java/world/anhgelus/molehunt/Molehunt.java +++ b/src/main/java/world/anhgelus/molehunt/Molehunt.java @@ -124,7 +124,7 @@ public class Molehunt implements ModInitializer { if (game == null || !game.hasStarted()) { player.networkHandler.sendPacket(new OverlayMessageS2CPacket( - Text.translatable("commands.molehunt.stop.failed").setStyle(Style.EMPTY.withColor(16733525)) + Text.translatable("commands.molehunt.stop.failed").withColor(16733525) )); } else { player.networkHandler.sendPacket(new OverlayMessageS2CPacket(Text.of(game.getShortRemainingText()))); @@ -139,11 +139,27 @@ public class Molehunt implements ModInitializer { return Command.SINGLE_SUCCESS; }) )); - command.then(literal("moles").requires(source -> - (game != null && game.isAMole(source.getPlayer())) || - (source.getPlayer() != null && source.getPlayer().isSpectator()) - ).executes(context -> { - context.getSource().sendFeedback(() -> Text.translatable("commands.molehunt.moles.list").append(" " + game.getMolesAsString()),false); + command.then(literal("role").requires(ServerCommandSource::isExecutedByPlayer).executes(context -> { + if (game == null || !game.hasStarted()) { + throw (new SimpleCommandExceptionType(Text.translatable("commands.molehunt.stop.failed"))).create(); + } + + var source = context.getSource(); + + if (game.isAMole(source.getPlayer())) { + source.sendFeedback( + () -> Text.translatable("commands.molehunt.role.mole") + .append("\n\n") + .append(Text.stringifiedTranslatable("commands.molehunt.role.mole.list", game.getMolesAsString())), + false); + } else { + source.sendFeedback( + () -> Text.translatable("commands.molehunt.role.survivor") + .append("\n\n") + .append(Text.stringifiedTranslatable("commands.molehunt.role.survivor.mole_count", game.getMoles().size())), + false); + } + return Command.SINGLE_SUCCESS; })); command.then(literal("stop").requires(source -> source.hasPermissionLevel(1)).executes(context -> { diff --git a/src/main/java/world/anhgelus/molehunt/game/Game.java b/src/main/java/world/anhgelus/molehunt/game/Game.java index 0bc7270..b797b72 100644 --- a/src/main/java/world/anhgelus/molehunt/game/Game.java +++ b/src/main/java/world/anhgelus/molehunt/game/Game.java @@ -155,9 +155,7 @@ public class Game { } else { winner = new TitleS2CPacket(Text.translatable("molehunt.game.end.winners.survivors.title")); } - pm.sendToAll(new SubtitleS2CPacket(Text.translatable("molehunt.game.end.winners.subtitle") - .append(" " + getMolesAsString())) - ); + pm.sendToAll(new SubtitleS2CPacket(Text.stringifiedTranslatable("molehunt.game.end.winners.subtitle", getMolesAsString()))); pm.sendToAll(winner); pm.sendToAll(timing); moles.clear(); -- cgit v1.2.3