added config updater
This commit is contained in:
parent
20b4f884d2
commit
532e6c01f3
@ -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();
|
||||
|
||||
|
@ -28,8 +28,14 @@ public class ConfigUpdater {
|
||||
public static void update(Plugin plugin, String resourceName, File toUpdate, List<String> 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<String, String> comments = parseComments(plugin, resourceName, defaultConfig);
|
||||
Map<String, String> 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<String, String> parseComments(Plugin plugin, String resourceName, FileConfiguration defaultConfig) throws IOException {
|
||||
//keys are in order
|
||||
List<String> 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<String, String> comments = new LinkedHashMap<>();
|
||||
StringBuilder commentBuilder = new StringBuilder();
|
||||
KeyBuilder keyBuilder = new KeyBuilder(defaultConfig, SEPARATOR);
|
||||
@ -365,4 +377,4 @@ public class ConfigUpdater {
|
||||
bufferedWriter.write(" {}\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user