fix: switch all translation blocks to pick up color codes

This commit is contained in:
Sekwah 2023-04-07 02:45:05 +01:00
parent 55de809349
commit ebc2196511
12 changed files with 27 additions and 46 deletions

View File

@ -62,17 +62,17 @@ public class CommandWithSubCommands implements CommandTemplate {
catch(NumberFormatException e) {
String subCommand = args[1].toLowerCase();
if(this.subCommandRegistry.isArgRegistered(subCommand)) {
sender.sendMessage(Lang.translateInsertVariablesColor("command.help.subcommandheader",
sender.sendMessage(Lang.translateInsertVariables("command.help.subcommandheader",
commandExecuted.substring(0,1).toUpperCase() + commandExecuted.substring(1).toLowerCase(), subCommand));
sender.sendMessage("\u00A77" + this.getSubCommand(subCommand).getDetailedHelpText());
}
else {
sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translateInsertVariablesColor("command.help.invalidhelp", args[1]));
sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translateInsertVariables("command.help.invalidhelp", args[1]));
}
return;
}
}
sender.sendMessage(Lang.translateInsertVariablesColor("command.help.header",
sender.sendMessage(Lang.translateInsertVariables("command.help.header",
commandExecuted.substring(0,1).toUpperCase() + commandExecuted.substring(1).toLowerCase(), helpPage, pages));
sender.sendMessage("\u00A7a█\u00A77 = Permission \u00A7c█\u00A77 = No Permission");
int subCommandOffset = (helpPage - 1) * this.subCommandsPerPage;
@ -95,17 +95,17 @@ public class CommandWithSubCommands implements CommandTemplate {
subCommand.onCommand(sender, args);
}
else {
sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translateInsertVariablesColor("command.subcommand.nopermission",
sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translateInsertVariables("command.subcommand.nopermission",
commandExecuted));
}
return;
}
}
sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translateColor("command.subcommand.invalid"));
sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("command.subcommand.invalid"));
}
}
else {
sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translateInsertVariablesColor("command.noargs", commandExecuted));
sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translateInsertVariables("command.noargs", commandExecuted));
}
}

View File

@ -1,11 +1,9 @@
package com.sekwah.advancedportals.core.commands.subcommands.desti;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.commands.SubCommand;
import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer;
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
import com.sekwah.advancedportals.core.data.DataTag;
import com.sekwah.advancedportals.core.destination.Destination;
import com.sekwah.advancedportals.core.util.Lang;
import com.sekwah.advancedportals.core.util.TagReader;
@ -19,7 +17,7 @@ public class CreateDestiSubCommand implements SubCommand {
if(args.length > 1) {
PlayerContainer player = sender.getPlayerContainer();
if(player == null) {
sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translate("command.createdesti.console"));
sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("command.createdesti.console"));
return;
}
ArrayList<DataTag> destiTags = TagReader.getTagsFromArgs(args);
@ -43,7 +41,7 @@ public class CreateDestiSubCommand implements SubCommand {
}*/
}
else {
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translate("command.error.noname"));
sender.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("command.error.noname"));
}
}

View File

@ -1,16 +1,13 @@
package com.sekwah.advancedportals.core.commands.subcommands.portal;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.commands.SubCommand;
import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer;
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
import com.sekwah.advancedportals.core.data.DataTag;
import com.sekwah.advancedportals.core.portal.AdvancedPortal;
import com.sekwah.advancedportals.core.util.Lang;
import com.sekwah.advancedportals.core.util.TagReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class CreatePortalSubCommand implements SubCommand {
@ -20,7 +17,7 @@ public class CreatePortalSubCommand implements SubCommand {
if(args.length > 1) {
PlayerContainer player = sender.getPlayerContainer();
if(player == null) {
sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translate("command.create.console"));
sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("command.create.console"));
return;
}
ArrayList<DataTag> portalTags = TagReader.getTagsFromArgs(args);
@ -35,10 +32,10 @@ public class CreatePortalSubCommand implements SubCommand {
sender.sendMessage("\u00A7a" + tag.NAME + "\u00A77:\u00A7e" + tag.VALUE);
}
}*/
sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translateColor("command.create.error"));
sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("command.create.error"));
}
else {
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translate("command.error.noname"));
sender.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("command.error.noname"));
}
}

View File

@ -18,13 +18,13 @@ public class EndGatewayBlockSubCommand implements SubCommand {
public void onCommand(CommandSenderContainer sender, String[] args) {
PlayerContainer player = sender.getPlayerContainer();
if(player == null) {
sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translate("command.playeronly"));
sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("command.playeronly"));
}
else {
player.giveWool("BLACK", "\u00A78Gateway Block Placer"
, "\u00A7rThis wool is made of a magical substance",
"\u00A7rRight Click: Place portal block");
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translate("command.gatewayblock"));
sender.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("command.gatewayblock"));
}
}

View File

