Do not log "enabled" when gate storage file is corrupted.
This commit is contained in:
		| @@ -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<Gate>)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; | ||||
| 	} | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -147,9 +147,16 @@ public class Plugin extends JavaPlugin | ||||
| 		this.registerEventListeners(); | ||||
| 		 | ||||
| 		// 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 | ||||
| 	// -------------------------------------------- // | ||||
|   | ||||
| @@ -29,7 +29,7 @@ import java.util.logging.Level; | ||||
|  | ||||
| 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) { | ||||
|  | ||||
| @@ -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; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Tobias Ottenweller
					Tobias Ottenweller