From dbb9eadde73c1cfee3556530d1a7e404d4b3847f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9D=8F=E9=BB=91?= Date: Sun, 22 Apr 2018 23:10:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ilummc/tlib/inject/TConfigInjector.java | 2 +- .../tlib/resources/TLocaleInstance.java | 2 +- .../ilummc/tlib/resources/TLocaleLoader.java | 2 +- .../tlib/resources/type/TLocaleTitle.java | 38 +++++++++---------- .../skymc/taboolib/fileutils/ConfigUtils.java | 5 ++- 5 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/ilummc/tlib/inject/TConfigInjector.java b/src/main/java/com/ilummc/tlib/inject/TConfigInjector.java index e2cbd02..f3a6312 100644 --- a/src/main/java/com/ilummc/tlib/inject/TConfigInjector.java +++ b/src/main/java/com/ilummc/tlib/inject/TConfigInjector.java @@ -32,7 +32,7 @@ import com.ilummc.tlib.bean.Property; public class TConfigInjector { - public static void fixUnicode(FileConfiguration configuration) { + public static void fixUnicode(YamlConfiguration configuration) { try { Field field = YamlConfiguration.class.getDeclaredField("yamlOptions"); field.setAccessible(true); diff --git a/src/main/java/com/ilummc/tlib/resources/TLocaleInstance.java b/src/main/java/com/ilummc/tlib/resources/TLocaleInstance.java index 591aa4a..4768d7b 100644 --- a/src/main/java/com/ilummc/tlib/resources/TLocaleInstance.java +++ b/src/main/java/com/ilummc/tlib/resources/TLocaleInstance.java @@ -47,7 +47,7 @@ class TLocaleInstance { return map.getOrDefault(path, ImmutableList.of(TLocaleSendable.getEmpty(path))).get(0).asString(); } - void load(FileConfiguration configuration) { + void load(YamlConfiguration configuration) { configuration.getKeys(false).forEach(s -> { Object object = configuration.get(s); if (object instanceof ConfigurationSection) { diff --git a/src/main/java/com/ilummc/tlib/resources/TLocaleLoader.java b/src/main/java/com/ilummc/tlib/resources/TLocaleLoader.java index 2397547..966334a 100644 --- a/src/main/java/com/ilummc/tlib/resources/TLocaleLoader.java +++ b/src/main/java/com/ilummc/tlib/resources/TLocaleLoader.java @@ -71,7 +71,7 @@ public class TLocaleLoader { saveResource(inputStream, file); } TLib.getTLib().getLogger().info("尝试加载 " + lang + ".yml 作为语言文件"); - FileConfiguration configuration = ConfigUtils.load(plugin, file); + YamlConfiguration configuration = ConfigUtils.loadYaml(plugin, file); TLocaleInstance localeInstance = new TLocaleInstance(); localeInstance.load(configuration); map.put(plugin.getName(), localeInstance); diff --git a/src/main/java/com/ilummc/tlib/resources/type/TLocaleTitle.java b/src/main/java/com/ilummc/tlib/resources/type/TLocaleTitle.java index ee8c808..4f19da4 100644 --- a/src/main/java/com/ilummc/tlib/resources/type/TLocaleTitle.java +++ b/src/main/java/com/ilummc/tlib/resources/type/TLocaleTitle.java @@ -23,31 +23,32 @@ import net.minecraft.server.v1_11_R1.EntityEvoker.e; * @since 2018-04-22 */ -@Immutable @SerializableAs("TITLE") -@Data public class TLocaleTitle implements TLocaleSendable, ConfigurationSerializable { - private String title; - private String subtitle; - private int fadein; - private int fadeout; - private int stay; + private final String title; + private final String subtitle; + private final int fadein; + private final int fadeout; + private final int stay; private boolean usePlaceholder; - private TLocaleTitle(boolean usePlaceholder) { + private TLocaleTitle(String title, String subString, int fadein, int fadeout, int stay, boolean usePlaceholder) { + this.title = title; + this.subtitle = subString; + this.fadein = fadein; + this.fadeout = fadeout; + this.stay = stay; this.usePlaceholder = usePlaceholder; } @Override public void sendTo(CommandSender sender, String... args) { - // TODO Auto-generated method stub } @Override public String asString(String... args) { - // TODO Auto-generated method stub return null; } @@ -66,16 +67,15 @@ public class TLocaleTitle implements TLocaleSendable, ConfigurationSerializable public static TLocaleTitle valueOf(Map map) { TLocaleTitle title; try { - title = new TLocaleTitle((boolean) map.getOrDefault("papi", TLib.getTLib().getConfig().isEnablePlaceholderHookByDefault())); - title.setTitle((String) map.getOrDefault("title", "")); - title.setSubtitle((String) map.getOrDefault("subtitle", "")); - title.setFadein((int) map.getOrDefault("fadein", 10)); - title.setFadeout((int) map.getOrDefault("fadeout", 10)); - title.setStay((int) map.getOrDefault("stay", 10)); + title = new TLocaleTitle( + (String) map.getOrDefault("title", ""), + (String) map.getOrDefault("subtitle", ""), + (int) map.getOrDefault("fadein", 10), + (int) map.getOrDefault("fadeout", 10), + (int) map.getOrDefault("stay", 20), + (boolean) map.getOrDefault("papi", TLib.getTLib().getConfig().isEnablePlaceholderHookByDefault())); } catch (Exception e) { - title = new TLocaleTitle(false); - title.setTitle("§4Load failed!"); - title.setSubtitle("§c" + e.getMessage()); + title = new TLocaleTitle("§4Load failed!", "§c" + e.getMessage(), 10, 20, 10, false); } return title; } diff --git a/src/main/java/me/skymc/taboolib/fileutils/ConfigUtils.java b/src/main/java/me/skymc/taboolib/fileutils/ConfigUtils.java index 225cc30..952c1c0 100644 --- a/src/main/java/me/skymc/taboolib/fileutils/ConfigUtils.java +++ b/src/main/java/me/skymc/taboolib/fileutils/ConfigUtils.java @@ -50,8 +50,11 @@ public class ConfigUtils { * @return */ public static FileConfiguration load(Plugin plugin, File file) { + return loadYaml(plugin, file); + } + + public static YamlConfiguration loadYaml(Plugin plugin, File file) { YamlConfiguration yaml = new YamlConfiguration(); - try { yaml = YamlConfiguration.loadConfiguration(new InputStreamReader(new FileInputStream(file), Charsets.UTF_8)); } catch (Exception e) {