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 --- .../resources/assets/molehunt/lang/en_us.json | 10 ++++---- .../resources/assets/molehunt/lang/fr_fr.json | 12 ++++++---- .../java/world/anhgelus/molehunt/Molehunt.java | 28 +++++++++++++++++----- .../java/world/anhgelus/molehunt/game/Game.java | 4 +--- 4 files changed, 36 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/client/resources/assets/molehunt/lang/en_us.json b/src/client/resources/assets/molehunt/lang/en_us.json index 5896c03..0158b58 100644 --- a/src/client/resources/assets/molehunt/lang/en_us.json +++ b/src/client/resources/assets/molehunt/lang/en_us.json @@ -2,16 +2,18 @@ "commands.molehunt.stop.failed": "The Molehunt game has not been started yet.", "commands.molehunt.timer.show": "Showing Molehunt timer.", "commands.molehunt.timer.hide": "Hiding Molehunt timer.", - "commands.molehunt.moles.list": "List of moles:", - "commands.molehunt.moles.list.deny": "You can't see the list of moles.", + "commands.molehunt.role.mole": "§cYou are a Mole.\nKill all the survivors before the timer runs out.", + "commands.molehunt.role.mole.list": "§eThe moles are: %s", + "commands.molehunt.role.survivor": "§aYou are not the Mole. \nSurvive until the timer runs out, and try to discover who's the Mole.", + "commands.molehunt.role.survivor.mole_count": "§eThere are %d §emoles among you.", "commands.molehunt.stop.success": "The Molehunt game has been stopped.", "molehunt.game.end.suspense.title": "§eAnd the winners are...", "molehunt.game.end.winners.moles.title": "§cThe Moles!", "molehunt.game.end.winners.survivors.title": "§aNot the Moles!", - "molehunt.game.end.winners.subtitle": "§6The Moles were", + "molehunt.game.end.winners.subtitle": "§6The Moles were %s", "molehunt.game.start.suspense": "§eYou are...", "molehunt.game.start.mole.title": "§cThe Mole!", - "molehunt.game.start.mole.subtitle": "§eGet the list of moles with §6/molehunt moles", + "molehunt.game.start.mole.subtitle": "§eGet the list of moles with §6/molehunt role§e.", "molehunt.game.start.survivor.title": "§aNot the Mole!", "molehunt.game.start.survivor.subtitle": "§eTry to survive and find out who's the mole!", "gamerule.molehunt:gameDuration": "Molehunt: Duration of a game", diff --git a/src/client/resources/assets/molehunt/lang/fr_fr.json b/src/client/resources/assets/molehunt/lang/fr_fr.json index 42b4722..022c2ea 100644 --- a/src/client/resources/assets/molehunt/lang/fr_fr.json +++ b/src/client/resources/assets/molehunt/lang/fr_fr.json @@ -1,10 +1,12 @@ { "commands.molehunt.stop.failed": "La partie de Molehunt n'a pas encore commencé.", - "commands.molehunt.timer.show": "Affiche le timer.", - "commands.molehunt.timer.hide": "Cache le timer.", - "commands.molehunt.moles.list": "Liste des taupes:", - "commands.molehunt.moles.list.deny": "Vous ne pouvez pas voir la liste des taupes.", - "commands.molehunt.stop.success": "La partie de Molehunt a été stoppée.", + "commands.molehunt.timer.show": "Le timer est maintenant affiché.", + "commands.molehunt.timer.hide": "Le timer est maintenant caché.", + "commands.molehunt.role.mole": "§cVous êtes une taupe.\nTuez tous les survivants avant la fin de la partie..", + "commands.molehunt.role.mole.list": "§eThe moles are: %s", + "commands.molehunt.role.survivor": "§aVous n'êtes pas la taupe. \nSurvivez jusqu'à la fin, et découvrez qui sont les moles.", + "commands.molehunt.role.survivor.mole_count": "§eIl y a %d §etaupes parmi vous.", + "commands.molehunt.stop.success": "La partie de Molehunt a été arrêtée.", "molehunt.game.end.suspense.title": "§eEt les gagnants sont...", "molehunt.game.end.winners.moles.title": "§cLes Taupes !", "molehunt.game.end.winners.survivors.title": "§aPas les Taupes !", 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 From cd88b422ecab4d57e1bebc7ed29052c55e728a5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Kosman?= Date: Sat, 31 Aug 2024 13:46:24 +0200 Subject: perf: don't use `stringifiedTranslatable` when `translatable` is enough --- src/main/java/world/anhgelus/molehunt/Molehunt.java | 4 ++-- src/main/java/world/anhgelus/molehunt/game/Game.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/main/java/world/anhgelus/molehunt/Molehunt.java b/src/main/java/world/anhgelus/molehunt/Molehunt.java index 7fa924d..272a401 100644 --- a/src/main/java/world/anhgelus/molehunt/Molehunt.java +++ b/src/main/java/world/anhgelus/molehunt/Molehunt.java @@ -150,13 +150,13 @@ public class Molehunt implements ModInitializer { source.sendFeedback( () -> Text.translatable("commands.molehunt.role.mole") .append("\n\n") - .append(Text.stringifiedTranslatable("commands.molehunt.role.mole.list", game.getMolesAsString())), + .append(Text.translatable("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())), + .append(Text.translatable("commands.molehunt.role.survivor.mole_count", game.getMoles().size())), false); } diff --git a/src/main/java/world/anhgelus/molehunt/game/Game.java b/src/main/java/world/anhgelus/molehunt/game/Game.java index b797b72..de5abe5 100644 --- a/src/main/java/world/anhgelus/molehunt/game/Game.java +++ b/src/main/java/world/anhgelus/molehunt/game/Game.java @@ -155,7 +155,7 @@ public class Game { } else { winner = new TitleS2CPacket(Text.translatable("molehunt.game.end.winners.survivors.title")); } - pm.sendToAll(new SubtitleS2CPacket(Text.stringifiedTranslatable("molehunt.game.end.winners.subtitle", getMolesAsString()))); + pm.sendToAll(new SubtitleS2CPacket(Text.translatable("molehunt.game.end.winners.subtitle", getMolesAsString()))); pm.sendToAll(winner); pm.sendToAll(timing); moles.clear(); -- cgit v1.2.3 From cb999a0fa6f4079a59ee642380865b3b902f1cd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Kosman?= Date: Sat, 31 Aug 2024 13:49:39 +0200 Subject: fix: french translation not being translated --- src/client/resources/assets/molehunt/lang/fr_fr.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/client/resources/assets/molehunt/lang/fr_fr.json b/src/client/resources/assets/molehunt/lang/fr_fr.json index 022c2ea..2836c35 100644 --- a/src/client/resources/assets/molehunt/lang/fr_fr.json +++ b/src/client/resources/assets/molehunt/lang/fr_fr.json @@ -3,7 +3,7 @@ "commands.molehunt.timer.show": "Le timer est maintenant affiché.", "commands.molehunt.timer.hide": "Le timer est maintenant caché.", "commands.molehunt.role.mole": "§cVous êtes une taupe.\nTuez tous les survivants avant la fin de la partie..", - "commands.molehunt.role.mole.list": "§eThe moles are: %s", + "commands.molehunt.role.mole.list": "§eLes taupes sont : %s", "commands.molehunt.role.survivor": "§aVous n'êtes pas la taupe. \nSurvivez jusqu'à la fin, et découvrez qui sont les moles.", "commands.molehunt.role.survivor.mole_count": "§eIl y a %d §etaupes parmi vous.", "commands.molehunt.stop.success": "La partie de Molehunt a été arrêtée.", -- cgit v1.2.3 From 07ec479ef0ed9d9cebf4af9c1e1e831d579a8bb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Kosman?= Date: Sat, 31 Aug 2024 14:02:36 +0200 Subject: style: use static class for color --- src/main/java/world/anhgelus/molehunt/Molehunt.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/main/java/world/anhgelus/molehunt/Molehunt.java b/src/main/java/world/anhgelus/molehunt/Molehunt.java index 272a401..9ae3bd1 100644 --- a/src/main/java/world/anhgelus/molehunt/Molehunt.java +++ b/src/main/java/world/anhgelus/molehunt/Molehunt.java @@ -17,6 +17,7 @@ import net.minecraft.network.packet.s2c.play.OverlayMessageS2CPacket; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.*; +import net.minecraft.util.Formatting; import net.minecraft.world.GameMode; import net.minecraft.world.GameRules; import org.slf4j.Logger; @@ -124,7 +125,7 @@ public class Molehunt implements ModInitializer { if (game == null || !game.hasStarted()) { player.networkHandler.sendPacket(new OverlayMessageS2CPacket( - Text.translatable("commands.molehunt.stop.failed").withColor(16733525) + Text.translatable("commands.molehunt.stop.failed").formatted(Formatting.RED) )); } else { player.networkHandler.sendPacket(new OverlayMessageS2CPacket(Text.of(game.getShortRemainingText()))); -- cgit v1.2.3 From 6f65825e1504a1090405685404e7cbc59bd0f44b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Kosman?= Date: Sat, 31 Aug 2024 14:03:41 +0200 Subject: style: rename translation key --- src/client/resources/assets/molehunt/lang/en_us.json | 2 +- src/client/resources/assets/molehunt/lang/fr_fr.json | 2 +- src/main/java/world/anhgelus/molehunt/Molehunt.java | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/client/resources/assets/molehunt/lang/en_us.json b/src/client/resources/assets/molehunt/lang/en_us.json index 0158b58..267230a 100644 --- a/src/client/resources/assets/molehunt/lang/en_us.json +++ b/src/client/resources/assets/molehunt/lang/en_us.json @@ -1,5 +1,5 @@ { - "commands.molehunt.stop.failed": "The Molehunt game has not been started yet.", + "commands.molehunt.error.game_not_started": "The Molehunt game has not been started yet.", "commands.molehunt.timer.show": "Showing Molehunt timer.", "commands.molehunt.timer.hide": "Hiding Molehunt timer.", "commands.molehunt.role.mole": "§cYou are a Mole.\nKill all the survivors before the timer runs out.", diff --git a/src/client/resources/assets/molehunt/lang/fr_fr.json b/src/client/resources/assets/molehunt/lang/fr_fr.json index 2836c35..62c10ca 100644 --- a/src/client/resources/assets/molehunt/lang/fr_fr.json +++ b/src/client/resources/assets/molehunt/lang/fr_fr.json @@ -1,5 +1,5 @@ { - "commands.molehunt.stop.failed": "La partie de Molehunt n'a pas encore commencé.", + "commands.molehunt.error.game_not_started": "La partie de Molehunt n'a pas encore commencé.", "commands.molehunt.timer.show": "Le timer est maintenant affiché.", "commands.molehunt.timer.hide": "Le timer est maintenant caché.", "commands.molehunt.role.mole": "§cVous êtes une taupe.\nTuez tous les survivants avant la fin de la partie..", diff --git a/src/main/java/world/anhgelus/molehunt/Molehunt.java b/src/main/java/world/anhgelus/molehunt/Molehunt.java index 9ae3bd1..86668e3 100644 --- a/src/main/java/world/anhgelus/molehunt/Molehunt.java +++ b/src/main/java/world/anhgelus/molehunt/Molehunt.java @@ -125,7 +125,7 @@ public class Molehunt implements ModInitializer { if (game == null || !game.hasStarted()) { player.networkHandler.sendPacket(new OverlayMessageS2CPacket( - Text.translatable("commands.molehunt.stop.failed").formatted(Formatting.RED) + Text.translatable("commands.molehunt.error.game_not_started").formatted(Formatting.RED) )); } else { player.networkHandler.sendPacket(new OverlayMessageS2CPacket(Text.of(game.getShortRemainingText()))); @@ -142,7 +142,7 @@ public class Molehunt implements ModInitializer { )); command.then(literal("role").requires(ServerCommandSource::isExecutedByPlayer).executes(context -> { if (game == null || !game.hasStarted()) { - throw (new SimpleCommandExceptionType(Text.translatable("commands.molehunt.stop.failed"))).create(); + throw (new SimpleCommandExceptionType(Text.translatable("commands.molehunt.error.game_not_started"))).create(); } var source = context.getSource(); @@ -165,7 +165,7 @@ public class Molehunt implements ModInitializer { })); command.then(literal("stop").requires(source -> source.hasPermissionLevel(1)).executes(context -> { if (game == null || !game.hasStarted()) { - throw (new SimpleCommandExceptionType(Text.translatable("commands.molehunt.stop.failed"))).create(); + throw (new SimpleCommandExceptionType(Text.translatable("commands.molehunt.error.game_not_started"))).create(); } game.stop(); -- cgit v1.2.3