Makes sure configuration pointers are still valid after reloading
All checks were successful
KnarCraft/KnarLib/pipeline/head This commit looks good

This commit is contained in:
2025-09-06 16:14:08 +02:00
parent 0ac76f28c3
commit 9e04d72449
2 changed files with 18 additions and 9 deletions

View File

@@ -40,14 +40,6 @@ public class StargateYamlConfiguration extends YamlConfiguration {
private static final String END_OF_COMMENT = "_endOfComment_";
private static final String START_OF_COMMENT = "comment_";
@Override
@NotNull
@Deprecated
@SuppressWarnings("deprecation")
protected String buildHeader() {
return "";
}
@Override
@NotNull
public String saveToString() {
@@ -61,6 +53,19 @@ public class StargateYamlConfiguration extends YamlConfiguration {
super.loadFromString(this.convertCommentsToYAMLMappings(contents));
}
/**
* Reloads this configuration
*
* @param plugin <p>The plugin this configuration belongs to</p>
*/
public void reload(@NotNull Plugin plugin) {
try {
this.load(new File(plugin.getDataFolder(), ConfigHelper.getConfigFile()));
} catch (IOException | InvalidConfigurationException exception) {
plugin.getLogger().log(Level.SEVERE, "Unable to load the configuration! Message: " + exception.getMessage());
}
}
/**
* Loads the configuration of the given plugin
*

View File

@@ -46,7 +46,11 @@ public abstract class ConfigCommentPlugin extends JavaPlugin {
@Override
public void reloadConfig() {
this.configuration = StargateYamlConfiguration.loadConfiguration(this, true);
if (this.configuration == null) {
this.configuration = StargateYamlConfiguration.loadConfiguration(this, true);
} else {
this.configuration.reload(this);
}
}
@Override