From 532e6c01f36df4f5b3a6ad6c8550e68c01d4a932 Mon Sep 17 00:00:00 2001 From: Logan Magnan Date: Thu, 26 Sep 2024 16:57:52 -0400 Subject: [PATCH] added config updater --- .../pluginbase/commands/ExampleCommand.java | 1 + .../pluginbase/utils/ConfigUpdater.java | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/loganmagnan/pluginbase/commands/ExampleCommand.java b/src/main/java/com/loganmagnan/pluginbase/commands/ExampleCommand.java index 46f93d2..dc73988 100644 --- a/src/main/java/com/loganmagnan/pluginbase/commands/ExampleCommand.java +++ b/src/main/java/com/loganmagnan/pluginbase/commands/ExampleCommand.java @@ -15,6 +15,7 @@ public class ExampleCommand extends BaseCommand { @Command(name = "example", permission = "permission.example") @Override + public void executeAs(CommandArguments command) { Player player = command.getPlayer(); diff --git a/src/main/java/com/loganmagnan/pluginbase/utils/ConfigUpdater.java b/src/main/java/com/loganmagnan/pluginbase/utils/ConfigUpdater.java index 6efb4fd..3cad316 100644 --- a/src/main/java/com/loganmagnan/pluginbase/utils/ConfigUpdater.java +++ b/src/main/java/com/loganmagnan/pluginbase/utils/ConfigUpdater.java @@ -28,8 +28,14 @@ public class ConfigUpdater { public static void update(Plugin plugin, String resourceName, File toUpdate, List ignoredSections) throws IOException { Preconditions.checkArgument(toUpdate.exists(), "The toUpdate file doesn't exist!"); - FileConfiguration defaultConfig = YamlConfiguration.loadConfiguration(new InputStreamReader(plugin.getResource(resourceName), StandardCharsets.UTF_8)); + FileConfiguration defaultConfig = YamlConfiguration.loadConfiguration( + new InputStreamReader( + plugin.getClass().getClassLoader().getResourceAsStream(resourceName) + ) + ); + FileConfiguration currentConfig = YamlConfiguration.loadConfiguration(toUpdate); + Map comments = parseComments(plugin, resourceName, defaultConfig); Map ignoredSectionsValues = parseIgnoredSections(toUpdate, comments, ignoredSections == null ? Collections.emptyList() : ignoredSections); // will write updated config file "contents" to a string @@ -83,7 +89,13 @@ public class ConfigUpdater { private static Map parseComments(Plugin plugin, String resourceName, FileConfiguration defaultConfig) throws IOException { //keys are in order List keys = new ArrayList<>(defaultConfig.getKeys(true)); - BufferedReader reader = new BufferedReader(new InputStreamReader(plugin.getResource(resourceName))); + + BufferedReader reader = new BufferedReader( + new InputStreamReader( + plugin.getClass().getClassLoader().getResourceAsStream(resourceName) + ) + ); + Map comments = new LinkedHashMap<>(); StringBuilder commentBuilder = new StringBuilder(); KeyBuilder keyBuilder = new KeyBuilder(defaultConfig, SEPARATOR); @@ -365,4 +377,4 @@ public class ConfigUpdater { bufferedWriter.write(" {}\n"); } } -} \ No newline at end of file +}