|
18 | 18 |
|
19 | 19 | import java.io.File; |
20 | 20 | import java.io.IOException; |
| 21 | +import java.io.InputStream; |
21 | 22 | import java.io.InputStreamReader; |
22 | 23 | import java.io.Reader; |
| 24 | +import java.nio.charset.StandardCharsets; |
23 | 25 | import java.time.Duration; |
24 | 26 |
|
25 | 27 | public class BMBukkitPlugin extends JavaPlugin { |
@@ -84,31 +86,34 @@ private PluginInfo setupConfigs() throws IOException { |
84 | 86 | this.saveResource(name, false); |
85 | 87 | } else { |
86 | 88 | File file = new File(getDataFolder(), name); |
87 | | - Reader defConfigStream = new InputStreamReader(getResource(file.getName()), "UTF8"); |
88 | | - |
89 | | - YamlConfiguration conf = YamlConfiguration.loadConfiguration(file); |
90 | | - YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream); |
91 | | - conf.setDefaults(defConfig); |
92 | | - conf.options().copyDefaults(true); |
93 | | - conf.save(file); |
| 89 | + try (InputStream in = getResource(file.getName()); |
| 90 | + Reader defConfigStream = new InputStreamReader(in, StandardCharsets.UTF_8)) { |
| 91 | + YamlConfiguration conf = YamlConfiguration.loadConfiguration(file); |
| 92 | + YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream); |
| 93 | + conf.setDefaults(defConfig); |
| 94 | + conf.options().copyDefaults(true); |
| 95 | + conf.save(file); |
| 96 | + } |
94 | 97 | } |
95 | 98 | } |
96 | 99 |
|
97 | 100 | // Load plugin.yml |
98 | 101 | PluginInfo pluginInfo = new PluginInfo(); |
99 | | - Reader defConfigStream = new InputStreamReader(getResource("plugin.yml"), "UTF8"); |
100 | | - YamlConfiguration conf = YamlConfiguration.loadConfiguration(defConfigStream); |
101 | | - ConfigurationSection commands = conf.getConfigurationSection("commands"); |
102 | | - String pluginName = conf.getString("name"); |
103 | | - |
104 | | - if (!pluginName.equals("BanManager")) { |
105 | | - throw new IOException("Unable to start BanManager as " + pluginName + " has broken resource loading forcing BanManager to load their plugin.yml file; please alert the author to resolve this issue"); |
106 | | - } |
| 102 | + try (InputStream in = getResource("plugin.yml"); |
| 103 | + Reader defConfigStream = new InputStreamReader(in, StandardCharsets.UTF_8)) { |
| 104 | + YamlConfiguration conf = YamlConfiguration.loadConfiguration(defConfigStream); |
| 105 | + ConfigurationSection commands = conf.getConfigurationSection("commands"); |
| 106 | + String pluginName = conf.getString("name"); |
| 107 | + |
| 108 | + if (!pluginName.equals("BanManager")) { |
| 109 | + throw new IOException("Unable to start BanManager as " + pluginName + " has broken resource loading forcing BanManager to load their plugin.yml file; please alert the author to resolve this issue"); |
| 110 | + } |
107 | 111 |
|
108 | | - for (String command : commands.getKeys(false)) { |
109 | | - ConfigurationSection cmd = commands.getConfigurationSection(command); |
| 112 | + for (String command : commands.getKeys(false)) { |
| 113 | + ConfigurationSection cmd = commands.getConfigurationSection(command); |
110 | 114 |
|
111 | | - pluginInfo.setCommand(new PluginInfo.CommandInfo(command, cmd.getString("permission"), cmd.getString("usage"), cmd.getStringList("aliases"))); |
| 115 | + pluginInfo.setCommand(new PluginInfo.CommandInfo(command, cmd.getString("permission"), cmd.getString("usage"), cmd.getStringList("aliases"))); |
| 116 | + } |
112 | 117 | } |
113 | 118 |
|
114 | 119 | Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> { |
|
0 commit comments