把部分硬编码语言文件抽取到新的语言系统
This commit is contained in:
@@ -1,11 +1,5 @@
|
||||
package com.ilummc.tlib;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import com.ilummc.tlib.annotations.Dependency;
|
||||
import com.ilummc.tlib.compat.PlaceholderHook;
|
||||
import com.ilummc.tlib.config.TLibConfig;
|
||||
@@ -14,21 +8,29 @@ import com.ilummc.tlib.inject.TConfigWatcher;
|
||||
import com.ilummc.tlib.inject.TDependencyInjector;
|
||||
import com.ilummc.tlib.inject.TPluginManager;
|
||||
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;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
@Dependency(type = Dependency.Type.LIBRARY, maven = "org.ow2.asm:asm:6.1.1")
|
||||
@Dependency(type = Dependency.Type.LIBRARY, maven = "com.zaxxer:HikariCP:3.1.0")
|
||||
@Dependency(type = Dependency.Type.LIBRARY, maven = "org.slf4j:slf4j-api:1.7.25")
|
||||
public class TLib {
|
||||
|
||||
@Getter
|
||||
@Getter
|
||||
private static TLib tLib;
|
||||
|
||||
@Getter
|
||||
@Getter
|
||||
private TLogger logger = new TLogger("§8[§3§lTabooLib§8][§r{1}§8] §f{2}", Main.getInst(), TLogger.FINE);
|
||||
|
||||
@Getter
|
||||
@@ -36,7 +38,7 @@ public class TLib {
|
||||
|
||||
@Getter
|
||||
private TConfigWatcher configWatcher = new TConfigWatcher();
|
||||
|
||||
|
||||
@Getter
|
||||
private File libsFolder;
|
||||
|
||||
@@ -44,33 +46,33 @@ public class TLib {
|
||||
private YamlConfiguration internalLang;
|
||||
|
||||
private TLib() {
|
||||
libsFolder = new File(Main.getInst().getDataFolder(), "/libs");
|
||||
if (!libsFolder.exists()) {
|
||||
libsFolder.mkdirs();
|
||||
}
|
||||
internalLang = YamlConfiguration.loadConfiguration(new InputStreamReader(TLib.class.getResourceAsStream("/internalLang.yml")));
|
||||
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);
|
||||
} catch (IOException | InvalidConfigurationException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
tLib = new TLib();
|
||||
|
||||
|
||||
TLoggerFilter.init();
|
||||
TLocaleLoader.init();
|
||||
PlaceholderHook.init();
|
||||
TLocaleLoader.load(Main.getInst(), false);
|
||||
TDependencyInjector.inject(Main.getInst(), tLib);
|
||||
|
||||
if (Bukkit.getPluginManager() instanceof TPluginManager) {
|
||||
tLib.getLogger().info("注入成功");
|
||||
} else {
|
||||
tLib.getLogger().fatal("注入失败");
|
||||
}
|
||||
}
|
||||
|
||||
public static void unload() {
|
||||
tLib.getConfigWatcher().unregisterAll();
|
||||
TDependencyInjector.eject(Main.getInst(), tLib);
|
||||
}
|
||||
|
||||
|
||||
public static void injectPluginManager() {
|
||||
try {
|
||||
Field field = Bukkit.getServer().getClass().getDeclaredField("pluginManager");
|
||||
@@ -78,5 +80,10 @@ public class TLib {
|
||||
field.set(Bukkit.getServer(), new TPluginManager());
|
||||
} catch (NoSuchFieldException | IllegalAccessException ignored) {
|
||||
}
|
||||
if (Bukkit.getPluginManager() instanceof TPluginManager) {
|
||||
TLocale.Logger.info("TLIB.INJECTION-SUCCESS");
|
||||
} else {
|
||||
TLocale.Logger.fatal("TLIB.INJECTION-FAILED");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user