Add in exception catching to MyLocationTypeAdapter, seems to finally be handling all problems without crash
Added 1.1.5b release with this fix
This commit is contained in:
parent
204f67c43b
commit
12bc5d9d74
BIN
releases/factions 1.1.5b.zip
Normal file
BIN
releases/factions 1.1.5b.zip
Normal file
Binary file not shown.
@ -1,6 +1,7 @@
|
|||||||
package com.bukkit.mcteam.factions;
|
package com.bukkit.mcteam.factions;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@ -23,11 +24,9 @@ public class MyLocationTypeAdapter implements JsonDeserializer<Location>, JsonSe
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Location deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
public Location deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||||
|
try {
|
||||||
JsonObject obj = json.getAsJsonObject();
|
JsonObject obj = json.getAsJsonObject();
|
||||||
|
|
||||||
if (obj.isJsonNull() || obj.get(WORLD).isJsonNull())
|
|
||||||
return null;
|
|
||||||
|
|
||||||
World world = Factions.instance.getServer().getWorld(obj.get(WORLD).getAsString());
|
World world = Factions.instance.getServer().getWorld(obj.get(WORLD).getAsString());
|
||||||
double x = obj.get(X).getAsDouble();
|
double x = obj.get(X).getAsDouble();
|
||||||
double y = obj.get(Y).getAsDouble();
|
double y = obj.get(Y).getAsDouble();
|
||||||
@ -36,12 +35,18 @@ public class MyLocationTypeAdapter implements JsonDeserializer<Location>, JsonSe
|
|||||||
float pitch = obj.get(PITCH).getAsFloat();
|
float pitch = obj.get(PITCH).getAsFloat();
|
||||||
|
|
||||||
return new Location(world, x, y, z, yaw, pitch);
|
return new Location(world, x, y, z, yaw, pitch);
|
||||||
|
|
||||||
|
} catch (NullPointerException ex) {
|
||||||
|
Factions.log(Level.SEVERE, "NPE encountered while deserializing a location");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JsonElement serialize(Location src, Type typeOfSrc, JsonSerializationContext context) {
|
public JsonElement serialize(Location src, Type typeOfSrc, JsonSerializationContext context) {
|
||||||
JsonObject obj = new JsonObject();
|
JsonObject obj = new JsonObject();
|
||||||
|
|
||||||
|
try {
|
||||||
if (src == null)
|
if (src == null)
|
||||||
{
|
{
|
||||||
Factions.log("Passed location is null in MyLocationTypeAdapter.");
|
Factions.log("Passed location is null in MyLocationTypeAdapter.");
|
||||||
@ -61,5 +66,10 @@ public class MyLocationTypeAdapter implements JsonDeserializer<Location>, JsonSe
|
|||||||
obj.addProperty(PITCH, src.getPitch());
|
obj.addProperty(PITCH, src.getPitch());
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
|
|
||||||
|
} catch (NullPointerException ex) {
|
||||||
|
Factions.log(Level.SEVERE, "NPE encountered while serializing a location");
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user