diff options
author | Tyler Murphy <tylermurphy534@gmail.com> | 2022-05-05 12:22:04 -0400 |
---|---|---|
committer | Tyler Murphy <tylermurphy534@gmail.com> | 2022-05-05 12:22:04 -0400 |
commit | 36027e007e512d54e7e3cd8fb66774cc9c5e43f2 (patch) | |
tree | 3ebf0f2868f8b2be243124f7f69e8681a7ff0124 /src/main/java/net/tylermurphy/hideAndSeek/configuration | |
parent | actionbar messages (diff) | |
download | kenshinshideandseek-36027e007e512d54e7e3cd8fb66774cc9c5e43f2.tar.gz kenshinshideandseek-36027e007e512d54e7e3cd8fb66774cc9c5e43f2.tar.bz2 kenshinshideandseek-36027e007e512d54e7e3cd8fb66774cc9c5e43f2.zip |
countdown titles, and possible config save for utf8
Diffstat (limited to 'src/main/java/net/tylermurphy/hideAndSeek/configuration')
-rw-r--r-- | src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java | 11 | ||||
-rw-r--r-- | src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java | 29 |
2 files changed, 27 insertions, 13 deletions
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java index 79571fc..ee2f8b6 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java @@ -22,6 +22,8 @@ package net.tylermurphy.hideAndSeek.configuration; import com.cryptomorin.xseries.XItemStack; import com.cryptomorin.xseries.XMaterial; import com.cryptomorin.xseries.XSound; +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.util.CountdownDisplay; import net.tylermurphy.hideAndSeek.util.Version; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -136,6 +138,9 @@ public class Config { public static XSound ringingSound, heartbeatSound; + + public static CountdownDisplay + countdownDisplay; public static void loadConfig() { @@ -249,6 +254,12 @@ public class Config { locale = config.getString("locale", "local"); blockedCommands = config.getStringList("blockedCommands"); leaveOnEnd = config.getBoolean("leaveOnEnd"); + try { + countdownDisplay = CountdownDisplay.valueOf(config.getString("hideCountdownDisplay")); + } catch (IllegalArgumentException e){ + countdownDisplay = CountdownDisplay.CHAT; + Main.plugin.getLogger().warning("hideCountdownDisplay: "+config.getString("hideCountdownDisplay")+" is not a valid configuration option!"); + } blockedInteracts = new ArrayList<>(); List<String> tempInteracts = config.getStringList("blockedInteracts"); for(String id : tempInteracts){ diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java index 3546fa8..0168dc5 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java @@ -52,16 +52,20 @@ public class ConfigManager { this.config = YamlConfiguration.loadConfiguration(file); - InputStream input = Main.plugin.getResource(file.getName()); - if(input == null){ + FileInputStream input = null; + try{ + input = new FileInputStream(file); + } catch (Exception e){ throw new RuntimeException("Could not create input stream for "+file.getPath()); } - InputStreamReader reader = new InputStreamReader(input); + + InputStreamReader reader = new InputStreamReader(input, StandardCharsets.UTF_8); this.defaultConfig = YamlConfiguration.loadConfiguration(reader); try{ input.close(); reader.close(); - } catch (IOException ignored){} + } catch (IOException ignored){ + } } public ConfigManager(String filename, String defaultFilename){ @@ -221,7 +225,7 @@ public class ConfigManager { while((c = reader.read()) != -1){ textBuilder.append((char) c); } - String yamlString = textBuilder.toString(); + String yamlString = new String(textBuilder.toString().getBytes(), StandardCharsets.UTF_8); Map<String, Object> temp = config.getValues(true); for(Map.Entry<String, Object> entry: temp.entrySet()){ if(entry.getValue() instanceof Integer || entry.getValue() instanceof Double || entry.getValue() instanceof String || entry.getValue() instanceof Boolean || entry.getValue() instanceof List){ @@ -246,26 +250,25 @@ public class ConfigManager { if(entry.getValue() instanceof List){ if(((List<?>) entry.getValue()).isEmpty()) continue; replace = "["; - for(Object o : (List<Object>)entry.getValue()){ - replace = replace + o.toString() + ", "; + for(Object o : (List<?>)entry.getValue()){ + replace = replace + new String(o.toString().getBytes(), StandardCharsets.UTF_8) + ", "; } replace = replace.substring(0, replace.length()-2); replace = replace + "]"; } else { - replace = entry.getValue().toString(); + replace = new String(entry.getValue().toString().getBytes(), StandardCharsets.UTF_8); } if(entry.getValue() instanceof String){ replace = "\"" + replace + "\""; } StringBuilder builder = new StringBuilder(yamlString); builder.replace(start+1, end, replace); - yamlString = builder.toString(); + yamlString = new String(builder.toString().getBytes(), StandardCharsets.UTF_8); } } - OutputStream os = new FileOutputStream(file); - PrintWriter out = new PrintWriter(new OutputStreamWriter(os, StandardCharsets.UTF_8), true); - out.print(yamlString); - out.close(); + Writer fileWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)); + fileWriter.write(yamlString); + fileWriter.close(); } catch (IOException e){ e.printStackTrace(); } |