From cb5ada6ec9a31741125d544b7d3445c84adbdc9c Mon Sep 17 00:00:00 2001 From: GJ Date: Sat, 5 May 2012 13:02:36 -0400 Subject: [PATCH] Fix for config files not being created at startup. --- .../java/com/gmail/nossr50/config/Config.java | 3 +- .../gmail/nossr50/config/LoadTreasures.java | 3 +- .../nossr50/config/mods/LoadCustomTools.java | 3 +- src/main/java/com/gmail/nossr50/mcMMO.java | 64 +++++++++++-------- 4 files changed, 40 insertions(+), 33 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/config/Config.java b/src/main/java/com/gmail/nossr50/config/Config.java index 6a5ae5067..dd941473e 100644 --- a/src/main/java/com/gmail/nossr50/config/Config.java +++ b/src/main/java/com/gmail/nossr50/config/Config.java @@ -444,11 +444,10 @@ public class Config extends ConfigLoader { super(plugin, "config.yml"); config = plugin.getConfig(); xpGainMultiplier = getExperienceGainsGlobalMultiplier(); - load(); } @Override - protected void load() { + public void load() { if (!configFile.exists()) { dataFolder.mkdir(); plugin.saveDefaultConfig(); diff --git a/src/main/java/com/gmail/nossr50/config/LoadTreasures.java b/src/main/java/com/gmail/nossr50/config/LoadTreasures.java index c7cc066b8..2659947fe 100644 --- a/src/main/java/com/gmail/nossr50/config/LoadTreasures.java +++ b/src/main/java/com/gmail/nossr50/config/LoadTreasures.java @@ -43,11 +43,10 @@ public class LoadTreasures extends ConfigLoader{ private LoadTreasures(mcMMO plugin) { super(plugin, "treasures.yml"); config = plugin.getTreasuresConfig(); - load(); } @Override - protected void load() { + public void load() { if (!configFile.exists()) { dataFolder.mkdir(); plugin.saveTreasuresConfig(); diff --git a/src/main/java/com/gmail/nossr50/config/mods/LoadCustomTools.java b/src/main/java/com/gmail/nossr50/config/mods/LoadCustomTools.java index b14d60101..84a370428 100644 --- a/src/main/java/com/gmail/nossr50/config/mods/LoadCustomTools.java +++ b/src/main/java/com/gmail/nossr50/config/mods/LoadCustomTools.java @@ -41,11 +41,10 @@ public class LoadCustomTools extends ConfigLoader { private LoadCustomTools(mcMMO plugin) { super(plugin, "ModConfigs" + File.separator + "tools.yml"); config = plugin.getToolsConfig(); - load(); } @Override - protected void load() { + public void load() { if (!configFile.exists()) { dataFolder.mkdir(); plugin.saveToolsConfig(); diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index 759952c31..e8943e3f3 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -7,6 +7,7 @@ import com.gmail.nossr50.commands.mc.*; import com.gmail.nossr50.commands.party.*; import com.gmail.nossr50.commands.general.*; import com.gmail.nossr50.config.*; +import com.gmail.nossr50.config.mods.LoadCustomTools; import com.gmail.nossr50.runnables.*; import com.gmail.nossr50.util.Database; import com.gmail.nossr50.util.Leaderboard; @@ -48,16 +49,18 @@ public class mcMMO extends JavaPlugin { public static Database database; public static mcMMO p; - //Jar stuff + /* Jar Stuff */ public static File mcmmo; - //File Paths + /* File Paths */ public static String mainDirectory; public static String flatFileDirectory; public static String usersFile; public static String leaderboardDirectory; public static String modDirectory; + private static Config configInstance = Config.getInstance(); + /** * Things to be run when the plugin is enabled. */ @@ -71,7 +74,14 @@ public class mcMMO extends JavaPlugin { modDirectory = mainDirectory + "ModConfigs" + File.separator; usersFile = flatFileDirectory + "mcmmo.users"; - if (!Config.getInstance().getUseMySQL()) { + configInstance.load(); + LoadTreasures.getInstance().load(); + + if (configInstance.getToolModsEnabled()) { + LoadCustomTools.getInstance().load(); + } + + if (!configInstance.getUseMySQL()) { Users.loadUsers(); } @@ -82,14 +92,14 @@ public class mcMMO extends JavaPlugin { pm.registerEvents(blockListener, this); pm.registerEvents(entityListener, this); - if (Config.getInstance().getHardcoreEnabled()) { + if (configInstance.getHardcoreEnabled()) { pm.registerEvents(hardcoreListener, this); } PluginDescriptionFile pdfFile = getDescription(); //Setup the leaderboards - if (Config.getInstance().getUseMySQL()) { + if (configInstance.getUseMySQL()) { database = new Database(this); database.createStructure(); } @@ -108,7 +118,7 @@ public class mcMMO extends JavaPlugin { //Schedule Spout Activation 1 second after start-up scheduler.scheduleSyncDelayedTask(this, new SpoutStart(this), 20); //Periodic save timer (Saves every 10 minutes) - scheduler.scheduleSyncRepeatingTask(this, new SaveTimer(this), 0, Config.getInstance().getSaveInterval() * 1200); + scheduler.scheduleSyncRepeatingTask(this, new SaveTimer(this), 0, configInstance.getSaveInterval() * 1200); //Regen & Cooldown timer (Runs every second) scheduler.scheduleSyncRepeatingTask(this, new SkillMonitor(this), 0, 20); //Bleed timer (Runs every two seconds) @@ -116,7 +126,7 @@ public class mcMMO extends JavaPlugin { registerCommands(); - if (Config.getInstance().getStatsTrackingEnabled()) { + if (configInstance.getStatsTrackingEnabled()) { try { Metrics metrics = new Metrics(this); metrics.start(); @@ -220,88 +230,88 @@ public class mcMMO extends JavaPlugin { getCommand("woodcutting").setExecutor(new WoodcuttingCommand()); //mc* commands - if (Config.getInstance().getCommandMCRemoveEnabled()) { + if (configInstance.getCommandMCRemoveEnabled()) { getCommand("mcremove").setExecutor(new McremoveCommand(this)); } - if (Config.getInstance().getCommandMCAbilityEnabled()) { + if (configInstance.getCommandMCAbilityEnabled()) { getCommand("mcability").setExecutor(new McabilityCommand()); } - if (Config.getInstance().getCommandMCCEnabled()) { + if (configInstance.getCommandMCCEnabled()) { getCommand("mcc").setExecutor(new MccCommand()); } - if (Config.getInstance().getCommandMCGodEnabled()) { + if (configInstance.getCommandMCGodEnabled()) { getCommand("mcgod").setExecutor(new McgodCommand()); } - if (Config.getInstance().getCommandmcMMOEnabled()) { + if (configInstance.getCommandmcMMOEnabled()) { getCommand("mcmmo").setExecutor(new McmmoCommand()); } - if (Config.getInstance().getCommandMCRefreshEnabled()) { + if (configInstance.getCommandMCRefreshEnabled()) { getCommand("mcrefresh").setExecutor(new McrefreshCommand(this)); } - if (Config.getInstance().getCommandMCTopEnabled()) { + if (configInstance.getCommandMCTopEnabled()) { getCommand("mctop").setExecutor(new MctopCommand()); } - if (Config.getInstance().getCommandMCStatsEnabled()) { + if (configInstance.getCommandMCStatsEnabled()) { getCommand("mcstats").setExecutor(new McstatsCommand()); } //Party commands - if (Config.getInstance().getCommandAcceptEnabled()) { + if (configInstance.getCommandAcceptEnabled()) { getCommand("accept").setExecutor(new AcceptCommand(this)); } - if (Config.getInstance().getCommandAdminChatAEnabled()) { + if (configInstance.getCommandAdminChatAEnabled()) { getCommand("a").setExecutor(new ACommand(this)); } - if (Config.getInstance().getCommandInviteEnabled()) { + if (configInstance.getCommandInviteEnabled()) { getCommand("invite").setExecutor(new InviteCommand(this)); } - if (Config.getInstance().getCommandPartyEnabled()) { + if (configInstance.getCommandPartyEnabled()) { getCommand("party").setExecutor(new PartyCommand(this)); } - if (Config.getInstance().getCommandPartyChatPEnabled()) { + if (configInstance.getCommandPartyChatPEnabled()) { getCommand("p").setExecutor(new PCommand(this)); } - if (Config.getInstance().getCommandPTPEnabled()) { + if (configInstance.getCommandPTPEnabled()) { getCommand("ptp").setExecutor(new PtpCommand(this)); } //Other commands - if (Config.getInstance().getCommandAddXPEnabled()) { + if (configInstance.getCommandAddXPEnabled()) { getCommand("addxp").setExecutor(new AddxpCommand(this)); } - if (Config.getInstance().getCommandAddLevelsEnabled()) { + if (configInstance.getCommandAddLevelsEnabled()) { getCommand("addlevels").setExecutor(new AddlevelsCommand(this)); } - if (Config.getInstance().getCommandMmoeditEnabled()) { + if (configInstance.getCommandMmoeditEnabled()) { getCommand("mmoedit").setExecutor(new MmoeditCommand(this)); } - if (Config.getInstance().getCommandInspectEnabled()) { + if (configInstance.getCommandInspectEnabled()) { getCommand("inspect").setExecutor(new InspectCommand(this)); } - if (Config.getInstance().getCommandXPRateEnabled()) { + if (configInstance.getCommandXPRateEnabled()) { getCommand("xprate").setExecutor(new XprateCommand(this)); } getCommand("mmoupdate").setExecutor(new MmoupdateCommand(this)); //Spout commands - if (Config.getInstance().getCommandXPLockEnabled()) { + if (configInstance.getCommandXPLockEnabled()) { getCommand("xplock").setExecutor(new XplockCommand()); }