Do not log "enabled" when gate storage file is corrupted.

This commit is contained in:
Tobias Ottenweller 2013-06-20 19:58:34 +02:00
parent 1e9b9905a5
commit b64f41ce0c
3 changed files with 26 additions and 17 deletions

View File

@ -103,7 +103,7 @@ public class GatesManager
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void loadGatesFromDisk() public boolean loadGatesFromDisk()
{ {
this.gatesConfigFile = new File(Plugin.getPlugin().getDataFolder(), "gates.yml"); this.gatesConfigFile = new File(Plugin.getPlugin().getDataFolder(), "gates.yml");
@ -118,8 +118,7 @@ public class GatesManager
catch (IOException e) { catch (IOException e) {
this.storageFileIsInvalid = true; this.storageFileIsInvalid = true;
Plugin.log(Level.SEVERE, "Cannot create gate storage file! No gates will be persisted."); Plugin.log(Level.SEVERE, "Cannot create gate storage file! No gates will be persisted.");
Plugin.getPlugin().getServer().getPluginManager().disablePlugin(Plugin.getPlugin()); return false;
return;
} }
} }
@ -131,8 +130,7 @@ public class GatesManager
catch (Exception e) { catch (Exception e) {
this.storageFileIsInvalid = true; 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.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 false;
return;
} }
this.gates = (List<Gate>)gatesConfig.getList(gatesPath); this.gates = (List<Gate>)gatesConfig.getList(gatesPath);
@ -146,9 +144,8 @@ public class GatesManager
if (!(o instanceof Gate)) { if (!(o instanceof Gate)) {
this.storageFileIsInvalid = true; 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.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()); return false;
break; }
}
} }
for (Gate g : this.gates) { for (Gate g : this.gates) {
@ -178,14 +175,18 @@ public class GatesManager
if (fileStorageVersion > storageVersion) { if (fileStorageVersion > storageVersion) {
this.storageFileIsInvalid = true; 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.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 false;
return;
} }
if (fileStorageVersion < storageVersion && !this.gates.isEmpty()) { if (fileStorageVersion < storageVersion && !this.gates.isEmpty()) {
Plugin.log("Outdated storage version detected. Performing data migration..."); 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;
} }

View File

@ -147,9 +147,16 @@ public class Plugin extends JavaPlugin
this.registerEventListeners(); this.registerEventListeners();
// Load gates // Load gates
gatesManager.loadGatesFromDisk(); boolean success = gatesManager.loadGatesFromDisk();
log("Enabled"); if (success) {
log("Enabled");
}
else {
PluginManager pm = this.getServer().getPluginManager();
pm.disablePlugin(this);
}
} }
@ -169,7 +176,6 @@ public class Plugin extends JavaPlugin
} }
// -------------------------------------------- // // -------------------------------------------- //
// Commands // Commands
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -29,7 +29,7 @@ import java.util.logging.Level;
public class MigrationUtil public class MigrationUtil
{ {
public static void performMigration(int storageVersion, int currentVersion, List<Gate> gates) public static boolean performMigration(int storageVersion, int currentVersion, List<Gate> gates)
{ {
if (currentVersion == 1 && storageVersion == 0) { if (currentVersion == 1 && storageVersion == 0) {
@ -43,10 +43,12 @@ public class MigrationUtil
} }
} }
} }
return true;
} }
else { 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.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;
} }
} }
} }