Factions/src/com/massivecraft/factions/TerritoryAccess.java

217 lines
5.4 KiB
Java
Raw Normal View History

package com.massivecraft.factions;
New "access" system to replace old ownership system. Access can be granted to build, destroy, and fully interact within any chunk for specific players or factions. Access can also optionally be denied to normal members of the host faction. Some further info display to go with this feature is yet to come, and further testing for possible bugs is also needed. Related info: New FPerm "ACCESS" which is granted to faction leaders and officers by default. This FPerm allows you to bypass access restrictions throughout your faction territory, and (along with the "factions.access" Bukkit permission below) allows you to change access settings for any chunk owned by your faction. New permissions: factions.access - Ability to grant territory access for your faction, if you have the proper "ACCESS" FPerm (defaults to leaders and officers only). Added to factions.kit.halfplayer permission kit. factions.access.any - Ability to grant territory access for any faction on the server. Added to factions.kit.mod permission kit. factions.access.view - Ability to view territory access info for your own faction. Added to factions.kit.halfplayer permission kit. New command: /f access [view|p|f|player|faction=view] [name=you] - view or change the access information for the chunk you are in. If "view" or nothing is specified, it will simply display the info. If "p" or "player" is specified, a player will be granted access, or removed from the list if they were already granted access. If "f" or "faction" is specified, the same will be done for the specified faction. The name defaults to yourself or your faction if not specified. If your own faction is specified, you will toggle restricted access for the chunk so that normal faction members can be denied access, unless they are in the access list. Examples: /f access - view access list, if in your own territory /f access p SomePlayer - grant access to player "SomePlayer" for the current chunk, or remove them from the access list if already there /f access f - toggle restricted access for the current chunk (since faction name isn't specified, uses your own faction), assuming you're in your own factions territory
2012-05-15 04:41:13 +02:00
import java.util.LinkedHashSet;
import java.util.Set;
import org.bukkit.entity.Player;
public class TerritoryAccess
New "access" system to replace old ownership system. Access can be granted to build, destroy, and fully interact within any chunk for specific players or factions. Access can also optionally be denied to normal members of the host faction. Some further info display to go with this feature is yet to come, and further testing for possible bugs is also needed. Related info: New FPerm "ACCESS" which is granted to faction leaders and officers by default. This FPerm allows you to bypass access restrictions throughout your faction territory, and (along with the "factions.access" Bukkit permission below) allows you to change access settings for any chunk owned by your faction. New permissions: factions.access - Ability to grant territory access for your faction, if you have the proper "ACCESS" FPerm (defaults to leaders and officers only). Added to factions.kit.halfplayer permission kit. factions.access.any - Ability to grant territory access for any faction on the server. Added to factions.kit.mod permission kit. factions.access.view - Ability to view territory access info for your own faction. Added to factions.kit.halfplayer permission kit. New command: /f access [view|p|f|player|faction=view] [name=you] - view or change the access information for the chunk you are in. If "view" or nothing is specified, it will simply display the info. If "p" or "player" is specified, a player will be granted access, or removed from the list if they were already granted access. If "f" or "faction" is specified, the same will be done for the specified faction. The name defaults to yourself or your faction if not specified. If your own faction is specified, you will toggle restricted access for the chunk so that normal faction members can be denied access, unless they are in the access list. Examples: /f access - view access list, if in your own territory /f access p SomePlayer - grant access to player "SomePlayer" for the current chunk, or remove them from the access list if already there /f access f - toggle restricted access for the current chunk (since faction name isn't specified, uses your own faction), assuming you're in your own factions territory
2012-05-15 04:41:13 +02:00
{
protected String hostFactionID;
protected boolean hostFactionAllowed = true;
protected Set<String> factionIDs = new LinkedHashSet<String>();
protected Set<String> fplayerIDs = new LinkedHashSet<String>();
New "access" system to replace old ownership system. Access can be granted to build, destroy, and fully interact within any chunk for specific players or factions. Access can also optionally be denied to normal members of the host faction. Some further info display to go with this feature is yet to come, and further testing for possible bugs is also needed. Related info: New FPerm "ACCESS" which is granted to faction leaders and officers by default. This FPerm allows you to bypass access restrictions throughout your faction territory, and (along with the "factions.access" Bukkit permission below) allows you to change access settings for any chunk owned by your faction. New permissions: factions.access - Ability to grant territory access for your faction, if you have the proper "ACCESS" FPerm (defaults to leaders and officers only). Added to factions.kit.halfplayer permission kit. factions.access.any - Ability to grant territory access for any faction on the server. Added to factions.kit.mod permission kit. factions.access.view - Ability to view territory access info for your own faction. Added to factions.kit.halfplayer permission kit. New command: /f access [view|p|f|player|faction=view] [name=you] - view or change the access information for the chunk you are in. If "view" or nothing is specified, it will simply display the info. If "p" or "player" is specified, a player will be granted access, or removed from the list if they were already granted access. If "f" or "faction" is specified, the same will be done for the specified faction. The name defaults to yourself or your faction if not specified. If your own faction is specified, you will toggle restricted access for the chunk so that normal faction members can be denied access, unless they are in the access list. Examples: /f access - view access list, if in your own territory /f access p SomePlayer - grant access to player "SomePlayer" for the current chunk, or remove them from the access list if already there /f access f - toggle restricted access for the current chunk (since faction name isn't specified, uses your own faction), assuming you're in your own factions territory
2012-05-15 04:41:13 +02:00
public TerritoryAccess(String factionID)
{
hostFactionID = factionID;
}
public TerritoryAccess() {}
public void setHostFactionID(String factionID)
{
hostFactionID = factionID;
hostFactionAllowed = true;
factionIDs.clear();
fplayerIDs.clear();
}
public String getHostFactionID()
{
return hostFactionID;
}
public Faction getHostFaction()
{
2013-04-09 12:58:39 +02:00
return FactionColl.i.get(hostFactionID);
New "access" system to replace old ownership system. Access can be granted to build, destroy, and fully interact within any chunk for specific players or factions. Access can also optionally be denied to normal members of the host faction. Some further info display to go with this feature is yet to come, and further testing for possible bugs is also needed. Related info: New FPerm "ACCESS" which is granted to faction leaders and officers by default. This FPerm allows you to bypass access restrictions throughout your faction territory, and (along with the "factions.access" Bukkit permission below) allows you to change access settings for any chunk owned by your faction. New permissions: factions.access - Ability to grant territory access for your faction, if you have the proper "ACCESS" FPerm (defaults to leaders and officers only). Added to factions.kit.halfplayer permission kit. factions.access.any - Ability to grant territory access for any faction on the server. Added to factions.kit.mod permission kit. factions.access.view - Ability to view territory access info for your own faction. Added to factions.kit.halfplayer permission kit. New command: /f access [view|p|f|player|faction=view] [name=you] - view or change the access information for the chunk you are in. If "view" or nothing is specified, it will simply display the info. If "p" or "player" is specified, a player will be granted access, or removed from the list if they were already granted access. If "f" or "faction" is specified, the same will be done for the specified faction. The name defaults to yourself or your faction if not specified. If your own faction is specified, you will toggle restricted access for the chunk so that normal faction members can be denied access, unless they are in the access list. Examples: /f access - view access list, if in your own territory /f access p SomePlayer - grant access to player "SomePlayer" for the current chunk, or remove them from the access list if already there /f access f - toggle restricted access for the current chunk (since faction name isn't specified, uses your own faction), assuming you're in your own factions territory
2012-05-15 04:41:13 +02:00
}
// considered "default" if host faction is still allowed and nobody has been granted access
public boolean isDefault()
{
return this.hostFactionAllowed && factionIDs.isEmpty() && fplayerIDs.isEmpty();
}
public boolean isHostFactionAllowed()
{
return this.hostFactionAllowed;
}
public void setHostFactionAllowed(boolean allowed)
{
this.hostFactionAllowed = allowed;
}
public boolean doesHostFactionMatch(Object testSubject)
{
if (testSubject instanceof String)
return hostFactionID.equals((String)testSubject);
else if (testSubject instanceof Player)
2013-04-09 13:22:23 +02:00
return hostFactionID.equals(FPlayerColl.i.get((Player)testSubject).getFactionId());
New "access" system to replace old ownership system. Access can be granted to build, destroy, and fully interact within any chunk for specific players or factions. Access can also optionally be denied to normal members of the host faction. Some further info display to go with this feature is yet to come, and further testing for possible bugs is also needed. Related info: New FPerm "ACCESS" which is granted to faction leaders and officers by default. This FPerm allows you to bypass access restrictions throughout your faction territory, and (along with the "factions.access" Bukkit permission below) allows you to change access settings for any chunk owned by your faction. New permissions: factions.access - Ability to grant territory access for your faction, if you have the proper "ACCESS" FPerm (defaults to leaders and officers only). Added to factions.kit.halfplayer permission kit. factions.access.any - Ability to grant territory access for any faction on the server. Added to factions.kit.mod permission kit. factions.access.view - Ability to view territory access info for your own faction. Added to factions.kit.halfplayer permission kit. New command: /f access [view|p|f|player|faction=view] [name=you] - view or change the access information for the chunk you are in. If "view" or nothing is specified, it will simply display the info. If "p" or "player" is specified, a player will be granted access, or removed from the list if they were already granted access. If "f" or "faction" is specified, the same will be done for the specified faction. The name defaults to yourself or your faction if not specified. If your own faction is specified, you will toggle restricted access for the chunk so that normal faction members can be denied access, unless they are in the access list. Examples: /f access - view access list, if in your own territory /f access p SomePlayer - grant access to player "SomePlayer" for the current chunk, or remove them from the access list if already there /f access f - toggle restricted access for the current chunk (since faction name isn't specified, uses your own faction), assuming you're in your own factions territory
2012-05-15 04:41:13 +02:00
else if (testSubject instanceof FPlayer)
return hostFactionID.equals(((FPlayer)testSubject).getFactionId());
else if (testSubject instanceof Faction)
return hostFactionID.equals(((Faction)testSubject).getId());
return false;
}
public void addFaction(String factionID)
{
factionIDs.add(factionID);
}
public void addFaction(Faction faction)
{
addFaction(faction.getId());
}
public void addFPlayer(String fplayerID)
{
fplayerIDs.add(fplayerID);
}
public void addFPlayer(FPlayer fplayer)
{
addFPlayer(fplayer.getId());
}
public void removeFaction(String factionID)
{
factionIDs.remove(factionID);
}
public void removeFaction(Faction faction)
{
removeFaction(faction.getId());
}
public void removeFPlayer(String fplayerID)
{
fplayerIDs.remove(fplayerID);
}
public void removeFPlayer(FPlayer fplayer)
{
removeFPlayer(fplayer.getId());
}
// return true if faction was added, false if it was removed
public boolean toggleFaction(String factionID)
{
// if the host faction, special handling
if (doesHostFactionMatch(factionID))
{
hostFactionAllowed ^= true;
return hostFactionAllowed;
}
if (factionIDs.contains(factionID))
{
removeFaction(factionID);
return false;
}
addFaction(factionID);
return true;
}
public boolean toggleFaction(Faction faction)
{
return toggleFaction(faction.getId());
}
public boolean toggleFPlayer(String fplayerID)
{
if (fplayerIDs.contains(fplayerID))
{
removeFPlayer(fplayerID);
return false;
}
addFPlayer(fplayerID);
return true;
}
public boolean toggleFPlayer(FPlayer fplayer)
{
return toggleFPlayer(fplayer.getId());
}
public String factionList()
{
StringBuilder list = new StringBuilder();
for (String factionID : factionIDs)
{
if (list.length() > 0)
list.append(", ");
2013-04-09 12:58:39 +02:00
list.append(FactionColl.i.get(factionID).getTag());
New "access" system to replace old ownership system. Access can be granted to build, destroy, and fully interact within any chunk for specific players or factions. Access can also optionally be denied to normal members of the host faction. Some further info display to go with this feature is yet to come, and further testing for possible bugs is also needed. Related info: New FPerm "ACCESS" which is granted to faction leaders and officers by default. This FPerm allows you to bypass access restrictions throughout your faction territory, and (along with the "factions.access" Bukkit permission below) allows you to change access settings for any chunk owned by your faction. New permissions: factions.access - Ability to grant territory access for your faction, if you have the proper "ACCESS" FPerm (defaults to leaders and officers only). Added to factions.kit.halfplayer permission kit. factions.access.any - Ability to grant territory access for any faction on the server. Added to factions.kit.mod permission kit. factions.access.view - Ability to view territory access info for your own faction. Added to factions.kit.halfplayer permission kit. New command: /f access [view|p|f|player|faction=view] [name=you] - view or change the access information for the chunk you are in. If "view" or nothing is specified, it will simply display the info. If "p" or "player" is specified, a player will be granted access, or removed from the list if they were already granted access. If "f" or "faction" is specified, the same will be done for the specified faction. The name defaults to yourself or your faction if not specified. If your own faction is specified, you will toggle restricted access for the chunk so that normal faction members can be denied access, unless they are in the access list. Examples: /f access - view access list, if in your own territory /f access p SomePlayer - grant access to player "SomePlayer" for the current chunk, or remove them from the access list if already there /f access f - toggle restricted access for the current chunk (since faction name isn't specified, uses your own faction), assuming you're in your own factions territory
2012-05-15 04:41:13 +02:00
}
return list.toString();
}
public String fplayerList()
{
StringBuilder list = new StringBuilder();
for (String fplayerID : fplayerIDs)
{
if (list.length() > 0)
list.append(", ");
list.append(fplayerID);
}
return list.toString();
}
// these return false if not granted explicit access, or true if granted explicit access (in FPlayer or Faction lists)
// they do not take into account hostFactionAllowed, which will need to be checked separately (as to not override FPerms which are denied for faction members and such)
public boolean subjectHasAccess(Object testSubject)
{
if (testSubject instanceof Player)
2013-04-09 13:22:23 +02:00
return fPlayerHasAccess(FPlayerColl.i.get((Player)testSubject));
New "access" system to replace old ownership system. Access can be granted to build, destroy, and fully interact within any chunk for specific players or factions. Access can also optionally be denied to normal members of the host faction. Some further info display to go with this feature is yet to come, and further testing for possible bugs is also needed. Related info: New FPerm "ACCESS" which is granted to faction leaders and officers by default. This FPerm allows you to bypass access restrictions throughout your faction territory, and (along with the "factions.access" Bukkit permission below) allows you to change access settings for any chunk owned by your faction. New permissions: factions.access - Ability to grant territory access for your faction, if you have the proper "ACCESS" FPerm (defaults to leaders and officers only). Added to factions.kit.halfplayer permission kit. factions.access.any - Ability to grant territory access for any faction on the server. Added to factions.kit.mod permission kit. factions.access.view - Ability to view territory access info for your own faction. Added to factions.kit.halfplayer permission kit. New command: /f access [view|p|f|player|faction=view] [name=you] - view or change the access information for the chunk you are in. If "view" or nothing is specified, it will simply display the info. If "p" or "player" is specified, a player will be granted access, or removed from the list if they were already granted access. If "f" or "faction" is specified, the same will be done for the specified faction. The name defaults to yourself or your faction if not specified. If your own faction is specified, you will toggle restricted access for the chunk so that normal faction members can be denied access, unless they are in the access list. Examples: /f access - view access list, if in your own territory /f access p SomePlayer - grant access to player "SomePlayer" for the current chunk, or remove them from the access list if already there /f access f - toggle restricted access for the current chunk (since faction name isn't specified, uses your own faction), assuming you're in your own factions territory
2012-05-15 04:41:13 +02:00
else if (testSubject instanceof FPlayer)
return fPlayerHasAccess((FPlayer)testSubject);
else if (testSubject instanceof Faction)
return factionHasAccess((Faction)testSubject);
return false;
}
public boolean fPlayerHasAccess(FPlayer fplayer)
{
if (factionHasAccess(fplayer.getFactionId())) return true;
return fplayerIDs.contains(fplayer.getId());
}
public boolean factionHasAccess(Faction faction)
{
return factionHasAccess(faction.getId());
}
public boolean factionHasAccess(String factionID)
{
return factionIDs.contains(factionID);
}
// this should normally only be checked after running subjectHasAccess() or fPlayerHasAccess() above to see if they have access explicitly granted
public boolean subjectAccessIsRestricted(Object testSubject)
{
return ( ! this.isHostFactionAllowed() && this.doesHostFactionMatch(testSubject) && ! FPerm.ACCESS.has(testSubject, this.getHostFaction()));
}
New "access" system to replace old ownership system. Access can be granted to build, destroy, and fully interact within any chunk for specific players or factions. Access can also optionally be denied to normal members of the host faction. Some further info display to go with this feature is yet to come, and further testing for possible bugs is also needed. Related info: New FPerm "ACCESS" which is granted to faction leaders and officers by default. This FPerm allows you to bypass access restrictions throughout your faction territory, and (along with the "factions.access" Bukkit permission below) allows you to change access settings for any chunk owned by your faction. New permissions: factions.access - Ability to grant territory access for your faction, if you have the proper "ACCESS" FPerm (defaults to leaders and officers only). Added to factions.kit.halfplayer permission kit. factions.access.any - Ability to grant territory access for any faction on the server. Added to factions.kit.mod permission kit. factions.access.view - Ability to view territory access info for your own faction. Added to factions.kit.halfplayer permission kit. New command: /f access [view|p|f|player|faction=view] [name=you] - view or change the access information for the chunk you are in. If "view" or nothing is specified, it will simply display the info. If "p" or "player" is specified, a player will be granted access, or removed from the list if they were already granted access. If "f" or "faction" is specified, the same will be done for the specified faction. The name defaults to yourself or your faction if not specified. If your own faction is specified, you will toggle restricted access for the chunk so that normal faction members can be denied access, unless they are in the access list. Examples: /f access - view access list, if in your own territory /f access p SomePlayer - grant access to player "SomePlayer" for the current chunk, or remove them from the access list if already there /f access f - toggle restricted access for the current chunk (since faction name isn't specified, uses your own faction), assuming you're in your own factions territory
2012-05-15 04:41:13 +02:00
//----------------------------------------------//
// COMPARISON
New "access" system to replace old ownership system. Access can be granted to build, destroy, and fully interact within any chunk for specific players or factions. Access can also optionally be denied to normal members of the host faction. Some further info display to go with this feature is yet to come, and further testing for possible bugs is also needed. Related info: New FPerm "ACCESS" which is granted to faction leaders and officers by default. This FPerm allows you to bypass access restrictions throughout your faction territory, and (along with the "factions.access" Bukkit permission below) allows you to change access settings for any chunk owned by your faction. New permissions: factions.access - Ability to grant territory access for your faction, if you have the proper "ACCESS" FPerm (defaults to leaders and officers only). Added to factions.kit.halfplayer permission kit. factions.access.any - Ability to grant territory access for any faction on the server. Added to factions.kit.mod permission kit. factions.access.view - Ability to view territory access info for your own faction. Added to factions.kit.halfplayer permission kit. New command: /f access [view|p|f|player|faction=view] [name=you] - view or change the access information for the chunk you are in. If "view" or nothing is specified, it will simply display the info. If "p" or "player" is specified, a player will be granted access, or removed from the list if they were already granted access. If "f" or "faction" is specified, the same will be done for the specified faction. The name defaults to yourself or your faction if not specified. If your own faction is specified, you will toggle restricted access for the chunk so that normal faction members can be denied access, unless they are in the access list. Examples: /f access - view access list, if in your own territory /f access p SomePlayer - grant access to player "SomePlayer" for the current chunk, or remove them from the access list if already there /f access f - toggle restricted access for the current chunk (since faction name isn't specified, uses your own faction), assuming you're in your own factions territory
2012-05-15 04:41:13 +02:00
//----------------------------------------------//
@Override
public int hashCode()
{
return this.hostFactionID.hashCode();
}
@Override
public boolean equals(Object obj)
{
if (obj == this) return true;
if (!(obj instanceof TerritoryAccess)) return false;
New "access" system to replace old ownership system. Access can be granted to build, destroy, and fully interact within any chunk for specific players or factions. Access can also optionally be denied to normal members of the host faction. Some further info display to go with this feature is yet to come, and further testing for possible bugs is also needed. Related info: New FPerm "ACCESS" which is granted to faction leaders and officers by default. This FPerm allows you to bypass access restrictions throughout your faction territory, and (along with the "factions.access" Bukkit permission below) allows you to change access settings for any chunk owned by your faction. New permissions: factions.access - Ability to grant territory access for your faction, if you have the proper "ACCESS" FPerm (defaults to leaders and officers only). Added to factions.kit.halfplayer permission kit. factions.access.any - Ability to grant territory access for any faction on the server. Added to factions.kit.mod permission kit. factions.access.view - Ability to view territory access info for your own faction. Added to factions.kit.halfplayer permission kit. New command: /f access [view|p|f|player|faction=view] [name=you] - view or change the access information for the chunk you are in. If "view" or nothing is specified, it will simply display the info. If "p" or "player" is specified, a player will be granted access, or removed from the list if they were already granted access. If "f" or "faction" is specified, the same will be done for the specified faction. The name defaults to yourself or your faction if not specified. If your own faction is specified, you will toggle restricted access for the chunk so that normal faction members can be denied access, unless they are in the access list. Examples: /f access - view access list, if in your own territory /f access p SomePlayer - grant access to player "SomePlayer" for the current chunk, or remove them from the access list if already there /f access f - toggle restricted access for the current chunk (since faction name isn't specified, uses your own faction), assuming you're in your own factions territory
2012-05-15 04:41:13 +02:00
TerritoryAccess that = (TerritoryAccess) obj;
return this.hostFactionID.equals(that.hostFactionID) && this.hostFactionAllowed == that.hostFactionAllowed && this.factionIDs == that.factionIDs && this.fplayerIDs == that.fplayerIDs;
}
}