From 3f167cff70b9377aed0f263c2197224313ef1c33 Mon Sep 17 00:00:00 2001 From: bazke Date: Mon, 9 Oct 2023 06:32:00 +0200 Subject: [PATCH] fix languagy stuff --- .../resources/assets/ltextras/lang/en_ud.json | 10 +++++ .../resources/assets/ltextras/lang/en_us.json | 22 +++++----- .../java/com/lovetropics/extras/LTExtras.java | 2 + .../lovetropics/extras/command/TpCommand.java | 42 +++++++++++++------ 4 files changed, 53 insertions(+), 23 deletions(-) diff --git a/src/generated/resources/assets/ltextras/lang/en_ud.json b/src/generated/resources/assets/ltextras/lang/en_ud.json index 98bd63ee..d7b38020 100644 --- a/src/generated/resources/assets/ltextras/lang/en_ud.json +++ b/src/generated/resources/assets/ltextras/lang/en_ud.json @@ -104,6 +104,16 @@ "block.ltextras.water_barrier": "ɹǝıɹɹɐᗺ ɹǝʇɐM", "block.ltextras.white_glow_sticks": "sʞɔıʇS ʍoן⅁ ǝʇıɥM", "block.ltextras.yellow_glow_sticks": "sʞɔıʇS ʍoן⅁ ʍoןןǝʎ", + "commands.tpa.general_error": "ʇɹodǝןǝʇ oʇ ǝןqɐu∩", + "commands.tpa.help.back": "buıʇɹodǝןǝʇ ǝɹoɟǝq ǝɹǝʍ noʎ ǝɹǝɥʍ oʇ ʞɔɐq ʇɹodǝןǝ⟘ - ʞɔɐq/", + "commands.tpa.help.tpa": "ɹǝʎɐןd ɐ oʇ ʇɹodǝןǝʇ oʇ ʇsǝnbǝᴚ - >ɹǝʎɐןd< ɐdʇ/", + "commands.tpa.help.tpaccept": "ɹǝʎɐןd ɐ ɯoɹɟ ʇsǝnbǝɹ ʇɹodǝןǝʇ ɐ ʇdǝɔɔⱯ - >ɹǝʎɐןd< ʇdǝɔɔɐdʇ/", + "commands.tpa.here": "]ǝɹǝɥ[", + "commands.tpa.player_not_found": "punoɟ ʇou ɹǝʎɐןԀ", + "commands.tpa.request": "ʇdǝɔɔɐ oʇ )%s ʇdǝɔɔɐdʇ/( %s ʞɔıןƆ ˙noʎ oʇ ʇɹodǝןǝʇ oʇ sʇuɐʍ %s", + "commands.tpa.request_sent": "ʇuǝs ʇsǝnbǝᴚ", + "commands.tpa.too_much": "ɥɔnɯ ooʇ ʇɐɥʇ buıop ǝɹɐ noʎ", + "commands.tpa.tp_accepted": "uɹnʇǝɹ oʇ ʞɔɐq/ ǝs∩ ˙ʇsǝnbǝɹ ʇɹodǝןǝʇ ɹnoʎ pǝʇdǝɔɔɐ sɐɥ %s", "effect.ltextras.fish_eye": "ǝʎƎ ɥsıℲ", "entity.ltextras.collectible": "ǝןqıʇɔǝןןoƆ", "entity.ltextras.party_beam": "ɯɐǝᗺ ʎʇɹɐԀ", diff --git a/src/generated/resources/assets/ltextras/lang/en_us.json b/src/generated/resources/assets/ltextras/lang/en_us.json index f49049ce..482bb28c 100644 --- a/src/generated/resources/assets/ltextras/lang/en_us.json +++ b/src/generated/resources/assets/ltextras/lang/en_us.json @@ -104,6 +104,16 @@ "block.ltextras.water_barrier": "Water Barrier", "block.ltextras.white_glow_sticks": "White Glow Sticks", "block.ltextras.yellow_glow_sticks": "Yellow Glow Sticks", + "commands.tpa.general_error": "Unable to teleport", + "commands.tpa.help.back": "/back - Teleport back to where you were before teleporting", + "commands.tpa.help.tpa": "/tpa - Request to teleport to a player", + "commands.tpa.help.tpaccept": "/tpaccept - Accept a teleport request from a player", + "commands.tpa.here": "[here]", + "commands.tpa.player_not_found": "Player not found", + "commands.tpa.request": "%s wants to teleport to you. Click %s (/tpaccept %s) to accept", + "commands.tpa.request_sent": "Request sent", + "commands.tpa.too_much": "You are doing that too much", + "commands.tpa.tp_accepted": "%s has accepted your teleport request. Use /back to return", "effect.ltextras.fish_eye": "Fish Eye", "entity.ltextras.collectible": "Collectible", "entity.ltextras.party_beam": "Party Beam", @@ -115,15 +125,5 @@ "spawnitems.set_not_restorable": "The spawn item set %s cannot be restored!", "spawnitems.unknown_set": "Unknown spawn item set: %s", "toast.collectible.item": " + %s", - "toast.collectible.title": "New Collectible!", - "commands.tpa.request": "%s wants to teleport to you. Click %s (/tpaccept %s) to accept", - "commands.tpa.here": "[here]", - "commands.tpa.tp_accepted": "%s has accepted your teleport request. Use /back to return", - "commands.tpa.too_much": "You are doing that too much", - "commands.tpa.request_sent": "Request sent", - "commands.tpa.player_not_found": "Player not found", - "commands.tpa.general_error": "Unable to teleport", - "commands.tpa.help.tpa": "/tpa - Request to teleport to a player", - "commands.tpa.help.tpaccept": "/tpaccept - Accept a teleport request from a player", - "commands.tpa.help.back": "/back - Teleport back to where you were before teleporting" + "toast.collectible.title": "New Collectible!" } \ No newline at end of file diff --git a/src/main/java/com/lovetropics/extras/LTExtras.java b/src/main/java/com/lovetropics/extras/LTExtras.java index 23860ee9..5985ef53 100644 --- a/src/main/java/com/lovetropics/extras/LTExtras.java +++ b/src/main/java/com/lovetropics/extras/LTExtras.java @@ -91,6 +91,8 @@ public LTExtras() { p.add("spawnitems.set_not_restorable", "The spawn item set %s cannot be restored!"); p.add("spawnitems.unknown_set", "Unknown spawn item set: %s"); p.add("spawnitems.restored_successfully", "Items restored!"); + + TpCommand.addTranslations(p); }) .generic(TAB_ID.getPath(), Registries.CREATIVE_MODE_TAB, () -> CreativeModeTab.builder() .title(registrate().addLang("itemGroup", TAB_ID, "LTExtras")) diff --git a/src/main/java/com/lovetropics/extras/command/TpCommand.java b/src/main/java/com/lovetropics/extras/command/TpCommand.java index 3e0ef04e..5069e520 100644 --- a/src/main/java/com/lovetropics/extras/command/TpCommand.java +++ b/src/main/java/com/lovetropics/extras/command/TpCommand.java @@ -8,6 +8,8 @@ import com.google.common.util.concurrent.ExecutionError; import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import com.lovetropics.extras.LTExtras; +import com.lovetropics.extras.effect.ExtraEffects; import com.mojang.brigadier.Command; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.StringArgumentType; @@ -15,6 +17,9 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.DynamicCommandExceptionType; +import com.tterrag.registrate.Registrate; +import com.tterrag.registrate.providers.ProviderType; +import com.tterrag.registrate.providers.RegistrateLangProvider; import net.minecraft.ChatFormatting; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; @@ -95,7 +100,7 @@ public static void register(CommandDispatcher dispatcher) { // @formatter:on } - private static int tpHelp(CommandContext ctx) throws CommandSyntaxException { + private static int tpHelp(final CommandContext ctx) throws CommandSyntaxException { final ServerPlayer player = nonNullSourcePlayer(ctx); player.sendSystemMessage(Component.translatable("commands.tpa.tpa_help")); @@ -105,7 +110,7 @@ private static int tpHelp(CommandContext ctx) throws Command return Command.SINGLE_SUCCESS; } - private static int tpBack(CommandContext ctx) throws CommandSyntaxException { + private static int tpBack(final CommandContext ctx) throws CommandSyntaxException { final BlockPos blockPos = backCache.getIfPresent(ctx.getSource().getDisplayName().getString().toLowerCase()); if (blockPos == null) { throw GENERAL_ERROR.create(null); @@ -118,7 +123,7 @@ private static int tpBack(CommandContext ctx) throws Command return Command.SINGLE_SUCCESS; } - private static int tpAccept(CommandContext ctx) throws CommandSyntaxException { + private static int tpAccept(final CommandContext ctx) throws CommandSyntaxException { final String tpRequester = ctx.getArgument(ARGUMENT_NAME, String.class); final String requestedTarget = requestCache.getIfPresent(tpRequester); @@ -133,7 +138,7 @@ private static int tpAccept(CommandContext ctx) throws Comma return Command.SINGLE_SUCCESS; } - private static int acceptAllTpRequests(CommandContext ctx) throws CommandSyntaxException { + private static int acceptAllTpRequests(final CommandContext ctx) throws CommandSyntaxException { final ServerPlayer executingPlayer = nonNullSourcePlayer(ctx); final String targetPlayerName = ctx.getSource().getDisplayName().getString(); @@ -150,7 +155,7 @@ private static int acceptAllTpRequests(CommandContext ctx) t return Command.SINGLE_SUCCESS; } - private static int tpRequest(CommandContext ctx) throws CommandSyntaxException { + private static int tpRequest(final CommandContext ctx) throws CommandSyntaxException { final ServerPlayer executingPlayer = nonNullSourcePlayer(ctx); final String requester = executingPlayer.getDisplayName().getString(); final String requesterLowerCase = requester.toLowerCase(); @@ -172,11 +177,11 @@ private static int tpRequest(CommandContext ctx) throws Comm return Command.SINGLE_SUCCESS; } - private static void teleportAndSendMessage(ServerPlayer playerToTeleport, ServerPlayer targetPlayer) { - requestCache.invalidate(playerToTeleport.getDisplayName().getString().toLowerCase()); - backCache.put(playerToTeleport.getDisplayName().toString().toLowerCase(), playerToTeleport.blockPosition()); - playerToTeleport.sendSystemMessage(Component.translatable("commands.tp_accepted", targetPlayer.getDisplayName())); - playerToTeleport.connection.teleport(targetPlayer.getX(), targetPlayer.getY(), targetPlayer.getZ(), targetPlayer.yya, targetPlayer.xxa, Collections.emptySet()); + private static void teleportAndSendMessage(ServerPlayer player, ServerPlayer target) { + requestCache.invalidate(player.getDisplayName().getString().toLowerCase()); + backCache.put(player.getDisplayName().toString().toLowerCase(), player.blockPosition()); + player.sendSystemMessage(Component.translatable("commands.tpa.tp_accepted", target.getDisplayName())); + player.connection.teleport(target.getX(), target.getY(), target.getZ(), target.yya, target.xxa, Collections.emptySet()); } private static void spamCheck(String requesterLowerCase, String targetLowerCase) throws CommandSyntaxException { @@ -186,7 +191,7 @@ private static void spamCheck(String requesterLowerCase, String targetLowerCase) } } - private static ServerPlayer nonNullSourcePlayer(CommandContext ctx) throws CommandSyntaxException { + private static ServerPlayer nonNullSourcePlayer(final CommandContext ctx) throws CommandSyntaxException { final ServerPlayer player = ctx.getSource().getPlayer(); if (player == null) { throw GENERAL_ERROR.create(null); @@ -194,11 +199,24 @@ private static ServerPlayer nonNullSourcePlayer(CommandContext ctx, String name) throws CommandSyntaxException { + private static ServerPlayer nonNullPlayerByName(final CommandContext ctx, String name) throws CommandSyntaxException { final ServerPlayer player = ctx.getSource().getServer().getPlayerList().getPlayerByName(name); if (player == null) { throw PLAYER_NOT_FOUND.create(null); } return player; } + + public static void addTranslations(final RegistrateLangProvider provider) { + provider.add("commands.tpa.request", "%s wants to teleport to you. Click %s (/tpaccept %s) to accept"); + provider.add("commands.tpa.here", "[here]"); + provider.add("commands.tpa.tp_accepted", "%s has accepted your teleport request. Use /back to return"); + provider.add("commands.tpa.too_much", "You are doing that too much"); + provider.add("commands.tpa.request_sent", "Request sent"); + provider.add("commands.tpa.player_not_found", "Player not found"); + provider.add("commands.tpa.general_error", "Unable to teleport"); + provider.add("commands.tpa.help.tpa", "/tpa - Request to teleport to a player"); + provider.add("commands.tpa.help.tpaccept", "/tpaccept - Accept a teleport request from a player"); + provider.add("commands.tpa.help.back", "/back - Teleport back to where you were before teleporting"); + } }