Skip to content

Commit

Permalink
fix: switch all translation blocks to pick up color codes
Browse files Browse the repository at this point in the history
  • Loading branch information
sekwah41 committed Nov 18, 2024
1 parent 55de809 commit ebc2196
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,17 @@ public void onCommand(CommandSenderContainer sender, String commandExecuted, Str
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;
Expand All @@ -95,17 +95,17 @@ public void onCommand(CommandSenderContainer sender, String commandExecuted, Str
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));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -19,7 +17,7 @@ public void onCommand(CommandSenderContainer sender, String[] args) {
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);
Expand All @@ -43,7 +41,7 @@ public void onCommand(CommandSenderContainer sender, String[] args) {
}*/
}
else {
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translate("command.error.noname"));
sender.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("command.error.noname"));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -20,7 +17,7 @@ public void onCommand(CommandSenderContainer sender, String[] args) {
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);
Expand All @@ -35,10 +32,10 @@ public void onCommand(CommandSenderContainer sender, String[] args) {
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"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public LangUpdateSubCommand() {
@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void onCommand(CommandSenderContainer sender, String[] args) {
// 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
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;
Expand Down Expand Up @@ -61,11 +59,11 @@ public ImmutableMap<String, Destination> getDestinations() {
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;
}

Expand Down
18 changes: 3 additions & 15 deletions core/src/main/java/com/sekwah/advancedportals/core/util/Lang.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ public static void loadLanguage(String fileName) {

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;
}
Expand All @@ -60,20 +62,6 @@ public static String translateInsertVariables(String s, Object... args) {
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");
Expand Down

0 comments on commit ebc2196

Please sign in to comment.