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 static void fixUnicode(FileConfiguration configuration) {
public static void fixUnicode(YamlConfiguration configuration) {
try {
Field field = YamlConfiguration.class.getDeclaredField("yamlOptions");
field.setAccessible(true);

View File

@ -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) {

View File

@ -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);

View File

@ -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<String, Object> 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;
}

View File

@ -50,8 +50,11 @@ public class ConfigUtils {
* @return
*/
public static FileConfiguration load(Plugin plugin, File file) {
YamlConfiguration yaml = new YamlConfiguration();
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) {