Improve translations, fix a problem with the files

This commit is contained in:
libraryaddict 2018-07-12 06:05:36 +12:00
parent 9d505d0e30
commit 4aa724fd6f
7 changed files with 110 additions and 74 deletions

View File

@ -104,7 +104,7 @@ public class DisguiseConfig {
public static void setUseTranslations(boolean setUseTranslations) {
useTranslations = setUseTranslations;
TranslateType.reloadTranslations();
TranslateType.refreshTranslations();
}
public static boolean isSaveEntityDisguises() {

View File

@ -46,12 +46,12 @@ public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompl
if (help != null) {
if (help.isEnums()) {
sender.sendMessage(ChatColor.RED + help.getName() + ": " + ChatColor.GREEN + StringUtils
.join(help.getEnums(""), ChatColor.RED + ", " + ChatColor.GREEN));
sender.sendMessage(LibsMsg.DHELP_HELP4.get(help.getName(),
StringUtils.join(help.getEnums(""), LibsMsg.DHELP_HELP4_SEPERATOR.get())));
} else {
sender.sendMessage(
ChatColor.RED + help.getName() + ": " + ChatColor.GREEN + help.getDescription());
sender.sendMessage(LibsMsg.DHELP_HELP5.get(help.getName(), help.getDescription()));
}
return true;
}
@ -107,14 +107,14 @@ public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompl
if (declaring == LivingWatcher.class) {
methodColor = ChatColor.AQUA;
} else if (!(FlagWatcher.class
.isAssignableFrom(declaring)) || declaring == FlagWatcher.class) {
} else if (!(FlagWatcher.class.isAssignableFrom(declaring)) ||
declaring == FlagWatcher.class) {
methodColor = ChatColor.GRAY;
}
String str = TranslateType.DISGUISE_OPTIONS
.get(method.getName()) + ChatColor.DARK_RED + "(" + ChatColor.GREEN + info
.getName() + ChatColor.DARK_RED + ")";
String str =
TranslateType.DISGUISE_OPTIONS.get(method.getName()) + ChatColor.DARK_RED + "(" +
ChatColor.GREEN + info.getName() + ChatColor.DARK_RED + ")";
map.put(str, methodColor);
methods.add(str);

View File

@ -8,14 +8,11 @@ import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction;
import com.comphenix.protocol.wrappers.PlayerInfoData;
import com.comphenix.protocol.wrappers.WrappedChatComponent;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.LibsProfileLookup;
import me.libraryaddict.disguise.utilities.ReflectionManager;
import me.libraryaddict.disguise.utilities.json.SerializerGameProfile;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
@ -84,6 +81,10 @@ public class PlayerDisguise extends TargetedDisguise {
createDisguise();
}
public UUID getUUID() {
return uuid;
}
@Override
public PlayerDisguise addPlayer(Player player) {
return (PlayerDisguise) super.addPlayer(player);

View File

@ -410,7 +410,6 @@ public class DisguiseUtilities {
// This here is a paradox.
// If fed a name. I can do this.
// But the rest of the time.. Its going to conflict.
// The below is debug output. Most people wouldn't care for it.
disguiseItel.remove();
d.removeDisguise();

View File

@ -1,5 +1,6 @@
package me.libraryaddict.disguise.utilities;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.ChatColor;
/**
@ -10,24 +11,28 @@ public enum LibsMsg {
CAN_USE_DISGS(ChatColor.DARK_GREEN + "You can use the disguises: %s"),
CANNOT_FIND_PLAYER(ChatColor.RED + "Cannot find the player/uuid '%s'"),
CLICK_TIMER(ChatColor.RED + "Right click a entity in the next %s seconds to grab the disguise reference!"),
CLONE_HELP1(
ChatColor.DARK_GREEN + "Right click a entity to get a disguise reference you can pass to other disguise commands!"),
CLONE_HELP2(
ChatColor.DARK_GREEN + "Security note: Any references you create will be available to all players able to use disguise references."),
CLONE_HELP3(
ChatColor.DARK_GREEN + "/disguiseclone IgnoreEquipment" + ChatColor.DARK_GREEN + "(" + ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")"),
CLONE_HELP1(ChatColor.DARK_GREEN +
"Right click a entity to get a disguise reference you can pass to other disguise commands!"),
CLONE_HELP2(ChatColor.DARK_GREEN +
"Security note: Any references you create will be available to all players able to use disguise " +
"references."),
CLONE_HELP3(ChatColor.DARK_GREEN + "/disguiseclone IgnoreEquipment" + ChatColor.DARK_GREEN + "(" + ChatColor.GREEN +
"Optional" + ChatColor.DARK_GREEN + ")"),
D_HELP1(ChatColor.DARK_GREEN + "Disguise another player!"),
D_HELP3(ChatColor.DARK_GREEN + "/disguiseplayer <PlayerName> player <Name>"),
D_HELP4(ChatColor.DARK_GREEN + "/disguiseplayer <PlayerName> <DisguiseType> <Baby>"),
D_HELP5(ChatColor.DARK_GREEN + "/disguiseplayer <PlayerName> <Dropped_Item/Falling_Block> <Id> <Durability>"),
D_PARSE_NOPERM(ChatColor.RED + "You do not have permission to use the option %s"),
DHELP_CANTFIND(ChatColor.RED + "Cannot find the disguise %s"),
DHELP_HELP1(
ChatColor.RED + "/disguisehelp <DisguiseType> " + ChatColor.GREEN + "- View the options you can set on a disguise. Add 'show' to reveal the options you don't have permission to use"),
DHELP_HELP2(
ChatColor.RED + "/disguisehelp <DisguiseOption> " + ChatColor.GREEN + "- View information about the " +
"disguise options such as 'RabbitType'"),
DHELP_HELP1(ChatColor.RED + "/disguisehelp <DisguiseType> " + ChatColor.GREEN +
"- View the options you can set on a disguise. Add 'show' to reveal the options you don't have permission" +
" to use"),
DHELP_HELP2(ChatColor.RED + "/disguisehelp <DisguiseOption> " + ChatColor.GREEN + "- View information about the " +
"disguise options such as 'RabbitType'"),
DHELP_HELP3(ChatColor.RED + "/disguisehelp %s" + ChatColor.GREEN + " - %s"),
DHELP_HELP4(ChatColor.RED + "%s: " + ChatColor.GREEN + "%s"),
DHELP_HELP4_SEPERATOR(ChatColor.RED + ", " + ChatColor.GREEN),
DHELP_HELP5(ChatColor.RED + "%s: " + ChatColor.GREEN + "%s"),
DHELP_OPTIONS("%s options: %s"),
DISABLED_LIVING_TO_MISC(
ChatColor.RED + "Can't disguise a living entity as a misc disguise. This has been disabled in the config!"),
@ -64,11 +69,11 @@ public enum LibsMsg {
DCLONE_SNEAKSPRINT("doSneakSprint"),
DCLONE_SNEAK("doSneak"),
DCLONE_SPRINT("doSprint"),
DMODRADIUS_HELP2(
(ChatColor.DARK_GREEN + "/disguisemodifyradius <DisguiseType" + ChatColor.DARK_GREEN + "(" + ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")> <Radius> <Disguise Options>")
.replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")),
DMODRADIUS_HELP3(
ChatColor.DARK_GREEN + "See the DisguiseType's usable by " + ChatColor.GREEN + "/disguisemodifyradius DisguiseType"),
DMODRADIUS_HELP2((ChatColor.DARK_GREEN + "/disguisemodifyradius <DisguiseType" + ChatColor.DARK_GREEN + "(" +
ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")> <Radius> <Disguise Options>")
.replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")),
DMODRADIUS_HELP3(ChatColor.DARK_GREEN + "See the DisguiseType's usable by " + ChatColor.GREEN +
"/disguisemodifyradius DisguiseType"),
DMODRADIUS_NEEDOPTIONS(ChatColor.RED + "You need to supply the disguise options as well as the radius"),
DMODRADIUS_NEEDOPTIONS_ENTITY(
ChatColor.RED + "You need to supply the disguise options as well as the radius and EntityType"),
@ -79,24 +84,27 @@ public enum LibsMsg {
DPLAYER_SUPPLY(ChatColor.RED + "You need to supply a disguise as well as the player/uuid"),
DRADIUS_ENTITIES(ChatColor.DARK_GREEN + "EntityTypes usable are: %s"),
DRADIUS_HELP1(ChatColor.DARK_GREEN + "Disguise all entities in a radius! Caps at %s blocks!"),
DRADIUS_HELP3(
(ChatColor.DARK_GREEN + "/disguiseradius <EntityType" + ChatColor.DARK_GREEN + "(" + ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")> <Radius> player <Name>")
.replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")),
DRADIUS_HELP4(
(ChatColor.DARK_GREEN + "/disguiseradius <EntityType" + ChatColor.DARK_GREEN + "(" + ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")> <Radius> <DisguiseType> <Baby" + ChatColor.DARK_GREEN + "(" + ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")>")
.replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")),
DRADIUS_HELP5(
(ChatColor.DARK_GREEN + "/disguiseradius <EntityType" + ChatColor.DARK_GREEN + "(" + ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")> <Radius> <Dropped_Item/Falling_Block> <Id> <Durability" + ChatColor.DARK_GREEN + "(" + ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")>")
.replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")),
DRADIUS_HELP3((ChatColor.DARK_GREEN + "/disguiseradius <EntityType" + ChatColor.DARK_GREEN + "(" + ChatColor.GREEN +
"Optional" + ChatColor.DARK_GREEN + ")> <Radius> player <Name>").replace("<", "<" + ChatColor.GREEN)
.replace(">", ChatColor.DARK_GREEN + ">")),
DRADIUS_HELP4((ChatColor.DARK_GREEN + "/disguiseradius <EntityType" + ChatColor.DARK_GREEN + "(" + ChatColor.GREEN +
"Optional" + ChatColor.DARK_GREEN + ")> <Radius> <DisguiseType> <Baby" + ChatColor.DARK_GREEN + "(" +
ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")>").replace("<", "<" + ChatColor.GREEN)
.replace(">", ChatColor.DARK_GREEN + ">")),
DRADIUS_HELP5((ChatColor.DARK_GREEN + "/disguiseradius <EntityType" + ChatColor.DARK_GREEN + "(" + ChatColor.GREEN +
"Optional" + ChatColor.DARK_GREEN + ")> <Radius> <Dropped_Item/Falling_Block> <Id> <Durability" +
ChatColor.DARK_GREEN + "(" + ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")>")
.replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")),
DRADIUS_HELP6(
ChatColor.DARK_GREEN + "See the EntityType's usable by " + ChatColor.GREEN + "/disguiseradius EntityTypes"),
DRADIUS_MISCDISG(
ChatColor.RED + "Failed to disguise %s entities because the option to disguise a living entity as a non-living has been disabled in the config"),
DRADIUS_MISCDISG(ChatColor.RED +
"Failed to disguise %s entities because the option to disguise a living entity as a non-living has been " +
"disabled in the config"),
DRADIUS_NEEDOPTIONS(ChatColor.RED + "You need to supply a disguise as well as the radius"),
DRADIUS_NEEDOPTIONS_ENTITY(ChatColor.RED + "You need to supply a disguise as well as the radius and EntityType"),
FAILED_DISGIUSE(ChatColor.RED + "Failed to disguise as a %s"),
INVALID_CLONE(
ChatColor.DARK_RED + "Unknown option '%s' - Valid options are 'IgnoreEquipment' 'DoSneakSprint' " + "'DoSneak' 'DoSprint'"),
INVALID_CLONE(ChatColor.DARK_RED + "Unknown option '%s' - Valid options are 'IgnoreEquipment' 'DoSneakSprint' " +
"'DoSneak' 'DoSprint'"),
LIBS_RELOAD_WRONG(ChatColor.RED + "[LibsDisguises] Did you mean 'reload'?"),
LIMITED_RADIUS(ChatColor.RED + "Limited radius to %s! Don't want to make too much lag right?"),
LISTEN_ENTITY_ENTITY_DISG_ENTITY(ChatColor.RED + "Disguised %s as a %s!"),
@ -117,8 +125,8 @@ public enum LibsMsg {
NO_CONSOLE(ChatColor.RED + "You may not use this command from the console!"),
NO_PERM(ChatColor.RED + "You are forbidden to use this command."),
NO_PERM_DISGUISE(ChatColor.RED + "You do not have permission for that disguise!"),
NO_PERMS_USE_OPTIONS(
ChatColor.RED + "Ignored %s options you do not have permission to use. Add 'show' to view unusable options."),
NO_PERMS_USE_OPTIONS(ChatColor.RED +
"Ignored %s options you do not have permission to use. Add 'show' to view unusable options."),
NOT_DISGUISED(ChatColor.RED + "You are not disguised!"),
NOT_NUMBER(ChatColor.RED + "Error! %s is not a number"),
PARSE_CANT_DISG_UNKNOWN(ChatColor.RED + "Error! You cannot disguise as " + ChatColor.GREEN + "Unknown!"),
@ -126,7 +134,8 @@ public enum LibsMsg {
PARSE_DISG_NO_EXIST(
ChatColor.RED + "Error! The disguise " + ChatColor.GREEN + "%s" + ChatColor.RED + " doesn't exist!"),
PARSE_EXPECTED_RECEIVED(
ChatColor.RED + "Expected " + ChatColor.GREEN + "%s" + ChatColor.RED + ", received " + ChatColor.GREEN + "%s" + ChatColor.RED + " instead for " + ChatColor.GREEN + "%s"),
ChatColor.RED + "Expected " + ChatColor.GREEN + "%s" + ChatColor.RED + ", received " + ChatColor.GREEN +
"%s" + ChatColor.RED + " instead for " + ChatColor.GREEN + "%s"),
PARSE_NO_ARGS("No arguments defined"),
PARSE_NO_OPTION_VALUE(ChatColor.RED + "No value was given for the option %s"),
PARSE_NO_PERM_NAME(ChatColor.RED + "Error! You don't have permission to use that name!"),
@ -138,8 +147,9 @@ public enum LibsMsg {
PARSE_SUPPLY_PLAYER(ChatColor.RED + "Error! You need to give a player name!"),
PARSE_TOO_MANY_ARGS(ChatColor.RED + "Error! %s doesn't know what to do with %s!"),
PARSE_USE_SECOND_NUM(ChatColor.RED + "Error! Only the disguises %s and %s uses a second number!"),
REF_TOO_MANY(
ChatColor.RED + "Failed to store the reference, too many cloned disguises. Please raise the maximum cloned disguises, or lower the time they last"),
REF_TOO_MANY(ChatColor.RED +
"Failed to store the reference, too many cloned disguises. Please raise the maximum cloned disguises, or " +
"lower the time they last"),
RELOADED_CONFIG(ChatColor.GREEN + "[LibsDisguises] Reloaded config."),
UND_ENTITY(ChatColor.RED + "Right click a disguised entity to undisguise them!"),
UNDISG(ChatColor.RED + "You are no longer disguised"),
@ -147,8 +157,9 @@ public enum LibsMsg {
UNDISG_PLAYER_FAIL(ChatColor.RED + "%s not disguised!"),
UNDISG_PLAYER_HELP(ChatColor.RED + "/undisguiseplayer <Name>"),
UNDISRADIUS(ChatColor.RED + "Successfully undisguised %s entities!"),
UPDATE_READY(
ChatColor.RED + "[LibsDisguises] " + ChatColor.DARK_RED + "There is a update ready to be downloaded! You are using " + ChatColor.RED + "v%s" + ChatColor.DARK_RED + ", the new version is " + ChatColor.RED + "%s" + ChatColor.DARK_RED + "!"),
UPDATE_READY(ChatColor.RED + "[LibsDisguises] " + ChatColor.DARK_RED +
"There is a update ready to be downloaded! You are using " + ChatColor.RED + "v%s" + ChatColor.DARK_RED +
", the new version is " + ChatColor.RED + "%s" + ChatColor.DARK_RED + "!"),
VIEW_SELF_ON(ChatColor.GREEN + "Toggled viewing own disguise on!"),
VIEW_SELF_OFF(ChatColor.GREEN + "Toggled viewing own disguise off!");
@ -163,8 +174,14 @@ public enum LibsMsg {
}
public String get(Object... strings) {
if (strings.length == 0)
if (StringUtils.countMatches(getRaw(), "%s") != strings.length) {
System.out.println("[LibsDisguises] Mismatch in messages, incorrect parameters supplied for " + name() +
". Please inform plugin author.");
}
if (strings.length == 0) {
return TranslateType.MESSAGES.get(getRaw());
}
return String.format(TranslateType.MESSAGES.get(getRaw()), (Object[]) strings);
}

View File

@ -52,8 +52,8 @@ public class TranslateFiller {
className = "Illager";
TranslateType.DISGUISE_OPTIONS.save(method.getName(),
"Found in the disguise options for " + className + " and uses " + (para.isArray() ?
"multiple" + " " : "a ") + para.getSimpleName().replace("[]", "s"));
"Found in the disguise options for " + className + " and uses " +
(para.isArray() ? "multiple" + " " : "a ") + para.getSimpleName().replace("[]", "s"));
}
}
@ -72,11 +72,11 @@ public class TranslateFiller {
.save("DisgiseType", "Used for the disgiuse modify radius command to list all " + "disguisetypes");
for (LibsMsg msg : LibsMsg.values()) {
TranslateType.MESSAGES.save(msg.getRaw());
TranslateType.MESSAGES.save(msg.getRaw(), "Reference: " + msg.name());
}
for (TranslateType type : TranslateType.values()) {
type.removeDuplicates();
type.saveTranslations();
}
}
}

View File

@ -8,8 +8,8 @@ import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
@ -23,16 +23,16 @@ public enum TranslateType {
DISGUISE_OPTIONS_PARAMETERS("disguise_option_parameters");
private File file;
private HashMap<String, String> translated = new HashMap<>();
private LinkedHashMap<String, String> translated = new LinkedHashMap<>();
private FileWriter writer;
TranslateType(String fileName) {
file = new File("plugins/LibsDisguises/Translations", fileName + ".yml");
}
public static void reloadTranslations() {
public static void refreshTranslations() {
for (TranslateType type : values()) {
type.reload();
type.loadTranslations();
}
if (!LibsPremium.isPremium() && DisguiseConfig.isUseTranslations()) {
@ -42,7 +42,10 @@ public enum TranslateType {
TranslateFiller.fillConfigs();
}
protected void removeDuplicates() {
protected void saveTranslations() {
// First remove translations which are not different from each other. We don't need to store messages that
// were not translated.
Iterator<Map.Entry<String, String>> itel = translated.entrySet().iterator();
while (itel.hasNext()) {
@ -54,6 +57,8 @@ public enum TranslateType {
itel.remove();
}
// Close the writer
try {
if (writer != null) {
writer.close();
@ -65,37 +70,51 @@ public enum TranslateType {
}
}
public void wipeTranslations() {
private void loadTranslations() {
translated.clear();
}
private void reload() {
wipeTranslations();
if (LibsPremium.isPremium() && DisguiseConfig.isUseTranslations()) {
System.out.println("[LibsDisguises] Loading translations: " + name());
}
if (!getFile().exists())
if (!getFile().exists()) {
System.out.println("[LibsDisguises] Translations for " + name() + " missing! Skipping...");
return;
}
YamlConfiguration config = new YamlConfiguration();
config.options().pathSeparator(Character.toChars(0)[0]);
try {
config.load(getFile());
int dupes = 0;
for (String key : config.getKeys(false)) {
String value = config.getString(key);
if (Objects.equals(key, value))
continue;
if (value == null)
if (value == null) {
System.err.println("Translation for " + name() + " has a null value for the key '" + key + "'");
else {
translated.put(ChatColor.translateAlternateColorCodes('&', key),
ChatColor.translateAlternateColorCodes('&', value));
} else {
String newKey = ChatColor.translateAlternateColorCodes('&', key);
if (translated.containsKey(newKey)) {
if (dupes++ < 5) {
System.out.println(
"[LibsDisguises] Alert! Duplicate translation entry for " + key + " in " + name() +
" translations!");
continue;
} else {
System.out.println(
"[LibsDisguises] Too many duplicated keys! It's likely that this file was mildly " +
"corrupted by a previous bug!");
System.out.println(
"[LibsDisguises] Delete the file, or you can remove every line after the first " +
"duplicate message!");
break;
}
}
translated.put(newKey, ChatColor.translateAlternateColorCodes('&', value));
}
}
}
@ -126,7 +145,7 @@ public enum TranslateType {
translated.put(message, message);
message = StringEscapeUtils.escapeJava(message.replaceAll(ChatColor.COLOR_CHAR + "", "&"));
message = StringEscapeUtils.escapeJava(message.replace(ChatColor.COLOR_CHAR + "", "&"));
try {
boolean exists = getFile().exists();