Faction admins can now mark already claimed areas as owned by specific faction members. Ownership can include multiple members. New command /f owner *[player name], to set/remove ownership. This command is only available to the faction admin and optionally the faction moderators. If no player name is specified, it will either set ownership to the player running the command (if no owner is currently set) or completely clear ownership of the territory. New command /f ownerlist, to view a list of owners for the current area. Only works inside your own faction's territory. New conf.json options "ownedAreasEnabled", "ownedAreasModeratorsCanSet", "ownedAreaModeratorsBypass", "ownedAreaDenyBuild", "ownedAreaProtectMaterials", and "ownedAreaDenyUseage" (all defaulting to true) to determine whether faction moderators can set or bypass ownership (faction admin always can), and what sort of protection these owned areas have against normal members of the faction (members other than the owner(s), faction admin, and probably faction moderators). New conf.json option "ownedAreasLimitPerFaction" to limit how many owned areas can be set. New permission node "factions.ownershipBypass" which allows a player to bypass ownership protection, but only within the person's own faction.

various little tweaks and improvements to other code
moderate speed boost to FLocation code
made commandDisable permissions work for any command alias of a command, instead of just the first one
This commit is contained in:
Brettflan
2011-07-30 20:17:00 -05:00
parent 63ab41f933
commit 508f953ce9
16 changed files with 643 additions and 49 deletions

View File

@ -0,0 +1,112 @@
package com.massivecraft.factions.util;
import java.lang.reflect.Type;
import java.util.HashMap;
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.Factions;
public class MapFLocToStringSetTypeAdapter 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 HashMap<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();
Factions.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();
Factions.log(Level.WARNING, "Error encountered while serializing a Map of FLocations to String Sets.");
return obj;
}
}
}

View File

@ -0,0 +1,80 @@
package com.massivecraft.factions.util;
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.Factions;
public class MyLocationTypeAdapter 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 = 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();
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();
Factions.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)
{
Factions.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();
Factions.log(Level.WARNING, "Error encountered while serializing a location.");
return obj;
}
}
}