diff --git a/TabooLib.iml b/TabooLib.iml
new file mode 100644
index 0000000..5c1eac3
--- /dev/null
+++ b/TabooLib.iml
@@ -0,0 +1,137 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index c56e5db..a319200 100644
--- a/pom.xml
+++ b/pom.xml
@@ -77,11 +77,6 @@
asm
6.1.1
-
- org.projectlombok
- lombok
- 1.16.20
-
bukkit
bukkit1_12
diff --git a/src/main/java/com/ilummc/tlib/ExampleMain.java b/src/main/java/com/ilummc/tlib/ExampleMain.java
index 3ac4877..3544dbc 100644
--- a/src/main/java/com/ilummc/tlib/ExampleMain.java
+++ b/src/main/java/com/ilummc/tlib/ExampleMain.java
@@ -1,12 +1,11 @@
package com.ilummc.tlib;
+import com.ilummc.tlib.annotations.TConfig;
+import com.ilummc.tlib.bean.Property;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
-import com.ilummc.tlib.annotations.Config;
-import com.ilummc.tlib.bean.Property;
-
-@Config(name = "cfg.yml", charset = "GBK")
+@TConfig(name = "cfg.yml", charset = "GBK")
public class ExampleMain extends JavaPlugin {
private Property update = Property.of(false);
diff --git a/src/main/java/com/ilummc/tlib/TLib.java b/src/main/java/com/ilummc/tlib/TLib.java
index 6686c94..91e5390 100644
--- a/src/main/java/com/ilummc/tlib/TLib.java
+++ b/src/main/java/com/ilummc/tlib/TLib.java
@@ -11,7 +11,6 @@ import com.ilummc.tlib.logger.TLogger;
import com.ilummc.tlib.resources.TLocale;
import com.ilummc.tlib.resources.TLocaleLoader;
import com.ilummc.tlib.util.IO;
-import lombok.Getter;
import me.skymc.taboolib.Main;
import org.bukkit.Bukkit;
import org.bukkit.configuration.InvalidConfigurationException;
@@ -27,44 +26,40 @@ import java.nio.charset.Charset;
@Dependency(type = Dependency.Type.LIBRARY, maven = "org.slf4j:slf4j-api:1.7.25")
public class TLib {
- @Getter
private static TLib tLib;
-
- @Getter
+ private static YamlConfiguration internalLanguage;
private TLogger logger = new TLogger("§8[§3§lTabooLib§8][§r{1}§8] §f{2}", Main.getInst(), TLogger.FINE);
-
- @Getter
private TLibConfig config;
-
- @Getter
private TConfigWatcher configWatcher = new TConfigWatcher();
-
- @Getter
private File libsFolder;
- @Getter
- private YamlConfiguration internalLang;
-
private TLib() {
libsFolder = new File(Main.getInst().getDataFolder(), "/libs");
if (!libsFolder.exists()) {
libsFolder.mkdirs();
}
try {
- String yamlText = new String(IO.readFully(TLib.class.getResourceAsStream("/internalLang.yml")), Charset.forName("utf-8"));
- internalLang = new YamlConfiguration();
- internalLang.loadFromString(yamlText);
+ String yamlText = new String(IO.readFully(TLib.class.getResourceAsStream("/lang/internal.yml")), Charset.forName("utf-8"));
+ internalLanguage = new YamlConfiguration();
+ internalLanguage.loadFromString(yamlText);
} catch (IOException | InvalidConfigurationException ignored) {
}
}
+ public static TLib getTLib() {
+ return tLib;
+ }
+
+ public static YamlConfiguration getInternalLanguage() {
+ return internalLanguage;
+ }
+
public static void init() {
tLib = new TLib();
TLoggerFilter.init();
TLocaleLoader.init();
PlaceholderHook.init();
- TLocaleLoader.load(Main.getInst(), false);
TDependencyInjector.inject(Main.getInst(), tLib);
}
@@ -86,4 +81,20 @@ public class TLib {
TLocale.Logger.fatal("TLIB.INJECTION-FAILED");
}
}
+
+ public TLogger getLogger() {
+ return logger;
+ }
+
+ public TLibConfig getConfig() {
+ return config;
+ }
+
+ public TConfigWatcher getConfigWatcher() {
+ return configWatcher;
+ }
+
+ public File getLibsFolder() {
+ return libsFolder;
+ }
}
diff --git a/src/main/java/com/ilummc/tlib/annotations/Config.java b/src/main/java/com/ilummc/tlib/annotations/Config.java
deleted file mode 100644
index 87b6aa3..0000000
--- a/src/main/java/com/ilummc/tlib/annotations/Config.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package com.ilummc.tlib.annotations;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-import java.lang.reflect.Modifier;
-
-import com.ilummc.tlib.util.Ref;
-
-@Target(ElementType.TYPE)
-@Retention(RetentionPolicy.RUNTIME)
-public @interface Config {
-
- String name() default "config.yml";
-
- boolean fromJar() default false;
-
- boolean saveOnExit() default false;
-
- boolean readOnly() default true;
-
- String charset() default "UTF-8";
-
- boolean listenChanges() default false;
-
- int excludeModifiers() default Modifier.STATIC | Modifier.TRANSIENT | Ref.ACC_SYNTHETIC | Ref.ACC_BRIDGE;
-
-}
diff --git a/src/main/java/com/ilummc/tlib/annotations/Logger.java b/src/main/java/com/ilummc/tlib/annotations/Logger.java
index 2fc75a9..1fd7408 100644
--- a/src/main/java/com/ilummc/tlib/annotations/Logger.java
+++ b/src/main/java/com/ilummc/tlib/annotations/Logger.java
@@ -5,14 +5,12 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-import com.ilummc.tlib.logger.TLogger;
-
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Logger {
String value() default "[{0}|{1}] {1}";
- int level() default TLogger.INFO;
+ int level() default com.ilummc.tlib.logger.TLogger.INFO;
}
diff --git a/src/main/java/com/ilummc/tlib/config/TLibConfig.java b/src/main/java/com/ilummc/tlib/config/TLibConfig.java
index f0c4cfc..cd30b1b 100644
--- a/src/main/java/com/ilummc/tlib/config/TLibConfig.java
+++ b/src/main/java/com/ilummc/tlib/config/TLibConfig.java
@@ -1,16 +1,20 @@
package com.ilummc.tlib.config;
-import com.ilummc.tlib.annotations.Config;
+import com.ilummc.tlib.annotations.TConfig;
/**
* @author sky
* @since 2018-04-22 14:31:11
*/
-@Config(name = "tlib.yml", listenChanges = true, readOnly = false)
+@TConfig(name = "tlib.yml", listenChanges = true)
public class TLibConfig {
private boolean enablePlaceholderHookByDefault = false;
+ public void setEnablePlaceholderHookByDefault(boolean enablePlaceholderHookByDefault) {
+ this.enablePlaceholderHookByDefault = enablePlaceholderHookByDefault;
+ }
+
public boolean isEnablePlaceholderHookByDefault() {
return enablePlaceholderHookByDefault;
}
diff --git a/src/main/java/com/ilummc/tlib/dependency/TDependencyLoader.java b/src/main/java/com/ilummc/tlib/dependency/TDependencyLoader.java
index 3db37f7..701e03a 100644
--- a/src/main/java/com/ilummc/tlib/dependency/TDependencyLoader.java
+++ b/src/main/java/com/ilummc/tlib/dependency/TDependencyLoader.java
@@ -7,6 +7,7 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
+import me.skymc.taboolib.message.MsgUtils;
import org.bukkit.plugin.Plugin;
public class TDependencyLoader {
diff --git a/src/main/java/com/ilummc/tlib/inject/TConfigInjector.java b/src/main/java/com/ilummc/tlib/inject/TConfigInjector.java
index 532e916..09ce66f 100644
--- a/src/main/java/com/ilummc/tlib/inject/TConfigInjector.java
+++ b/src/main/java/com/ilummc/tlib/inject/TConfigInjector.java
@@ -1,7 +1,7 @@
package com.ilummc.tlib.inject;
import com.google.common.io.Files;
-import com.ilummc.tlib.annotations.Config;
+import com.ilummc.tlib.annotations.TConfig;
import com.ilummc.tlib.resources.TLocale;
import me.skymc.taboolib.fileutils.ConfigUtils;
import org.apache.commons.lang3.Validate;
@@ -50,7 +50,7 @@ public class TConfigInjector {
public static Object loadConfig(Plugin plugin, Class> clazz) {
try {
- Config config = clazz.getAnnotation(Config.class);
+ TConfig config = clazz.getAnnotation(TConfig.class);
Validate.notNull(config);
File file = new File(plugin.getDataFolder(), config.name());
if (!file.exists()) if (config.fromJar()) plugin.saveResource(config.name(), true);
@@ -68,7 +68,7 @@ public class TConfigInjector {
public static void reloadConfig(Plugin plugin, Object object) {
try {
- Config config = object.getClass().getAnnotation(Config.class);
+ TConfig config = object.getClass().getAnnotation(TConfig.class);
Validate.notNull(config);
File file = new File(plugin.getDataFolder(), config.name());
Map map = ConfigUtils.confToMap(ConfigUtils.loadYaml(plugin, file));
@@ -83,7 +83,7 @@ public class TConfigInjector {
public static Object unserialize(Plugin plugin, Class> clazz) {
try {
- Config config = clazz.getAnnotation(Config.class);
+ TConfig config = clazz.getAnnotation(TConfig.class);
Validate.notNull(config);
return ConfigUtils.confToObj(
ConfigUtils.mapToConf(
@@ -104,7 +104,7 @@ public class TConfigInjector {
public static Map serialize(Plugin plugin, Object object) {
try {
- Config config = object.getClass().getAnnotation(Config.class);
+ TConfig config = object.getClass().getAnnotation(TConfig.class);
Validate.notNull(config);
return ConfigUtils.objToConf(object).getValues(false);
} catch (NullPointerException e) {
@@ -116,7 +116,7 @@ public class TConfigInjector {
}
public static void saveConfig(Plugin plugin, Object object) throws IOException, NullPointerException {
- Config config = object.getClass().getAnnotation(Config.class);
+ TConfig config = object.getClass().getAnnotation(TConfig.class);
Validate.notNull(config);
Object obj = serialize(plugin, object);
Validate.notNull(obj);
diff --git a/src/main/java/com/ilummc/tlib/inject/TDependencyInjector.java b/src/main/java/com/ilummc/tlib/inject/TDependencyInjector.java
index 4cf3744..ea6fc35 100644
--- a/src/main/java/com/ilummc/tlib/inject/TDependencyInjector.java
+++ b/src/main/java/com/ilummc/tlib/inject/TDependencyInjector.java
@@ -3,10 +3,10 @@ package com.ilummc.tlib.inject;
import com.ilummc.tlib.TLib;
import com.ilummc.tlib.annotations.*;
import com.ilummc.tlib.dependency.TDependency;
-import com.ilummc.tlib.logger.TLogger;
import com.ilummc.tlib.resources.TLocale;
import com.ilummc.tlib.resources.TLocaleLoader;
import com.ilummc.tlib.util.Ref;
+import me.skymc.taboolib.Main;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
@@ -17,15 +17,17 @@ import java.lang.reflect.Field;
public class TDependencyInjector {
public static void inject(Plugin plugin, Object o) {
+ TLocaleLoader.load(plugin, true);
injectDependencies(plugin, o);
injectLogger(plugin, o);
injectConfig(plugin, o);
injectPluginInstance(plugin, o);
- TLocaleLoader.load(plugin, true);
}
static void injectOnEnable(Plugin plugin) {
- inject(plugin, plugin);
+ if (!plugin.equals(Main.getInst())) {
+ inject(plugin, plugin);
+ }
}
static void onDisable(Plugin plugin) {
@@ -41,8 +43,8 @@ public class TDependencyInjector {
private static void ejectConfig(Plugin plugin, Object o) {
for (Field field : Ref.getDeclaredFields(o.getClass())) {
- Config config;
- if ((config = field.getType().getAnnotation(Config.class)) != null && config.saveOnExit()) {
+ TConfig config;
+ if ((config = field.getType().getAnnotation(TConfig.class)) != null && config.saveOnExit()) {
try {
field.setAccessible(true);
TConfigInjector.saveConfig(plugin, field.get(o));
@@ -58,8 +60,8 @@ public class TDependencyInjector {
private static void injectConfig(Plugin plugin, Object o) {
for (Field field : Ref.getDeclaredFields(o.getClass())) {
try {
- Config config;
- if ((config = field.getType().getAnnotation(Config.class)) != null) {
+ TConfig config;
+ if ((config = field.getType().getAnnotation(TConfig.class)) != null) {
field.setAccessible(true);
Object obj = TConfigInjector.loadConfig(plugin, field.getType());
if (obj != null) {
@@ -92,8 +94,8 @@ public class TDependencyInjector {
try {
Logger logger;
if ((logger = field.getAnnotation(Logger.class)) != null) {
- field.getType().asSubclass(TLogger.class);
- TLogger tLogger = new TLogger(logger.value(), plugin, logger.level());
+ field.getType().asSubclass(com.ilummc.tlib.logger.TLogger.class);
+ com.ilummc.tlib.logger.TLogger tLogger = new com.ilummc.tlib.logger.TLogger(logger.value(), plugin, logger.level());
if (!field.isAccessible())
field.setAccessible(true);
field.set(o, tLogger);
diff --git a/src/main/java/com/ilummc/tlib/logger/TLogger.java b/src/main/java/com/ilummc/tlib/logger/TLogger.java
index b2ee777..dd07bd4 100644
--- a/src/main/java/com/ilummc/tlib/logger/TLogger.java
+++ b/src/main/java/com/ilummc/tlib/logger/TLogger.java
@@ -1,8 +1,6 @@
package com.ilummc.tlib.logger;
import com.ilummc.tlib.util.Strings;
-import lombok.Getter;
-import lombok.Setter;
import me.skymc.taboolib.Main;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@@ -12,16 +10,31 @@ public class TLogger {
public static final int VERBOSE = 0, FINEST = 1, FINE = 2, INFO = 3, WARN = 4, ERROR = 5, FATAL = 6;
- @Getter
private static TLogger globalLogger = new TLogger("§8[§3§lTabooLib§8][§r{1}§8] §f{2}", Main.getInst(), TLogger.FINE);
- @Getter
private final String pattern;
- @Getter
private Plugin plugin;
- @Getter
- @Setter
private int level;
+ public static TLogger getGlobalLogger() {
+ return globalLogger;
+ }
+
+ public String getPattern() {
+ return pattern;
+ }
+
+ public Plugin getPlugin() {
+ return plugin;
+ }
+
+ public int getLevel() {
+ return level;
+ }
+
+ public void setLevel(int level) {
+ this.level = level;
+ }
+
public TLogger(String pattern, Plugin plugin, int level) {
this.pattern = pattern;
this.plugin = plugin;
diff --git a/src/main/java/com/ilummc/tlib/resources/TLocale.java b/src/main/java/com/ilummc/tlib/resources/TLocale.java
index a948875..daee4af 100644
--- a/src/main/java/com/ilummc/tlib/resources/TLocale.java
+++ b/src/main/java/com/ilummc/tlib/resources/TLocale.java
@@ -10,6 +10,8 @@ import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;
import java.lang.reflect.Field;
+import java.util.Collections;
+import java.util.List;
public class TLocale {
@@ -17,25 +19,18 @@ public class TLocale {
throw new AssertionError();
}
- private static JavaPlugin getCallerPlugin(Class> callerClass) {
- try {
- Field pluginField = callerClass.getClassLoader().getClass().getDeclaredField("plugin");
- pluginField.setAccessible(true);
- return (JavaPlugin) pluginField.get(callerClass.getClassLoader());
- } catch (Exception ignored) {
- TLib.getTLib().getLogger().error("无效的语言文件发送形式: &4" + callerClass.getName());
- }
- return (JavaPlugin) Main.getInst();
+ static String asString(String path, Class> callerClass, String... args) {
+ return TLocaleLoader.asString(getCallerPlugin(callerClass), path, args);
+ }
+
+ static List asStringList(String path, Class> callerClass, String... args) {
+ return TLocaleLoader.asStringList(getCallerPlugin(callerClass), path, args);
}
private static void sendTo(String path, CommandSender sender, String[] args, Class> callerClass) {
TLocaleLoader.sendTo(getCallerPlugin(callerClass), path, sender, args);
}
- static String asString(String path, Class> callerClass, String... args) {
- return TLocaleLoader.asString(getCallerPlugin(callerClass), path, args);
- }
-
public static void sendToConsole(String path, String... args) {
Ref.getCallerClass(3).ifPresent(clazz -> sendTo(path, Bukkit.getConsoleSender(), args, clazz));
}
@@ -50,18 +45,39 @@ public class TLocale {
public static String asString(String path, String... args) {
try {
- return asString(path, Ref.getCallerClass(3).get(), args);
+ return asString(path, Ref.getCallerClassNotOptional(3), args);
} catch (Exception e) {
- TLib.getTLib().getLogger().error(Strings.replaceWithOrder(TLib.getTLib().getInternalLang().getString("FETCH-LOCALE-ERROR"), path));
- TLib.getTLib().getLogger().error(Strings.replaceWithOrder(TLib.getTLib().getInternalLang().getString("LOCALE-ERROR-REASON"), e.getMessage()));
+ TLib.getTLib().getLogger().error(Strings.replaceWithOrder(TLib.getTLib().getInternalLanguage().getString("FETCH-LOCALE-ERROR"), path));
+ TLib.getTLib().getLogger().error(Strings.replaceWithOrder(TLib.getTLib().getInternalLanguage().getString("LOCALE-ERROR-REASON"), e.getMessage()));
return "§4<" + path + "§4>";
}
}
+ public static List asStringList(String path, String... args) {
+ try {
+ return asStringList(path, Ref.getCallerClassNotOptional(3), args);
+ } catch (Exception e) {
+ TLib.getTLib().getLogger().error(Strings.replaceWithOrder(TLib.getTLib().getInternalLanguage().getString("FETCH-LOCALE-ERROR"), path));
+ TLib.getTLib().getLogger().error(Strings.replaceWithOrder(TLib.getTLib().getInternalLanguage().getString("LOCALE-ERROR-REASON"), e.getMessage()));
+ return Collections.singletonList("§4<" + path + "§4>");
+ }
+ }
+
public static void reload() {
Ref.getCallerClass(3).ifPresent(clazz -> TLocaleLoader.load(getCallerPlugin(clazz), false));
}
+ private static JavaPlugin getCallerPlugin(Class> callerClass) {
+ try {
+ Field pluginField = callerClass.getClassLoader().getClass().getDeclaredField("plugin");
+ pluginField.setAccessible(true);
+ return (JavaPlugin) pluginField.get(callerClass.getClassLoader());
+ } catch (Exception ignored) {
+ TLib.getTLib().getLogger().error("无效的语言文件发送形式: &4" + callerClass.getName());
+ }
+ return (JavaPlugin) Main.getInst();
+ }
+
public static final class Logger extends TLocale {
public static void info(String path, String... args) {
diff --git a/src/main/java/com/ilummc/tlib/resources/TLocaleInstance.java b/src/main/java/com/ilummc/tlib/resources/TLocaleInstance.java
index e70fae0..0258710 100644
--- a/src/main/java/com/ilummc/tlib/resources/TLocaleInstance.java
+++ b/src/main/java/com/ilummc/tlib/resources/TLocaleInstance.java
@@ -2,6 +2,7 @@ package com.ilummc.tlib.resources;
import com.google.common.collect.ImmutableList;
import com.ilummc.tlib.TLib;
+import com.ilummc.tlib.logger.TLogger;
import com.ilummc.tlib.resources.type.TLocaleText;
import com.ilummc.tlib.util.Strings;
import org.bukkit.Bukkit;
@@ -22,13 +23,36 @@ import java.util.stream.Collectors;
@SuppressWarnings("rawtypes")
class TLocaleInstance {
+ private final Map> map = new HashMap<>();
private final Plugin plugin;
+ private int updateNodes;
TLocaleInstance(Plugin plugin) {
this.plugin = plugin;
}
- void sendTo(String path, CommandSender sender, String... args) {
+ @Override
+ public String toString() {
+ return map.toString();
+ }
+
+ public int size() {
+ return map.size();
+ }
+
+ public Map> getMap() {
+ return map;
+ }
+
+ public Plugin getPlugin() {
+ return plugin;
+ }
+
+ public int getUpdateNodes() {
+ return updateNodes;
+ }
+
+ public void sendTo(String path, CommandSender sender, String... args) {
try {
map.getOrDefault(path, ImmutableList.of(TLocaleSendable.getEmpty(path))).forEach(sendable -> {
if (Bukkit.isPrimaryThread()) {
@@ -38,39 +62,39 @@ class TLocaleInstance {
}
});
} catch (Exception | Error e) {
- TLib.getTLib().getLogger().error(Strings.replaceWithOrder(TLib.getTLib().getInternalLang().getString("SEND-LOCALE-ERROR"), path));
- TLib.getTLib().getLogger().error(Strings.replaceWithOrder(TLib.getTLib().getInternalLang().getString("LOCALE-ERROR-REASON"), e.toString()));
+ TLib.getTLib().getLogger().error(Strings.replaceWithOrder(TLib.getTLib().getInternalLanguage().getString("SEND-LOCALE-ERROR"), path));
+ TLib.getTLib().getLogger().error(Strings.replaceWithOrder(TLib.getTLib().getInternalLanguage().getString("LOCALE-ERROR-REASON"), e.toString()));
e.printStackTrace();
}
}
- String asString(String path, String... args) {
+ public String asString(String path, String... args) {
return map.getOrDefault(path, ImmutableList.of(TLocaleSendable.getEmpty(path))).get(0).asString(args);
}
- void load(YamlConfiguration configuration) {
+ public List asStringList(String path, String... args) {
+ return map.getOrDefault(path, ImmutableList.of(TLocaleSendable.getEmpty(path))).get(0).asStringList(args);
+ }
+
+ public void load(YamlConfiguration configuration) {
+ updateNodes = 0;
configuration.getKeys(true).forEach(s -> {
+ boolean isCover = false;
Object object = configuration.get(s);
if (object instanceof TLocaleSendable) {
- map.put(s, Collections.singletonList((TLocaleSendable) object));
+ isCover = map.put(s, Collections.singletonList((TLocaleSendable) object)) != null;
} else if (object instanceof List && !((List) object).isEmpty()) {
- map.put(s, ((List>) object).stream().map(TO_SENDABLE).collect(Collectors.toList()));
+ isCover = map.put(s, ((List>) object).stream().map(TO_SENDABLE).collect(Collectors.toList())) != null;
} else if (!(object instanceof ConfigurationSection)) {
String str = String.valueOf(object);
- map.put(s, Collections.singletonList(str.length() == 0 ? TLocaleSendable.getEmpty() : TLocaleText.of(str)));
+ isCover = map.put(s, Collections.singletonList(str.length() == 0 ? TLocaleSendable.getEmpty() : TLocaleText.of(str))) != null;
+ }
+ if (isCover) {
+ updateNodes++;
}
});
}
- int size() {
- return map.size();
- }
-
- @Override
- public String toString() {
- return map.toString();
- }
-
private static final Function