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

@@ -28,6 +28,7 @@ public class Faction {
private transient int id;
private Map<Integer, Relation> relationWish;
private Map<FLocation, Set<String>> claimOwnership;
private Set<String> invites; // Where string is a lowercase player name
private boolean open;
private String tag;
@@ -397,6 +398,152 @@ public class Faction {
return this.getRelation(fplayer).getColor();
}
//----------------------------------------------//
// Ownership of specific claims
//----------------------------------------------//
private boolean isClaimOwnershipEmpty() {
if (claimOwnership == null) {
claimOwnership = new HashMap<FLocation, Set<String>>();
return true;
}
return claimOwnership.isEmpty();
}
public void clearAllClaimOwnership() {
claimOwnership.clear();
}
public void clearClaimOwnership(FLocation loc) {
claimOwnership.remove(loc);
}
public void clearClaimOwnership(String playerName) {
if (playerName == null || playerName.isEmpty()) {
return;
}
isClaimOwnershipEmpty();
Set<String> ownerData;
String player = playerName.toLowerCase();
for (Entry<FLocation, Set<String>> entry : claimOwnership.entrySet()) {
ownerData = entry.getValue();
if (ownerData == null) {
continue;
}
Iterator<String> iter = ownerData.iterator();
while (iter.hasNext()) {
if (iter.next().equals(player)) {
iter.remove();
}
}
if (ownerData.isEmpty()) {
claimOwnership.remove(entry.getKey());
}
}
}
public int getCountOfClaimsWithOwners() {
return isClaimOwnershipEmpty() ? 0 : claimOwnership.size();
}
public boolean doesLocationHaveOwnersSet(FLocation loc) {
if (isClaimOwnershipEmpty() || !claimOwnership.containsKey(loc)) {
return false;
}
Set<String> ownerData = claimOwnership.get(loc);
return ownerData != null && !ownerData.isEmpty();
}
public boolean isPlayerInOwnerList(String playerName, FLocation loc) {
if (isClaimOwnershipEmpty()) {
return false;
}
Set<String> ownerData = claimOwnership.get(loc);
if (ownerData == null) {
return false;
}
if (ownerData.contains(playerName.toLowerCase())) {
return true;
}
return false;
}
public void setPlayerAsOwner(String playerName, FLocation loc) {
isClaimOwnershipEmpty();
Set<String> ownerData = claimOwnership.get(loc);
if (ownerData == null) {
ownerData = new HashSet<String>();
}
ownerData.add(playerName.toLowerCase());
claimOwnership.put(loc, ownerData);
}
public void removePlayerAsOwner(String playerName, FLocation loc) {
isClaimOwnershipEmpty();
Set<String> ownerData = claimOwnership.get(loc);
if (ownerData == null) {
return;
}
ownerData.remove(playerName.toLowerCase());
claimOwnership.put(loc, ownerData);
}
public Set<String> getOwnerList(FLocation loc) {
isClaimOwnershipEmpty();
return claimOwnership.get(loc);
}
public String getOwnerListString(FLocation loc) {
isClaimOwnershipEmpty();
Set<String> ownerData = claimOwnership.get(loc);
if (ownerData == null || ownerData.isEmpty()) {
return "";
}
String ownerList = "";
Iterator<String> iter = ownerData.iterator();
while (iter.hasNext()) {
if (!ownerList.isEmpty()) {
ownerList += ", ";
}
ownerList += iter.next();
}
return ownerList;
}
public boolean playerHasOwnershipRights(FPlayer fplayer, FLocation loc) {
// different faction?
if (fplayer.getFactionId() != id) {
return false;
}
// sufficient role to bypass ownership?
if (fplayer.getRole() == (Conf.ownedAreaModeratorsBypass ? Role.MODERATOR : Role.ADMIN)) {
return true;
}
// make sure claimOwnership is initialized
if (isClaimOwnershipEmpty()) {
return true;
}
// need to check the ownership list, then
Set<String> ownerData = claimOwnership.get(loc);
// if no owner list, owner list is empty, or player is in owner list, they're allowed
if (ownerData == null || ownerData.isEmpty() || ownerData.contains(fplayer.getName().toLowerCase())) {
return true;
}
return false;
}
//----------------------------------------------//