Skip to content

Commit

Permalink
fix languagy stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
bazke committed Oct 9, 2023
1 parent 77feda3 commit a2d03a3
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 23 deletions.
10 changes: 10 additions & 0 deletions src/generated/resources/assets/ltextras/lang/en_ud.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "ɯɐǝᗺ ʎʇɹɐԀ",
Expand Down
22 changes: 11 additions & 11 deletions src/generated/resources/assets/ltextras/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 <player> - Request to teleport to a player",
"commands.tpa.help.tpaccept": "/tpaccept <player> - 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",
Expand All @@ -112,15 +122,5 @@
"item.ltextras.entity_wand": "Entity Wand",
"itemGroup.ltextras.ltextras": "LTExtras",
"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 <player> - Request to teleport to a player",
"commands.tpa.help.tpaccept": "/tpaccept <player> - 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!"
}
1 change: 1 addition & 0 deletions src/main/java/com/lovetropics/extras/LTExtras.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public LTExtras() {
p.add(ExtraEffects.FISH_EYE.get(), "Fish Eye");
p.add("toast.collectible.title", "New Collectible!");
p.add("toast.collectible.item", " + %s");
TpCommand.addTranslations(p);
})
.generic(TAB_ID.getPath(), Registries.CREATIVE_MODE_TAB, () -> CreativeModeTab.builder()
.title(registrate().addLang("itemGroup", TAB_ID, "LTExtras"))
Expand Down
42 changes: 30 additions & 12 deletions src/main/java/com/lovetropics/extras/command/TpCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@
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;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
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;
Expand Down Expand Up @@ -95,7 +100,7 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
// @formatter:on
}

private static int tpHelp(CommandContext<CommandSourceStack> ctx) throws CommandSyntaxException {
private static int tpHelp(final CommandContext<CommandSourceStack> ctx) throws CommandSyntaxException {
final ServerPlayer player = nonNullSourcePlayer(ctx);

player.sendSystemMessage(Component.translatable("commands.tpa.tpa_help"));
Expand All @@ -105,7 +110,7 @@ private static int tpHelp(CommandContext<CommandSourceStack> ctx) throws Command
return Command.SINGLE_SUCCESS;
}

private static int tpBack(CommandContext<CommandSourceStack> ctx) throws CommandSyntaxException {
private static int tpBack(final CommandContext<CommandSourceStack> ctx) throws CommandSyntaxException {
final BlockPos blockPos = backCache.getIfPresent(ctx.getSource().getDisplayName().getString().toLowerCase());
if (blockPos == null) {
throw GENERAL_ERROR.create(null);
Expand All @@ -118,7 +123,7 @@ private static int tpBack(CommandContext<CommandSourceStack> ctx) throws Command
return Command.SINGLE_SUCCESS;
}

private static int tpAccept(CommandContext<CommandSourceStack> ctx) throws CommandSyntaxException {
private static int tpAccept(final CommandContext<CommandSourceStack> ctx) throws CommandSyntaxException {
final String tpRequester = ctx.getArgument(ARGUMENT_NAME, String.class);
final String requestedTarget = requestCache.getIfPresent(tpRequester);

Expand All @@ -133,7 +138,7 @@ private static int tpAccept(CommandContext<CommandSourceStack> ctx) throws Comma
return Command.SINGLE_SUCCESS;
}

private static int acceptAllTpRequests(CommandContext<CommandSourceStack> ctx) throws CommandSyntaxException {
private static int acceptAllTpRequests(final CommandContext<CommandSourceStack> ctx) throws CommandSyntaxException {
final ServerPlayer executingPlayer = nonNullSourcePlayer(ctx);

final String targetPlayerName = ctx.getSource().getDisplayName().getString();
Expand All @@ -150,7 +155,7 @@ private static int acceptAllTpRequests(CommandContext<CommandSourceStack> ctx) t
return Command.SINGLE_SUCCESS;
}

private static int tpRequest(CommandContext<CommandSourceStack> ctx) throws CommandSyntaxException {
private static int tpRequest(final CommandContext<CommandSourceStack> ctx) throws CommandSyntaxException {
final ServerPlayer executingPlayer = nonNullSourcePlayer(ctx);
final String requester = executingPlayer.getDisplayName().getString();
final String requesterLowerCase = requester.toLowerCase();
Expand All @@ -172,11 +177,11 @@ private static int tpRequest(CommandContext<CommandSourceStack> 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 {
Expand All @@ -186,19 +191,32 @@ private static void spamCheck(String requesterLowerCase, String targetLowerCase)
}
}

private static ServerPlayer nonNullSourcePlayer(CommandContext<CommandSourceStack> ctx) throws CommandSyntaxException {
private static ServerPlayer nonNullSourcePlayer(final CommandContext<CommandSourceStack> ctx) throws CommandSyntaxException {
final ServerPlayer player = ctx.getSource().getPlayer();
if (player == null) {
throw GENERAL_ERROR.create(null);
}
return player;
}

private static ServerPlayer nonNullPlayerByName(CommandContext<CommandSourceStack> ctx, String name) throws CommandSyntaxException {
private static ServerPlayer nonNullPlayerByName(final CommandContext<CommandSourceStack> 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 <player> - Request to teleport to a player");
provider.add("commands.tpa.help.tpaccept", "/tpaccept <player> - Accept a teleport request from a player");
provider.add("commands.tpa.help.back", "/back - Teleport back to where you were before teleporting");
}
}

0 comments on commit a2d03a3

Please sign in to comment.