diff --git a/src/de/craftinc/gates/GatesManager.java b/src/de/craftinc/gates/GatesManager.java index 45d28a3..e2bac0e 100644 --- a/src/de/craftinc/gates/GatesManager.java +++ b/src/de/craftinc/gates/GatesManager.java @@ -103,7 +103,7 @@ public class GatesManager @SuppressWarnings("unchecked") - public void loadGatesFromDisk() + public boolean loadGatesFromDisk() { this.gatesConfigFile = new File(Plugin.getPlugin().getDataFolder(), "gates.yml"); @@ -118,8 +118,7 @@ public class GatesManager catch (IOException e) { this.storageFileIsInvalid = true; Plugin.log(Level.SEVERE, "Cannot create gate storage file! No gates will be persisted."); - Plugin.getPlugin().getServer().getPluginManager().disablePlugin(Plugin.getPlugin()); - return; + return false; } } @@ -131,8 +130,7 @@ public class GatesManager catch (Exception e) { this.storageFileIsInvalid = true; Plugin.log(Level.SEVERE, "Gate file on disk is invalid. No gates loaded. Plugin will be disabled! (" + Arrays.toString(e.getStackTrace()) + ")"); - Plugin.getPlugin().getServer().getPluginManager().disablePlugin(Plugin.getPlugin()); - return; + return false; } this.gates = (List)gatesConfig.getList(gatesPath); @@ -146,9 +144,8 @@ public class GatesManager if (!(o instanceof Gate)) { this.storageFileIsInvalid = true; Plugin.log(Level.SEVERE, "Gate file on disk is invalid. No gates loaded. Plugin will be disabled! (Invalid gate class detected)"); - Plugin.getPlugin().getServer().getPluginManager().disablePlugin(Plugin.getPlugin()); - break; - } + return false; + } } for (Gate g : this.gates) { @@ -178,14 +175,18 @@ public class GatesManager if (fileStorageVersion > storageVersion) { this.storageFileIsInvalid = true; Plugin.log(Level.SEVERE, "Unsupported storage version detected! Make sure you have the latest version of Craft Inc. Gates installed. Plugin will be disabled!"); - Plugin.getPlugin().getServer().getPluginManager().disablePlugin(Plugin.getPlugin()); - return; + return false; } if (fileStorageVersion < storageVersion && !this.gates.isEmpty()) { Plugin.log("Outdated storage version detected. Performing data migration..."); - MigrationUtil.performMigration(fileStorageVersion, storageVersion, this.gates); + boolean success = MigrationUtil.performMigration(fileStorageVersion, storageVersion, this.gates); + + this.storageFileIsInvalid = !success; + return success; } + + return true; } diff --git a/src/de/craftinc/gates/Plugin.java b/src/de/craftinc/gates/Plugin.java index 91d4353..a40cc1b 100644 --- a/src/de/craftinc/gates/Plugin.java +++ b/src/de/craftinc/gates/Plugin.java @@ -147,9 +147,16 @@ public class Plugin extends JavaPlugin this.registerEventListeners(); // Load gates - gatesManager.loadGatesFromDisk(); - - log("Enabled"); + boolean success = gatesManager.loadGatesFromDisk(); + + if (success) { + log("Enabled"); + + } + else { + PluginManager pm = this.getServer().getPluginManager(); + pm.disablePlugin(this); + } } @@ -168,7 +175,6 @@ public class Plugin extends JavaPlugin } } - // -------------------------------------------- // // Commands diff --git a/src/de/craftinc/gates/persistence/MigrationUtil.java b/src/de/craftinc/gates/persistence/MigrationUtil.java index 0af5473..9010bc7 100644 --- a/src/de/craftinc/gates/persistence/MigrationUtil.java +++ b/src/de/craftinc/gates/persistence/MigrationUtil.java @@ -29,7 +29,7 @@ import java.util.logging.Level; public class MigrationUtil { - public static void performMigration(int storageVersion, int currentVersion, List gates) + public static boolean performMigration(int storageVersion, int currentVersion, List gates) { if (currentVersion == 1 && storageVersion == 0) { @@ -43,10 +43,12 @@ public class MigrationUtil } } } + + return true; } else { Plugin.log(Level.SEVERE, "Supplied storage version is currently not supported! Make sure you have the latest version of Craft Inc. Gates installed. Plugin will be disabled!"); - Plugin.getPlugin().getServer().getPluginManager().disablePlugin(Plugin.getPlugin()); + return false; } } }