diff --git a/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/AnarchyExploitFixes.java b/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/AnarchyExploitFixes.java index a28086ec..242cb2e0 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/AnarchyExploitFixes.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/AnarchyExploitFixes.java @@ -21,8 +21,6 @@ import java.io.File; import java.io.FileNotFoundException; -import java.io.IOException; -import java.nio.file.FileAlreadyExistsException; import java.nio.file.Files; import java.util.Arrays; import java.util.Collections; @@ -118,14 +116,6 @@ public void onEnable() { prefixedLogger.info("Detected Folia server."); } - try { - createDirectory(getDataFolder()); - } catch (IOException e) { - prefixedLogger.error("Unable to create plugin folder!", e); - getServer().getPluginManager().disablePlugin(this); - return; - } - prefixedLogger.info("Loading Config"); reloadConfiguration(); @@ -205,14 +195,6 @@ public static LanguageCache getLang(String lang) { return languageCacheMap.getOrDefault(lang.replace("-", "_"), languageCacheMap.get(config.default_lang.toString().toLowerCase())); } - public void createDirectory(File dir) throws IOException { - try { - Files.createDirectories(dir.toPath()); - } catch (FileAlreadyExistsException e) { // Thrown if dir exists but is not a directory - if (dir.delete()) createDirectory(dir); - } - } - public void reloadPlugin() { reloadConfiguration(); reloadLang(); @@ -220,7 +202,6 @@ public void reloadPlugin() { private void reloadConfiguration() { try { - createDirectory(getDataFolder()); config = new Config(); if (tickReporter != null) tickReporter.disable(); tickReporter = TickReporter.create(this, config.tickData_cache_duration); @@ -267,7 +248,7 @@ public void reloadLang() { private @NotNull List getAvailableTranslations() { try (final JarFile pluginJar = new JarFile(getFile())) { - createDirectory(new File(getDataFolder(), "/lang")); + Files.createDirectories(new File(getDataFolder(), "/lang").toPath()); final Pattern langPattern = Pattern.compile("([a-z]{1,3}_[a-z]{1,3})(\\.yml)", Pattern.CASE_INSENSITIVE); final File[] langDirFiles = new File(getDataFolder() + "/lang").listFiles(); return Stream.concat(pluginJar.stream().map(ZipEntry::getName), Arrays.stream(langDirFiles).map(File::getName)) diff --git a/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/config/Config.java b/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/config/Config.java index 20d2716a..f6763687 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/config/Config.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/config/Config.java @@ -8,6 +8,7 @@ import org.bukkit.Sound; import java.io.File; +import java.nio.file.Files; import java.time.Duration; import java.util.List; import java.util.Locale; @@ -30,8 +31,10 @@ public class Config { public Config() throws Exception { AnarchyExploitFixes plugin = AnarchyExploitFixes.getInstance(); + Files.createDirectories(plugin.getDataFolder().toPath()); // Load config.yml with ConfigMaster this.config = ConfigFile.loadConfig(new File(plugin.getDataFolder(), "config.yml")); + config.set("plugin-version", plugin.getPluginMeta().getVersion()); config.set("server-version", plugin.getServer().getVersion()); diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/AnarchyExploitFixes.java b/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/AnarchyExploitFixes.java index fd726224..96db1b46 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/AnarchyExploitFixes.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/AnarchyExploitFixes.java @@ -23,8 +23,6 @@ import java.io.File; import java.io.FileNotFoundException; -import java.io.IOException; -import java.nio.file.FileAlreadyExistsException; import java.nio.file.Files; import java.util.Arrays; import java.util.Collections; @@ -124,13 +122,6 @@ public void onEnable() { prefixedLogger.warn("Its highly recommended to use the Folia jar for your server."); } - try { - createDirectory(getDataFolder()); - } catch (IOException e) { - prefixedLogger.error("Unable to create plugin folder!", e); - getServer().getPluginManager().disablePlugin(this); - } - prefixedLogger.info("Loading Datastore"); datastore = new Datastore(); @@ -221,14 +212,6 @@ public static LanguageCache getLang(String lang) { return languageCacheMap.getOrDefault(lang.replace("-", "_"), languageCacheMap.get(config.default_lang.toString().toLowerCase())); } - public void createDirectory(File dir) throws IOException { - try { - Files.createDirectories(dir.toPath()); - } catch (FileAlreadyExistsException e) { // Thrown if dir exists but is not a directory - if (dir.delete()) createDirectory(dir); - } - } - public void reloadPlugin() { reloadConfiguration(); reloadLang(); @@ -236,7 +219,6 @@ public void reloadPlugin() { private void reloadConfiguration() { try { - createDirectory(getDataFolder()); config = new Config(); if (tickReporter != null) tickReporter.disable(); tickReporter = TickReporter.create(this, config.tps_cache_duration); @@ -283,7 +265,7 @@ public void reloadLang() { private @NotNull List getAvailableTranslations() { try (final JarFile pluginJar = new JarFile(getFile())) { - createDirectory(new File(getDataFolder(), "/lang")); + Files.createDirectories(new File(getDataFolder(), "/lang").toPath()); final Pattern langPattern = Pattern.compile("([a-z]{1,3}_[a-z]{1,3})(\\.yml)", Pattern.CASE_INSENSITIVE); final File[] langDirFiles = new File(getDataFolder() + "/lang").listFiles(); return Stream.concat(pluginJar.stream().map(ZipEntry::getName), Arrays.stream(langDirFiles).map(File::getName)) diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/config/Config.java b/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/config/Config.java index 2fcf2744..cee5e9ce 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/config/Config.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/config/Config.java @@ -10,6 +10,7 @@ import org.bukkit.Sound; import java.io.File; +import java.nio.file.Files; import java.time.Duration; import java.util.Collections; import java.util.HashMap; @@ -35,8 +36,10 @@ public class Config { public Config() throws Exception { AnarchyExploitFixes plugin = AnarchyExploitFixes.getInstance(); + Files.createDirectories(plugin.getDataFolder().toPath()); // Load config.yml with ConfigMaster this.config = ConfigFile.loadConfig(new File(plugin.getDataFolder(), "config.yml")); + config.set("plugin-version", plugin.getDescription().getVersion()); config.set("server-version", plugin.getServer().getVersion());