added config updater

This commit is contained in:
Logan Magnan 2024-09-26 18:03:08 -04:00
parent 95c591f55c
commit ccfe0c6098
3 changed files with 10 additions and 6 deletions

View File

@ -40,8 +40,8 @@ public class PluginBase extends JavaPlugin {
// Initialize all of the configuration files
this.saveDefaultConfig();
this.mainConfig = new Config("config", this);
this.messagesConfig = new FileConfig(this, "messages.yml");
this.mainConfig = new Config("config", this, true);
this.messagesConfig = new FileConfig(this, "messages.yml", true);
// Say the plugin's name
this.getServer().getConsoleSender().sendMessage(Utils.chatBar);

View File

@ -24,7 +24,7 @@ public class FileConfig {
return this.config;
}
public FileConfig(JavaPlugin plugin, String fileName) {
public FileConfig(JavaPlugin plugin, String fileName, boolean update) {
this.file = new File(plugin.getDataFolder(), fileName);
if (!this.file.exists()) {
this.file.getParentFile().mkdirs();
@ -40,7 +40,9 @@ public class FileConfig {
}
try {
ConfigUpdater.update(PluginBase.getInstance(), fileName, this.file);
if (update) {
ConfigUpdater.update(PluginBase.getInstance(), fileName, this.file);
}
} catch (Exception exception) {
exception.printStackTrace();
}

View File

@ -17,7 +17,7 @@ public class Config {
private final File configFile;
protected boolean wasCreated;
public Config(String name, JavaPlugin plugin) {
public Config(String name, JavaPlugin plugin, boolean update) {
this.configFile = new File(plugin.getDataFolder() + "/" + name + ".yml");
if (!this.configFile.exists()) {
try {
@ -30,7 +30,9 @@ public class Config {
}
try {
ConfigUpdater.update(PluginBase.getInstance(), name + ".yml", this.configFile);
if (update) {
ConfigUpdater.update(PluginBase.getInstance(), name + ".yml", this.configFile);
}
} catch (Exception exception) {
exception.printStackTrace();
}