Updated readme, Fixed admin bypass command and corresponding permissions, Swapped colors for ally and truce, added new faction permissions, improved explosion protection and implemented firespread protection, fixed painbuild check order, flags can only be changed by server admins now and implemented type adapters for some enumerations for future changes to be non breaking. That it \:D /
This commit is contained in:
18
src/com/massivecraft/factions/adapters/FFlagTypeAdapter.java
Normal file
18
src/com/massivecraft/factions/adapters/FFlagTypeAdapter.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package com.massivecraft.factions.adapters;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.massivecraft.factions.struct.FFlag;
|
||||
|
||||
public class FFlagTypeAdapter implements JsonDeserializer<FFlag>
|
||||
{
|
||||
@Override
|
||||
public FFlag deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
|
||||
{
|
||||
return FFlag.parse(json.getAsString());
|
||||
}
|
||||
}
|
@@ -0,0 +1,129 @@
|
||||
package com.massivecraft.factions.adapters;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
import com.massivecraft.factions.FLocation;
|
||||
import com.massivecraft.factions.P;
|
||||
|
||||
|
||||
// TODO: Is this one even used anymore??
|
||||
public class FLocToStringSetTypeAdapter implements JsonDeserializer<Map<FLocation, Set<String>>>, JsonSerializer<Map<FLocation, Set<String>>>
|
||||
{
|
||||
|
||||
@Override
|
||||
public Map<FLocation, Set<String>> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
|
||||
{
|
||||
try {
|
||||
JsonObject obj = json.getAsJsonObject();
|
||||
if (obj == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Map<FLocation, Set<String>> locationMap = new ConcurrentHashMap<FLocation, Set<String>>();
|
||||
Set<String> nameSet;
|
||||
Iterator<JsonElement> iter;
|
||||
String worldName;
|
||||
String[] coords;
|
||||
int x, z;
|
||||
|
||||
for (Entry<String, JsonElement> entry : obj.entrySet())
|
||||
{
|
||||
worldName = entry.getKey();
|
||||
for (Entry<String, JsonElement> entry2 : entry.getValue().getAsJsonObject().entrySet())
|
||||
{
|
||||
coords = entry2.getKey().trim().split("[,\\s]+");
|
||||
x = Integer.parseInt(coords[0]);
|
||||
z = Integer.parseInt(coords[1]);
|
||||
|
||||
nameSet = new HashSet<String>();
|
||||
iter = entry2.getValue().getAsJsonArray().iterator();
|
||||
while (iter.hasNext())
|
||||
{
|
||||
nameSet.add(iter.next().getAsString());
|
||||
}
|
||||
|
||||
locationMap.put(new FLocation(worldName, x, z), nameSet);
|
||||
}
|
||||
}
|
||||
|
||||
return locationMap;
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ex.printStackTrace();
|
||||
P.p.log(Level.WARNING, "Error encountered while deserializing a Map of FLocations to String Sets.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(Map<FLocation, Set<String>> src, Type typeOfSrc, JsonSerializationContext context)
|
||||
{
|
||||
JsonObject obj = new JsonObject();
|
||||
|
||||
try {
|
||||
if (src != null)
|
||||
{
|
||||
FLocation loc;
|
||||
String locWorld;
|
||||
Set<String> nameSet;
|
||||
Iterator<String> iter;
|
||||
JsonArray nameArray;
|
||||
JsonPrimitive nameElement;
|
||||
|
||||
for (Entry<FLocation, Set<String>> entry : src.entrySet())
|
||||
{
|
||||
loc = entry.getKey();
|
||||
locWorld = loc.getWorldName();
|
||||
nameSet = entry.getValue();
|
||||
|
||||
if (nameSet == null || nameSet.isEmpty())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
nameArray = new JsonArray();
|
||||
iter = nameSet.iterator();
|
||||
while (iter.hasNext())
|
||||
{
|
||||
nameElement = new JsonPrimitive(iter.next());
|
||||
nameArray.add(nameElement);
|
||||
}
|
||||
|
||||
if ( ! obj.has(locWorld))
|
||||
{
|
||||
obj.add(locWorld, new JsonObject());
|
||||
}
|
||||
|
||||
obj.get(locWorld).getAsJsonObject().add(loc.getCoordString(), nameArray);
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ex.printStackTrace();
|
||||
P.p.log(Level.WARNING, "Error encountered while serializing a Map of FLocations to String Sets.");
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
}
|
18
src/com/massivecraft/factions/adapters/FPermTypeAdapter.java
Normal file
18
src/com/massivecraft/factions/adapters/FPermTypeAdapter.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package com.massivecraft.factions.adapters;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.massivecraft.factions.struct.FPerm;
|
||||
|
||||
public class FPermTypeAdapter implements JsonDeserializer<FPerm>
|
||||
{
|
||||
@Override
|
||||
public FPerm deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
|
||||
{
|
||||
return FPerm.parse(json.getAsString());
|
||||
}
|
||||
}
|
@@ -0,0 +1,88 @@
|
||||
package com.massivecraft.factions.adapters;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
import com.massivecraft.factions.P;
|
||||
|
||||
|
||||
public class LocationTypeAdapter implements JsonDeserializer<Location>, JsonSerializer<Location>
|
||||
{
|
||||
private static final String WORLD = "world";
|
||||
private static final String X = "x";
|
||||
private static final String Y = "y";
|
||||
private static final String Z = "z";
|
||||
private static final String YAW = "yaw";
|
||||
private static final String PITCH = "pitch";
|
||||
|
||||
@Override
|
||||
public Location deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
|
||||
{
|
||||
try
|
||||
{
|
||||
JsonObject obj = json.getAsJsonObject();
|
||||
|
||||
String worldname = obj.get(WORLD).getAsString();
|
||||
World world = P.p.getServer().getWorld(worldname);
|
||||
if (world == null) {
|
||||
P.p.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();
|
||||
float yaw = obj.get(YAW).getAsFloat();
|
||||
float pitch = obj.get(PITCH).getAsFloat();
|
||||
|
||||
return new Location(world, x, y, z, yaw, pitch);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ex.printStackTrace();
|
||||
P.p.log(Level.WARNING, "Error encountered while deserializing a location.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(Location src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
JsonObject obj = new JsonObject();
|
||||
|
||||
try
|
||||
{
|
||||
if (src.getWorld() == null)
|
||||
{
|
||||
P.p.log(Level.WARNING, "Passed location's world was not found on the server. Dropping the location.");
|
||||
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 (Exception ex)
|
||||
{
|
||||
ex.printStackTrace();
|
||||
P.p.log(Level.WARNING, "Error encountered while serializing a location.");
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
}
|
18
src/com/massivecraft/factions/adapters/RelTypeAdapter.java
Normal file
18
src/com/massivecraft/factions/adapters/RelTypeAdapter.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package com.massivecraft.factions.adapters;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.massivecraft.factions.struct.Rel;
|
||||
|
||||
public class RelTypeAdapter implements JsonDeserializer<Rel>
|
||||
{
|
||||
@Override
|
||||
public Rel deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
|
||||
{
|
||||
return Rel.parse(json.getAsString());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user