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