Current progress
This commit is contained in:
@@ -51,8 +51,8 @@ public class ReflectionFlagWatchers {
|
||||
}
|
||||
|
||||
private ParamInfo(String name, String description) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.name = TranslateType.METHOD_PARAM.get(name, null);
|
||||
this.description = TranslateType.METHOD_PARAM.get(description, null);
|
||||
}
|
||||
|
||||
public ParamInfo(String className, String name, String description) throws ClassNotFoundException {
|
||||
@@ -169,6 +169,7 @@ public class ReflectionFlagWatchers {
|
||||
|
||||
potionEnums.add(toReadable(effectType.getName()));
|
||||
}
|
||||
|
||||
String[] materials = new String[Material.values().length];
|
||||
|
||||
for (int i = 0; i < Material.values().length; i++) {
|
||||
|
34
src/me/libraryaddict/disguise/utilities/TranslateFiller.java
Normal file
34
src/me/libraryaddict/disguise/utilities/TranslateFiller.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package me.libraryaddict.disguise.utilities;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 10/06/2017.
|
||||
*/
|
||||
public class TranslateFiller {
|
||||
public static void fillConfigs() {
|
||||
// Fill the configs
|
||||
|
||||
for (ReflectionFlagWatchers.ParamInfo info : ReflectionFlagWatchers.getParamInfos()) {
|
||||
if (!info.isEnums())
|
||||
continue;
|
||||
|
||||
for (String e : info.getEnums("")) {
|
||||
TranslateType.METHOD_PARAM.get(e, "Name for the param for " + info.getName());
|
||||
}
|
||||
}
|
||||
|
||||
for (DisguiseType type : DisguiseType.values()) {
|
||||
type.toReadable();
|
||||
|
||||
for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(type.getWatcherClass())) {
|
||||
TranslateType.METHOD.get(method.getName(),
|
||||
"Found in " + method.getDeclaringClass().getSimpleName().replace("Watcher",
|
||||
"") + " and accepts as a parameter " + TranslateType.METHOD_PARAM.get(
|
||||
method.getParameterTypes()[0].getSimpleName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
94
src/me/libraryaddict/disguise/utilities/TranslateType.java
Normal file
94
src/me/libraryaddict/disguise/utilities/TranslateType.java
Normal file
@@ -0,0 +1,94 @@
|
||||
package me.libraryaddict.disguise.utilities;
|
||||
|
||||
import org.apache.commons.lang3.StringEscapeUtils;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 10/06/2017.
|
||||
*/
|
||||
public enum TranslateType {
|
||||
DISGUISE("disguise_names"), MESSAGE("messages"), METHOD_PARAM("option_names"), METHOD("disguise_options");
|
||||
private File file;
|
||||
private YamlConfiguration config;
|
||||
|
||||
TranslateType(String fileName) {
|
||||
file = new File("translate", fileName + ".yml");
|
||||
reload();
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
if (!file.exists())
|
||||
file.getParentFile().mkdirs();
|
||||
|
||||
try {
|
||||
file.createNewFile();
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
config = YamlConfiguration.loadConfiguration(file);
|
||||
}
|
||||
|
||||
private YamlConfiguration getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
private File getFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
public void save(String message, String comment) {
|
||||
message = StringEscapeUtils.escapeJson(message);
|
||||
|
||||
if (getConfig().contains(message))
|
||||
return;
|
||||
|
||||
try {
|
||||
PrintWriter writer = new PrintWriter(getFile());
|
||||
writer.write((comment != null ? "# " + comment + "\n" : "") + message + ": " + message + "\n");
|
||||
|
||||
writer.close();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public String reverseGet(String translated) {
|
||||
translated = StringEscapeUtils.unescapeJson(translated).toLowerCase();
|
||||
|
||||
for (Map.Entry<String, Object> entry : getConfig().getValues(false).entrySet()) {
|
||||
if (!Objects.equals(entry.getValue().toString().toLowerCase(), translated))
|
||||
continue;
|
||||
|
||||
return entry.getKey();
|
||||
}
|
||||
|
||||
return translated;
|
||||
}
|
||||
|
||||
public String get(String message) {
|
||||
if (this != TranslateType.MESSAGE)
|
||||
throw new IllegalArgumentException("Can't set no comment for '" + message + "'");
|
||||
|
||||
return get(message, null);
|
||||
}
|
||||
|
||||
public String get(String message, String comment) {
|
||||
String msg = getConfig().getString(StringEscapeUtils.escapeJson(message));
|
||||
|
||||
if (msg != null)
|
||||
return msg;
|
||||
|
||||
save(message, comment);
|
||||
|
||||
return message;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user