This commit is contained in:
坏黑 2018-04-22 23:10:05 +08:00
parent b49a779859
commit dbb9eadde7
5 changed files with 26 additions and 23 deletions

View File

@ -32,7 +32,7 @@ import com.ilummc.tlib.bean.Property;
public class TConfigInjector { public class TConfigInjector {
public static void fixUnicode(FileConfiguration configuration) { public static void fixUnicode(YamlConfiguration configuration) {
try { try {
Field field = YamlConfiguration.class.getDeclaredField("yamlOptions"); Field field = YamlConfiguration.class.getDeclaredField("yamlOptions");
field.setAccessible(true); field.setAccessible(true);

View File

@ -47,7 +47,7 @@ class TLocaleInstance {
return map.getOrDefault(path, ImmutableList.of(TLocaleSendable.getEmpty(path))).get(0).asString(); 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 -> { configuration.getKeys(false).forEach(s -> {
Object object = configuration.get(s); Object object = configuration.get(s);
if (object instanceof ConfigurationSection) { if (object instanceof ConfigurationSection) {

View File

@ -71,7 +71,7 @@ public class TLocaleLoader {
saveResource(inputStream, file); saveResource(inputStream, file);
} }
TLib.getTLib().getLogger().info("尝试加载 " + lang + ".yml 作为语言文件"); TLib.getTLib().getLogger().info("尝试加载 " + lang + ".yml 作为语言文件");
FileConfiguration configuration = ConfigUtils.load(plugin, file); YamlConfiguration configuration = ConfigUtils.loadYaml(plugin, file);
TLocaleInstance localeInstance = new TLocaleInstance(); TLocaleInstance localeInstance = new TLocaleInstance();
localeInstance.load(configuration); localeInstance.load(configuration);
map.put(plugin.getName(), localeInstance); map.put(plugin.getName(), localeInstance);

View File

@ -23,31 +23,32 @@ import net.minecraft.server.v1_11_R1.EntityEvoker.e;
* @since 2018-04-22 * @since 2018-04-22
*/ */
@Immutable
@SerializableAs("TITLE") @SerializableAs("TITLE")
@Data
public class TLocaleTitle implements TLocaleSendable, ConfigurationSerializable { public class TLocaleTitle implements TLocaleSendable, ConfigurationSerializable {
private String title; private final String title;
private String subtitle; private final String subtitle;
private int fadein; private final int fadein;
private int fadeout; private final int fadeout;
private int stay; private final int stay;
private boolean usePlaceholder; 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; this.usePlaceholder = usePlaceholder;
} }
@Override @Override
public void sendTo(CommandSender sender, String... args) { public void sendTo(CommandSender sender, String... args) {
// TODO Auto-generated method stub
} }
@Override @Override
public String asString(String... args) { public String asString(String... args) {
// TODO Auto-generated method stub
return null; return null;
} }
@ -66,16 +67,15 @@ public class TLocaleTitle implements TLocaleSendable, ConfigurationSerializable
public static TLocaleTitle valueOf(Map<String, Object> map) { public static TLocaleTitle valueOf(Map<String, Object> map) {
TLocaleTitle title; TLocaleTitle title;
try { try {
title = new TLocaleTitle((boolean) map.getOrDefault("papi", TLib.getTLib().getConfig().isEnablePlaceholderHookByDefault())); title = new TLocaleTitle(
title.setTitle((String) map.getOrDefault("title", "")); (String) map.getOrDefault("title", ""),
title.setSubtitle((String) map.getOrDefault("subtitle", "")); (String) map.getOrDefault("subtitle", ""),
title.setFadein((int) map.getOrDefault("fadein", 10)); (int) map.getOrDefault("fadein", 10),
title.setFadeout((int) map.getOrDefault("fadeout", 10)); (int) map.getOrDefault("fadeout", 10),
title.setStay((int) map.getOrDefault("stay", 10)); (int) map.getOrDefault("stay", 20),
(boolean) map.getOrDefault("papi", TLib.getTLib().getConfig().isEnablePlaceholderHookByDefault()));
} catch (Exception e) { } catch (Exception e) {
title = new TLocaleTitle(false); title = new TLocaleTitle("§4Load failed!", "§c" + e.getMessage(), 10, 20, 10, false);
title.setTitle("§4Load failed!");
title.setSubtitle("§c" + e.getMessage());
} }
return title; return title;
} }

View File

@ -50,8 +50,11 @@ public class ConfigUtils {
* @return * @return
*/ */
public static FileConfiguration load(Plugin plugin, File file) { public static FileConfiguration load(Plugin plugin, File file) {
return loadYaml(plugin, file);
}
public static YamlConfiguration loadYaml(Plugin plugin, File file) {
YamlConfiguration yaml = new YamlConfiguration(); YamlConfiguration yaml = new YamlConfiguration();
try { try {
yaml = YamlConfiguration.loadConfiguration(new InputStreamReader(new FileInputStream(file), Charsets.UTF_8)); yaml = YamlConfiguration.loadConfiguration(new InputStreamReader(new FileInputStream(file), Charsets.UTF_8));
} catch (Exception e) { } catch (Exception e) {