@ -18,13 +18,13 @@ public class EndPortalBlockSubCommand implements SubCommand {
public void onCommand(CommandSenderContainer sender, String[] args) {
PlayerContainer player = sender.getPlayerContainer();
if(player == null) {
sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translate("command.playeronly"));
sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("command.playeronly"));
}
else {
player.giveWool("BLACK", "\u00A78End Portal Block Placer"
, "\u00A7rThis wool is made of a magical substance",
"\u00A7rRight Click: Place portal block");
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translate("command.endportalblock"));
sender.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("command.endportalblock"));
}
}

View File

@ -19,7 +19,7 @@ public class LangUpdateSubCommand implements SubCommand {
@Override
public void onCommand(CommandSenderContainer sender, String[] args) {
this.portalsCore.getDataStorage().copyDefaultFile("lang/en_GB.lang", true);
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translateColor("translatedata.replaced"));
sender.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("translatedata.replaced"));
}
@Override

View File

@ -19,14 +19,14 @@ public class PortalBlockSubCommand implements SubCommand {
public void onCommand(CommandSenderContainer sender, String[] args) {
PlayerContainer player = sender.getPlayerContainer();
if(player == null) {
sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translate("command.playeronly"));
sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("command.playeronly"));
}
else {
player.giveWool("PURPLE", "\u00A75Portal Block Placer"
, "\u00A7rThis wool is made of a magical substance",
"\u00A7rRight Click: Place portal block",
"\u00A7rLeft Click: Rotate portal block");
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translate("command.portalblock"));
sender.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("command.portalblock"));
}
}

View File

@ -19,7 +19,7 @@ public class ReloadSubCommand implements SubCommand {
// TODO re-add or figure out a replacement.
//portalsCore.getPortalServices().loadPortals();
//portalsCore.getDestinationServices().loadDestinations();
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translateColor("command.reload.reloaded"));
sender.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("command.reload.reloaded"));
}
@Override

View File

@ -22,12 +22,12 @@ public class SelectorSubCommand implements SubCommand {
public void onCommand(CommandSenderContainer sender, String[] args) {
PlayerContainer player = sender.getPlayerContainer();
if(player == null) {
sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translate("command.playeronly"));
sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("command.playeronly"));
}
else {
player.giveItem(configRepo.getSelectorMaterial(), "\u00A7ePortal Region Selector"
, "\u00A7rThis wand with has the power to help", "\u00A7r create portals bistowed upon it!");
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translate("command.selector"));
sender.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("command.selector"));
}
}

View File

@ -11,7 +11,7 @@ public class VersionSubCommand implements SubCommand {
@Override
public void onCommand(CommandSenderContainer sender, String[] args) {
sender.sendMessage(Lang.translateColor("messageprefix.positive") + " Advanced Portals v" + AdvancedPortalsCore.version);
sender.sendMessage(Lang.translate("messageprefix.positive") + " Advanced Portals v" + AdvancedPortalsCore.version);
}
@Override

View File

@ -4,14 +4,12 @@ package com.sekwah.advancedportals.core.services;
import com.google.common.collect.ImmutableMap;
import com.google.gson.reflect.TypeToken;
import com.google.inject.Inject;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
import com.sekwah.advancedportals.core.data.DataTag;
import com.sekwah.advancedportals.core.data.PlayerLocation;
import com.sekwah.advancedportals.core.destination.Destination;
import com.sekwah.advancedportals.core.repository.IDestinationRepository;
import com.sekwah.advancedportals.core.util.Lang;
import com.sekwah.advancedportals.core.warphandler.TagHandler;
import java.io.IOException;
import java.lang.reflect.Type;
@ -61,11 +59,11 @@ public class DestinationServices {
public Destination createDesti(String name, PlayerContainer player, PlayerLocation playerLocation, ArrayList<DataTag> tags) {
// TODO change to write messages
if(name == null || name.equals("")) {
player.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translate("desti.error.noname"));
player.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("desti.error.noname"));
return null;
}
else if(this.destinationRepository.containsKey(name)) {
player.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translate("desti.error.takenname"));
player.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("desti.error.takenname"));
return null;
}

View File

@ -46,7 +46,9 @@ public class Lang {
public static String translate(String s) {
if (instance.languageMap.containsKey(s)) {
return instance.languageMap.get(s);
String translation = instance.languageMap.get(s);
translation = translation.replaceAll("\\\\u00A7", "\u00A7");
return translation;
} else {
return s;
}
@ -60,20 +62,6 @@ public class Lang {
return translation;
}
public static String translateInsertVariablesColor(String s, Object... args) {
String translation = instance.translateColor(s);
for (int i = 1; i <= args.length; i++) {
translation = translation.replaceAll("%" + i + "\\$s", args[i-1].toString());
}
return translation;
}
public static String translateColor(String s) {
String translation = instance.translate(s);
translation = translation.replaceAll("\\\\u00A7", "\u00A7");
return translation;
}
private void injectTranslations(Lang lang, String fileName) {
try {
//URL url = lang.getClass().getClassLoader().getResource("lang/" + fileName + ".lang");