Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MultiLanguage Support for 1.18 #67

Open
wants to merge 15 commits into
base: 1.18/dev
Choose a base branch
from
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1802.2.3]

### Added
* Add the multilanguage support. (`assets/ftbessentials/lang/en_us.json`) and make the majority of
the languages (use the AI to translate)
* Now the translator can translate the text according to the `en_us.json` file
and make more languages support.
* The added language include
* Player now can enjoy the Localization of the languages.

## [1802.2.2]

### Added
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# FTB Essentials

Use https://github.com/FTBTeam/FTB-Mods-Issues for any mod issues
Use https://github.com/FTBTeam/FTB-Mods-Issues for any mod issues
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ ftb_library_version=1802.3.11-build.177
ftb_ranks_version=1802.1.11-build.71
forge_version=40.2.1
curseforge_id=410811
curseforge_type=release
curseforge_type=release
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.minecraft.network.chat.Style;
import net.minecraft.network.chat.TextColor;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.level.storage.LevelResource;
Expand Down Expand Up @@ -187,11 +188,11 @@ public static void serverTick(TickEvent.ServerTickEvent event) {
ServerPlayer target = server.getPlayerList().getPlayer(r.target().uuid);

if (source != null) {
source.sendMessage(new TextComponent("TPA request expired!"), Util.NIL_UUID);
source.sendMessage(new TranslatableComponent("tip.ftbessentials.tpa_expired"), Util.NIL_UUID);
}

if (target != null) {
target.sendMessage(new TextComponent("TPA request expired!"), Util.NIL_UUID);
target.sendMessage(new TranslatableComponent("tip.ftbessentials.tpa_expired"), Util.NIL_UUID);
}

iterator.remove();
Expand All @@ -210,7 +211,7 @@ public static void playerServerChatHighest(ServerChatEvent event) {

if (data != null && data.muted) {
event.setCanceled(true);
event.getPlayer().displayClientMessage(new TextComponent("You can't use chat, you've been muted by an admin!").withStyle(ChatFormatting.RED), false);
event.getPlayer().displayClientMessage(new TranslatableComponent("tip.ftbessentials.muted").withStyle(ChatFormatting.RED), false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ public FTBEssentials() {
ranksMod = ModList.get().isLoaded("ftbranks");
luckpermsMod = ModList.get().isLoaded("luckperms");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.minecraft.commands.arguments.EntityArgument;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.entity.player.Inventory;
Expand All @@ -24,6 +25,7 @@
* @author LatvianModder
*/
public class CheatCommands {

public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
/*
killall
Expand Down Expand Up @@ -121,12 +123,12 @@ public static int fly(ServerPlayer player) {
data.save();
abilities.mayfly = false;
abilities.flying = false;
player.displayClientMessage(new TextComponent("Flight disabled"), true);
player.displayClientMessage(new TranslatableComponent("cheat_command_message.ftbessentials.flight_disable"), true);
} else {
data.fly = true;
data.save();
abilities.mayfly = true;
player.displayClientMessage(new TextComponent("Flight enabled"), true);
player.displayClientMessage(new TranslatableComponent("cheat_command_message.ftbessentials.flight_enable"), true);
}

player.onUpdateAbilities();
Expand All @@ -141,12 +143,12 @@ public static int god(ServerPlayer player) {
data.god = false;
data.save();
abilities.invulnerable = false;
player.displayClientMessage(new TextComponent("God mode disabled"), true);
player.displayClientMessage(new TranslatableComponent("cheat_command_message.ftbessentials.godmode_disable"), true);
} else {
data.god = true;
data.save();
abilities.invulnerable = true;
player.displayClientMessage(new TextComponent("God mode enabled"), true);
player.displayClientMessage(new TranslatableComponent("cheat_command_message.ftbessentials.godmode_enable"), true);
}

player.onUpdateAbilities();
Expand All @@ -171,7 +173,7 @@ public AbstractContainerMenu createMenu(int id, Inventory playerInventory, Playe

public static int nicknamefor(CommandSourceStack source, ServerPlayer player, String nick) {
if (nick.length() > 30) {
player.displayClientMessage(new TextComponent("Nickname too long!"), false);
player.displayClientMessage(new TranslatableComponent("cheat_command_message.ftbessentials.nickname_toolong"), false);
return 0;
}

Expand All @@ -181,9 +183,9 @@ public static int nicknamefor(CommandSourceStack source, ServerPlayer player, St
player.refreshDisplayName();

if (data.nick.isEmpty()) {
source.sendSuccess(new TextComponent("Nickname reset!"), true);
source.sendSuccess(new TranslatableComponent("cheat_command_message.ftbessentials.nickname_reset"), true);
} else {
source.sendSuccess(new TextComponent("Nickname changed to '" + data.nick + "'"), true);
source.sendSuccess(new TranslatableComponent("cheat_command_message.ftbessentials.nickname_change").append(new TextComponent(data.nick + "'")), true);
}

data.sendTabName(source.getServer());
Expand All @@ -194,15 +196,15 @@ public static int mute(CommandSourceStack source, ServerPlayer player) {
FTBEPlayerData data = FTBEPlayerData.get(player);
data.muted = true;
data.save();
source.sendSuccess(new TextComponent("").append(player.getDisplayName()).append(" has been muted by ").append(source.getDisplayName()), true);
source.sendSuccess(new TextComponent("").append(player.getDisplayName()).append(new TranslatableComponent("cheat_command_message.ftbessentials.mute")).append(source.getDisplayName()), true);
return 1;
}

public static int unmute(CommandSourceStack source, ServerPlayer player) {
FTBEPlayerData data = FTBEPlayerData.get(player);
data.muted = false;
data.save();
source.sendSuccess(new TextComponent("").append(player.getDisplayName()).append(" has been unmuted by ").append(source.getDisplayName()), true);
source.sendSuccess(new TextComponent("").append(player.getDisplayName()).append(new TranslatableComponent("cheat_command_message.ftbessentials.unmute")).append(source.getDisplayName()), true);
return 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import net.minecraft.commands.arguments.GameProfileArgument;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.server.level.ServerPlayer;

import java.util.Collections;
Expand Down Expand Up @@ -83,7 +84,7 @@ public static int home(ServerPlayer player, String name) {
TeleportPos pos = data.homes.get(name.toLowerCase());

if (pos == null) {
player.displayClientMessage(new TextComponent("Home not found!"), false);
player.displayClientMessage(new TranslatableComponent("home_command_message.ftbessentials.home_notfound"), false);
return 0;
}

Expand All @@ -98,13 +99,13 @@ public static int sethome(ServerPlayer player, String name) {
}

if (data.homes.size() >= FTBEConfig.MAX_HOMES.get(player) && !data.homes.containsKey(name.toLowerCase())) {
player.displayClientMessage(new TextComponent("Can't add any more homes!"), false);
player.displayClientMessage(new TranslatableComponent("home_command_message.ftbessentials.home_toomuch"), false);
return 0;
}

data.homes.put(name.toLowerCase(), new TeleportPos(player));
data.save();
player.displayClientMessage(new TextComponent("Home set!"), false);
player.displayClientMessage(new TranslatableComponent("home_command_message.ftbessentials.home_set"), false);
return 1;
}

Expand All @@ -117,10 +118,10 @@ public static int delhome(ServerPlayer player, String name) {

if (data.homes.remove(name.toLowerCase()) != null) {
data.save();
player.displayClientMessage(new TextComponent("Home deleted!"), false);
player.displayClientMessage(new TranslatableComponent("home_command_message.ftbessentials.home_deleted"), false);
return 1;
} else {
player.displayClientMessage(new TextComponent("Home not found!"), false);
player.displayClientMessage(new TranslatableComponent("home_command_message.ftbessentials.home_notfound"), false);
return 0;
}
}
Expand All @@ -133,7 +134,7 @@ public static int listhomes(CommandSourceStack source, GameProfile of) {
}

if (data.homes.isEmpty()) {
source.sendSuccess(new TextComponent("None"), false);
source.sendSuccess(new TranslatableComponent("home_command_message.ftbessentials.home_none"), false);
return 1;
}

Expand Down
22 changes: 11 additions & 11 deletions src/main/java/dev/ftb/mods/ftbessentials/command/MiscCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,15 @@ private static int enderChest(ServerPlayer player, @Nullable ServerPlayer target
}

public static int kickme(ServerPlayer player) {
player.connection.disconnect(new TextComponent("You kicked yourself!"));
player.connection.disconnect(new TranslatableComponent("misc_command_message.ftbessentials.kickme"));
return 1;
}

public static int trashcan(ServerPlayer player) {
player.openMenu(new MenuProvider() {
@Override
public Component getDisplayName() {
return new TextComponent("Trash Can");
return new TranslatableComponent("misc_command_name.ftbessentials.trash_can");
}

@Override
Expand Down Expand Up @@ -180,10 +180,10 @@ public static <T extends Number> int leaderboard(CommandSourceStack source, Lead
}
}

source.sendSuccess(new TextComponent("== Leaderboard [" + leaderboard.name + "] ==").withStyle(ChatFormatting.DARK_GREEN), false);
source.sendSuccess(new TranslatableComponent("misc_command_message.ftbessentials.leaderboard_title").append(new TextComponent(" ==[" + leaderboard.name + "]== ")).withStyle(ChatFormatting.DARK_GREEN), false);

if (list.isEmpty()) {
source.sendSuccess(new TextComponent("No data!").withStyle(ChatFormatting.GRAY), false);
source.sendSuccess(new TranslatableComponent("misc_command_message.ftbessentials.leaderboard_nodata").withStyle(ChatFormatting.GRAY), false);
return 1;
}

Expand Down Expand Up @@ -228,9 +228,9 @@ public static int recording(ServerPlayer player) {
player.refreshDisplayName();

if (data.recording == 1) {
player.server.getPlayerList().broadcastMessage(new TextComponent("").append(player.getDisplayName().copy().withStyle(ChatFormatting.YELLOW)).append(" is now recording!"), ChatType.CHAT, Util.NIL_UUID);
player.server.getPlayerList().broadcastMessage(new TextComponent("").append(player.getDisplayName().copy().withStyle(ChatFormatting.YELLOW)).append(new TranslatableComponent("misc_command_message.ftbessentials.recording_on")), ChatType.CHAT, Util.NIL_UUID);
} else {
player.server.getPlayerList().broadcastMessage(new TextComponent("").append(player.getDisplayName().copy().withStyle(ChatFormatting.YELLOW)).append(" is no longer recording!"), ChatType.CHAT, Util.NIL_UUID);
player.server.getPlayerList().broadcastMessage(new TextComponent("").append(player.getDisplayName().copy().withStyle(ChatFormatting.YELLOW)).append(new TranslatableComponent("misc_command_message.ftbessentials.recording_off")), ChatType.CHAT, Util.NIL_UUID);
}

data.sendTabName(player.server);
Expand All @@ -244,9 +244,9 @@ public static int streaming(ServerPlayer player) {
player.refreshDisplayName();

if (data.recording == 2) {
player.server.getPlayerList().broadcastMessage(new TextComponent("").append(player.getDisplayName().copy().withStyle(ChatFormatting.YELLOW)).append(" is now streaming!"), ChatType.CHAT, Util.NIL_UUID);
player.server.getPlayerList().broadcastMessage(new TextComponent("").append(player.getDisplayName().copy().withStyle(ChatFormatting.YELLOW)).append(new TranslatableComponent("misc_command_message.ftbessentials.streaming_on")), ChatType.CHAT, Util.NIL_UUID);
} else {
player.server.getPlayerList().broadcastMessage(new TextComponent("").append(player.getDisplayName().copy().withStyle(ChatFormatting.YELLOW)).append(" is no longer streaming!"), ChatType.CHAT, Util.NIL_UUID);
player.server.getPlayerList().broadcastMessage(new TextComponent("").append(player.getDisplayName().copy().withStyle(ChatFormatting.YELLOW)).append(new TranslatableComponent("misc_command_message.ftbessentials.streaming_off")), ChatType.CHAT, Util.NIL_UUID);
}

data.sendTabName(player.server);
Expand All @@ -264,7 +264,7 @@ public static int hat(ServerPlayer player) {

public static int nickname(ServerPlayer player, String nick) {
if (nick.length() > 30) {
player.displayClientMessage(new TextComponent("Nickname too long!"), false);
player.displayClientMessage(new TranslatableComponent("misc_command_message.ftbessentials.nickname_toolong"), false);
return 0;
}

Expand All @@ -275,9 +275,9 @@ public static int nickname(ServerPlayer player, String nick) {
player.refreshDisplayName();

if (data.nick.isEmpty()) {
player.displayClientMessage(new TextComponent("Nickname reset!"), false);
player.displayClientMessage(new TranslatableComponent("misc_command_message.ftbessentials.nickname_reset"), false);
} else {
player.displayClientMessage(new TextComponent("Nickname changed to '" + data.nick + "'"), false);
player.displayClientMessage(new TranslatableComponent("misc_command_message.ftbessentials.nickname_changedto").append(new TextComponent(data.nick + "'")), false);
}

data.sendTabName(player.server);
Expand Down
40 changes: 20 additions & 20 deletions src/main/java/dev/ftb/mods/ftbessentials/command/TPACommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.commands.arguments.EntityArgument;
import net.minecraft.network.chat.ClickEvent;
import net.minecraft.network.chat.HoverEvent;
import net.minecraft.network.chat.Style;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.chat.*;
import net.minecraft.server.level.ServerPlayer;

import java.util.HashMap;
Expand Down Expand Up @@ -81,7 +78,7 @@ public static int tpa(ServerPlayer player, ServerPlayer target, boolean here) {
}

if (REQUESTS.values().stream().anyMatch(r -> r.source == dataSource && r.target == dataTarget)) {
player.displayClientMessage(new TextComponent("Request already sent!"), false);
player.displayClientMessage(new TranslatableComponent("tpa_command_message.ftbessentials.tpa_2request"), false);
return 0;
}

Expand All @@ -95,50 +92,53 @@ public static int tpa(ServerPlayer player, ServerPlayer target, boolean here) {

TPARequest request = create(dataSource, dataTarget, here);

TextComponent component = new TextComponent("TPA request! [ ");
TranslatableComponent component = new TranslatableComponent("tpa_command_message.ftbessentials.tpa_request[");
component.append((here ? target : player).getDisplayName().copy().withStyle(ChatFormatting.YELLOW));
component.append(" \u27A1 ");
component.append((here ? player : target).getDisplayName().copy().withStyle(ChatFormatting.YELLOW));
component.append(" ]");

TextComponent component2 = new TextComponent("Click one of these: ");
component2.append(new TextComponent("Accept \u2714").setStyle(Style.EMPTY
TranslatableComponent component2 = new TranslatableComponent("tpa_command_message.ftbessentials.tpa_tip");
component2
.append(new TextComponent(new TranslatableComponent("tpa_command_message.ftbessentials.tpa_accept").getString()+ " \u2714").setStyle(Style.EMPTY
.applyFormat(ChatFormatting.GREEN)
.withBold(true)
.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tpaccept " + request.id))
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent("Click to Accept")))
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TranslatableComponent("tpa_command_message.ftbessentials.tpa_accept_info")))
));

component2.append(" | ");

component2.append(new TextComponent("Deny \u274C").setStyle(Style.EMPTY
.applyFormat(ChatFormatting.RED)
.withBold(true)
.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tpdeny " + request.id))
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent("Click to Deny")))
component2
.append(new TextComponent(new TranslatableComponent("tpa_command_message.ftbessentials.tpa_deny").getString() + " \u274C")
.setStyle(Style.EMPTY
.applyFormat(ChatFormatting.RED)
.withBold(true)
.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tpdeny " + request.id))
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TranslatableComponent("tpa_command_message.ftbessentials.tpa_deny_info")))
));

component2.append(" |");

target.displayClientMessage(component, false);
target.displayClientMessage(component2, false);

player.displayClientMessage(new TextComponent("Request sent!"), false);
player.displayClientMessage(new TranslatableComponent("tpa_command_message.ftbessentials.tpa_request"), false);
return 1;
}

public static int tpaccept(ServerPlayer player, String id) {
TPARequest request = REQUESTS.get(id);

if (request == null) {
player.displayClientMessage(new TextComponent("Invalid request!"), false);
player.displayClientMessage(new TranslatableComponent("tpa_command_message.ftbessentials.tpa_request_invalid"), false);
return 0;
}

ServerPlayer sourcePlayer = player.server.getPlayerList().getPlayer(request.source.uuid);

if (sourcePlayer == null) {
player.displayClientMessage(new TextComponent("Player has gone offline!"), false);
player.displayClientMessage(new TranslatableComponent("tpa_command_message.ftbessentials.tpa_request_offline"), false);
return 0;
}

Expand All @@ -157,18 +157,18 @@ public static int tpdeny(ServerPlayer player, String id) {
TPARequest request = REQUESTS.get(id);

if (request == null) {
player.displayClientMessage(new TextComponent("Invalid request!"), false);
player.displayClientMessage(new TranslatableComponent("tpa_command_message.ftbessentials.tpa_request_invalid"), false);
return 0;
}

REQUESTS.remove(request.id);

player.displayClientMessage(new TextComponent("Request denied!"), false);
player.displayClientMessage(new TranslatableComponent("tpa_command_message.ftbessentials.tpa_request_deny"), false);

ServerPlayer player2 = player.server.getPlayerList().getPlayer(request.target.uuid);

if (player2 != null) {
player2.displayClientMessage(new TextComponent("Request denied!"), false);
player2.displayClientMessage(new TranslatableComponent("tpa_command_message.ftbessentials.tpa_request_offline"), false);
}

return 1;
Expand Down
Loading