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;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
@ -23,43 +24,52 @@ public class MyLocationTypeAdapter implements JsonDeserializer<Location>, JsonSe
|
||||
|
||||
@Override
|
||||
public Location deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
JsonObject obj = json.getAsJsonObject();
|
||||
try {
|
||||
JsonObject obj = json.getAsJsonObject();
|
||||
|
||||
if (obj.isJsonNull() || obj.get(WORLD).isJsonNull())
|
||||
World world = Factions.instance.getServer().getWorld(obj.get(WORLD).getAsString());
|
||||
double x = obj.get(X).getAsDouble();
|
||||
double y = obj.get(Y).getAsDouble();
|
||||
double z = obj.get(Z).getAsDouble();
|
||||
float yaw = obj.get(YAW).getAsFloat();
|
||||
float pitch = obj.get(PITCH).getAsFloat();
|
||||
|
||||
return new Location(world, x, y, z, yaw, pitch);
|
||||
|
||||
} catch (NullPointerException ex) {
|
||||
Factions.log(Level.SEVERE, "NPE encountered while deserializing a location");
|
||||
return null;
|
||||
|
||||
World world = Factions.instance.getServer().getWorld(obj.get(WORLD).getAsString());
|
||||
double x = obj.get(X).getAsDouble();
|
||||
double y = obj.get(Y).getAsDouble();
|
||||
double z = obj.get(Z).getAsDouble();
|
||||
float yaw = obj.get(YAW).getAsFloat();
|
||||
float pitch = obj.get(PITCH).getAsFloat();
|
||||
|
||||
return new Location(world, x, y, z, yaw, pitch);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(Location src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
JsonObject obj = new JsonObject();
|
||||
|
||||
if (src == 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.");
|
||||
return obj;
|
||||
}
|
||||
try {
|
||||
if (src == 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.");
|
||||
return obj;
|
||||
}
|
||||
|
||||
obj.addProperty(WORLD, src.getWorld().getName());
|
||||
obj.addProperty(X, src.getX());
|
||||
obj.addProperty(Y, src.getY());
|
||||
obj.addProperty(Z, src.getZ());
|
||||
obj.addProperty(YAW, src.getYaw());
|
||||
obj.addProperty(PITCH, src.getPitch());
|
||||
|
||||
return obj;
|
||||
obj.addProperty(WORLD, src.getWorld().getName());
|
||||
obj.addProperty(X, src.getX());
|
||||
obj.addProperty(Y, src.getY());
|
||||
obj.addProperty(Z, src.getZ());
|
||||
obj.addProperty(YAW, src.getYaw());
|
||||
obj.addProperty(PITCH, src.getPitch());
|
||||
|
||||
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