1
0
mirror of https://github.com/mcMMO-Dev/mcMMO.git synced 2026-02-20 18:53:11 +01:00

Fix mcMMO saving copies of config files into the main server directory instead of the correct place

This commit is contained in:
nossr50
2021-04-09 10:19:34 -07:00
parent 6d057c577e
commit c1c32cb1fd
13 changed files with 64 additions and 49 deletions

View File

@@ -9,11 +9,10 @@ import java.io.File;
import java.util.List;
public abstract class ConfigLoader {
protected static final mcMMO plugin = mcMMO.p;
protected String fileName;
protected final File configFile;
protected FileConfiguration config;
protected @NotNull File dataFolder;
protected @NotNull final File dataFolder;
public ConfigLoader(String relativePath, String fileName, @NotNull File dataFolder) {
this.fileName = fileName;
@@ -33,6 +32,7 @@ public abstract class ConfigLoader {
public ConfigLoader(String relativePath, String fileName) {
this.fileName = fileName;
configFile = new File(mcMMO.p.getDataFolder(), relativePath + File.separator + fileName);
this.dataFolder = mcMMO.p.getDataFolder();
loadFile();
}
@@ -40,22 +40,23 @@ public abstract class ConfigLoader {
public ConfigLoader(String fileName) {
this.fileName = fileName;
configFile = new File(mcMMO.p.getDataFolder(), fileName);
this.dataFolder = mcMMO.p.getDataFolder();
loadFile();
}
protected void loadFile() {
if (!configFile.exists()) {
plugin.debug("Creating mcMMO " + fileName + " File...");
mcMMO.p.debug("Creating mcMMO " + fileName + " File...");
try {
plugin.saveResource(fileName, false); // Normal files
mcMMO.p.saveResource(fileName, false); // Normal files
}
catch (IllegalArgumentException ex) {
plugin.saveResource(configFile.getParentFile().getName() + File.separator + fileName, false); // Mod files
mcMMO.p.saveResource(configFile.getParentFile().getName() + File.separator + fileName, false); // Mod files
}
}
else {
plugin.debug("Loading mcMMO " + fileName + " File...");
mcMMO.p.debug("Loading mcMMO " + fileName + " File...");
}
config = YamlConfiguration.loadConfiguration(configFile);
@@ -69,7 +70,7 @@ public abstract class ConfigLoader {
protected boolean noErrorsInConfig(List<String> issues) {
for (String issue : issues) {
plugin.getLogger().warning(issue);
mcMMO.p.getLogger().warning(issue);
}
return issues.isEmpty();
@@ -77,12 +78,12 @@ public abstract class ConfigLoader {
protected void validate() {
if (validateKeys()) {
plugin.debug("No errors found in " + fileName + "!");
mcMMO.p.debug("No errors found in " + fileName + "!");
}
else {
plugin.getLogger().warning("Errors were found in " + fileName + "! mcMMO was disabled!");
plugin.getServer().getPluginManager().disablePlugin(plugin);
plugin.noErrorsInConfigFiles = false;
mcMMO.p.getLogger().warning("Errors were found in " + fileName + "! mcMMO was disabled!");
mcMMO.p.getServer().getPluginManager().disablePlugin(mcMMO.p);
mcMMO.p.noErrorsInConfigFiles = false;
}
}
@@ -91,16 +92,16 @@ public abstract class ConfigLoader {
}
public void backup() {
plugin.getLogger().warning("You are using an old version of the " + fileName + " file.");
plugin.getLogger().warning("Your old file has been renamed to " + fileName + ".old and has been replaced by an updated version.");
mcMMO.p.getLogger().warning("You are using an old version of the " + fileName + " file.");
mcMMO.p.getLogger().warning("Your old file has been renamed to " + fileName + ".old and has been replaced by an updated version.");
configFile.renameTo(new File(configFile.getPath() + ".old"));
if (plugin.getResource(fileName) != null) {
plugin.saveResource(fileName, true);
if (mcMMO.p.getResource(fileName) != null) {
mcMMO.p.saveResource(fileName, true);
}
plugin.getLogger().warning("Reloading " + fileName + " with new values...");
mcMMO.p.getLogger().warning("Reloading " + fileName + " with new values...");
loadFile();
loadKeys();
}