Widened the exception catching nets for loading and saving all data (IOException -> Exception, etc.), so loading and saving problems don't wipe out unrelated plugin data
This commit is contained in:
		@@ -195,9 +195,9 @@ public class Board {
 | 
			
		||||
		
 | 
			
		||||
		try {
 | 
			
		||||
			DiscUtil.write(file, Factions.gson.toJson(dumpAsSaveFormat()));
 | 
			
		||||
		} catch (IOException e) {
 | 
			
		||||
			Factions.log("Failed to save the board to disk.");
 | 
			
		||||
		} catch (Exception e) {
 | 
			
		||||
			e.printStackTrace();
 | 
			
		||||
			Factions.log("Failed to save the board to disk.");
 | 
			
		||||
			return false;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
@@ -218,9 +218,9 @@ public class Board {
 | 
			
		||||
			Type type = new TypeToken<Map<String,Map<String,Integer>>>(){}.getType();
 | 
			
		||||
			Map<String,Map<String,Integer>> worldCoordIds = Factions.gson.fromJson(DiscUtil.read(file), type);
 | 
			
		||||
			loadFromSaveFormat(worldCoordIds);
 | 
			
		||||
		} catch (IOException e) {
 | 
			
		||||
			Factions.log("Failed to load the board from disk.");
 | 
			
		||||
		} catch (Exception e) {
 | 
			
		||||
			e.printStackTrace();
 | 
			
		||||
			Factions.log("Failed to load the board from disk.");
 | 
			
		||||
			return false;
 | 
			
		||||
		}
 | 
			
		||||
			
 | 
			
		||||
 
 | 
			
		||||
@@ -7,6 +7,7 @@ import org.bukkit.*;
 | 
			
		||||
import org.bukkit.entity.CreatureType;
 | 
			
		||||
 | 
			
		||||
import com.bukkit.mcteam.util.DiscUtil;
 | 
			
		||||
import com.bukkit.mcteam.gson.JsonParseException;
 | 
			
		||||
 | 
			
		||||
public class Conf {
 | 
			
		||||
	public static transient File file = new File(Factions.instance.getDataFolder(), "conf.json");
 | 
			
		||||
@@ -96,7 +97,7 @@ public class Conf {
 | 
			
		||||
		
 | 
			
		||||
		try {
 | 
			
		||||
			DiscUtil.write(file, Factions.gson.toJson(new Conf()));
 | 
			
		||||
		} catch (IOException e) {
 | 
			
		||||
		} catch (Exception e) {
 | 
			
		||||
			e.printStackTrace();
 | 
			
		||||
			Factions.log("Failed to save the config to disk.");
 | 
			
		||||
			return false;
 | 
			
		||||
@@ -115,7 +116,7 @@ public class Conf {
 | 
			
		||||
		
 | 
			
		||||
		try {
 | 
			
		||||
			Factions.gson.fromJson(DiscUtil.read(file), Conf.class);
 | 
			
		||||
		} catch (IOException e) {
 | 
			
		||||
		} catch (Exception e) {
 | 
			
		||||
			e.printStackTrace();
 | 
			
		||||
			Factions.log("Failed to load the config from disk.");
 | 
			
		||||
			return false;
 | 
			
		||||
 
 | 
			
		||||
@@ -460,9 +460,9 @@ public class FPlayer {
 | 
			
		||||
		
 | 
			
		||||
		try {
 | 
			
		||||
			DiscUtil.write(file, Factions.gson.toJson(playersToSave));
 | 
			
		||||
		} catch (IOException e) {
 | 
			
		||||
			Factions.log("Failed to save the players to disk.");
 | 
			
		||||
		} catch (Exception e) {
 | 
			
		||||
			e.printStackTrace();
 | 
			
		||||
			Factions.log("Failed to save the players to disk.");
 | 
			
		||||
			return false;
 | 
			
		||||
		}
 | 
			
		||||
		return true;
 | 
			
		||||
@@ -482,8 +482,9 @@ public class FPlayer {
 | 
			
		||||
			Map<String, FPlayer> instancesFromFile = Factions.gson.fromJson(DiscUtil.read(file), type);
 | 
			
		||||
			instances.clear();
 | 
			
		||||
			instances.putAll(instancesFromFile);
 | 
			
		||||
		} catch (IOException e) {
 | 
			
		||||
		} catch (Exception e) {
 | 
			
		||||
			e.printStackTrace();
 | 
			
		||||
			Factions.log("Failed to load the players from disk.");
 | 
			
		||||
			return false;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
 
 | 
			
		||||
@@ -332,12 +332,12 @@ public class Faction {
 | 
			
		||||
		try {
 | 
			
		||||
			DiscUtil.write(file, Factions.gson.toJson(instances));
 | 
			
		||||
		} catch (IOException e) {
 | 
			
		||||
			e.printStackTrace();
 | 
			
		||||
			Factions.log("Failed to save the factions to disk due to I/O exception.");
 | 
			
		||||
			e.printStackTrace();
 | 
			
		||||
			return false;
 | 
			
		||||
		} catch (NullPointerException e) {
 | 
			
		||||
			Factions.log("Failed to save the factions to disk due to NPE.");
 | 
			
		||||
		} catch (Exception e) {
 | 
			
		||||
			e.printStackTrace();
 | 
			
		||||
			Factions.log("Failed to save the factions to disk.");
 | 
			
		||||
			return false;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
@@ -358,8 +358,9 @@ public class Faction {
 | 
			
		||||
			Map<Integer, Faction> instancesFromFile = Factions.gson.fromJson(DiscUtil.read(file), type);
 | 
			
		||||
			instances.clear();
 | 
			
		||||
			instances.putAll(instancesFromFile);
 | 
			
		||||
		} catch (IOException e) {
 | 
			
		||||
		} catch (Exception e) {
 | 
			
		||||
			e.printStackTrace();
 | 
			
		||||
			Factions.log("Failed to load the factions from disk.");
 | 
			
		||||
			return false;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
 
 | 
			
		||||
@@ -27,7 +27,13 @@ public class MyLocationTypeAdapter implements JsonDeserializer<Location>, JsonSe
 | 
			
		||||
		try {
 | 
			
		||||
			JsonObject obj = json.getAsJsonObject();
 | 
			
		||||
 | 
			
		||||
			World world = Factions.instance.getServer().getWorld(obj.get(WORLD).getAsString());
 | 
			
		||||
			String worldname = obj.get(WORLD).getAsString();
 | 
			
		||||
			World world = Factions.instance.getServer().getWorld(worldname);
 | 
			
		||||
			if (world == null) {
 | 
			
		||||
				Factions.log(Level.WARNING, "Stored location's world \"" + worldname + "\" not found on server; dropping the location.");
 | 
			
		||||
				return null;
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			double x = obj.get(X).getAsDouble();
 | 
			
		||||
			double y = obj.get(Y).getAsDouble();
 | 
			
		||||
			double z = obj.get(Z).getAsDouble();
 | 
			
		||||
@@ -36,8 +42,9 @@ public class MyLocationTypeAdapter implements JsonDeserializer<Location>, JsonSe
 | 
			
		||||
 | 
			
		||||
			return new Location(world, x, y, z, yaw, pitch);
 | 
			
		||||
 | 
			
		||||
		} catch (NullPointerException ex) {
 | 
			
		||||
			Factions.log(Level.SEVERE, "NPE encountered while deserializing a location");
 | 
			
		||||
		} catch (Exception ex) {
 | 
			
		||||
			ex.printStackTrace();
 | 
			
		||||
			Factions.log(Level.WARNING, "Error encountered while deserializing a location.");
 | 
			
		||||
			return null;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
@@ -47,14 +54,9 @@ public class MyLocationTypeAdapter implements JsonDeserializer<Location>, JsonSe
 | 
			
		||||
		JsonObject obj = new JsonObject();
 | 
			
		||||
 | 
			
		||||
		try {
 | 
			
		||||
			if (src == null)
 | 
			
		||||
			if (src.getWorld() == null)
 | 
			
		||||
			{
 | 
			
		||||
				Factions.log("Passed location is null in MyLocationTypeAdapter.");
 | 
			
		||||
				return obj;
 | 
			
		||||
			}
 | 
			
		||||
			else if (src.getWorld() == null)
 | 
			
		||||
			{
 | 
			
		||||
				Factions.log("Passed location's world is null in MyLocationTypeAdapter.");
 | 
			
		||||
				Factions.log(Level.WARNING, "Passed location's world was not found on the server. Dropping the location.");
 | 
			
		||||
				return obj;
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
@@ -67,8 +69,9 @@ public class MyLocationTypeAdapter implements JsonDeserializer<Location>, JsonSe
 | 
			
		||||
 | 
			
		||||
			return obj;
 | 
			
		||||
 | 
			
		||||
		} catch (NullPointerException ex) {
 | 
			
		||||
			Factions.log(Level.SEVERE, "NPE encountered while serializing a location");
 | 
			
		||||
		} catch (Exception ex) {
 | 
			
		||||
			ex.printStackTrace();
 | 
			
		||||
			Factions.log(Level.WARNING, "Error encountered while serializing a location.");
 | 
			
		||||
			return obj;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user