Disable the plugin if the gate storage file is corrupted.
This commit is contained in:
		| @@ -51,6 +51,8 @@ public class GatesManager | |||||||
|  |  | ||||||
|     protected List<Gate> gates; |     protected List<Gate> gates; | ||||||
|  |  | ||||||
|  |     protected boolean storageFileIsInvalid = false; | ||||||
|  |  | ||||||
|  |  | ||||||
| 	public Gate getGateWithId(final String id) | 	public Gate getGateWithId(final String id) | ||||||
| 	{ | 	{ | ||||||
| @@ -81,7 +83,12 @@ public class GatesManager | |||||||
| 	 | 	 | ||||||
| 	public void saveGatesToDisk() | 	public void saveGatesToDisk() | ||||||
| 	{ | 	{ | ||||||
| 		gatesConfig.set(gatesPath, new ArrayList<Object>(gatesById.values())); | 		if (storageFileIsInvalid) { | ||||||
|  |             Plugin.log(Level.SEVERE, "ERROR: Not saving gates to disk. Storage file is invalid or corrupted!"); | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         gatesConfig.set(gatesPath, new ArrayList<Object>(gatesById.values())); | ||||||
|         gatesConfig.set(storageVersionPath, storageVersion); |         gatesConfig.set(storageVersionPath, storageVersion); | ||||||
| 		 | 		 | ||||||
| 		try { | 		try { | ||||||
| @@ -118,9 +125,9 @@ public class GatesManager | |||||||
|         for (Object o : this.gates) { |         for (Object o : this.gates) { | ||||||
| 			 | 			 | ||||||
| 			if (!(o instanceof Gate)) { | 			if (!(o instanceof Gate)) { | ||||||
| 				Plugin.log(Level.SEVERE, "Gate file on disk is invalid. No gates loaded."); |                 this.storageFileIsInvalid = true; | ||||||
| 				// TODO: gates.yml will be empty after save/reload/server stop! All gates will be lost! No user will expect this! | 				Plugin.log(Level.SEVERE, "Gate file on disk is invalid. No gates loaded. Plugin will be disabled!"); | ||||||
| 				this.gates = new ArrayList<Gate>(); |                 Plugin.getPlugin().getServer().getPluginManager().disablePlugin(Plugin.getPlugin()); | ||||||
| 				break; | 				break; | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Tobias Ottenweller
					Tobias Ottenweller