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
This commit is contained in:
Brettflan
2012-05-14 21:41:13 -05:00
parent d2b0fee335
commit 58bec9d6dc
8 changed files with 534 additions and 46 deletions

View File

@@ -16,6 +16,7 @@ import org.bukkit.block.Block;
import com.google.gson.reflect.TypeToken;
import com.massivecraft.factions.integration.LWCFeatures;
import com.massivecraft.factions.iface.RelationParticipator;
import com.massivecraft.factions.struct.TerritoryAccess;
import com.massivecraft.factions.util.AsciiCompass;
import com.massivecraft.factions.zcore.util.DiscUtil;
@@ -23,21 +24,25 @@ import com.massivecraft.factions.zcore.util.DiscUtil;
public class Board
{
private static transient File file = new File(P.p.getDataFolder(), "board.json");
private static transient HashMap<FLocation, String> flocationIds = new HashMap<FLocation, String>();
private static transient HashMap<FLocation, TerritoryAccess> flocationIds = new HashMap<FLocation, TerritoryAccess>();
//----------------------------------------------//
// Get and Set
//----------------------------------------------//
public static String getIdAt(FLocation flocation)
{
if ( ! flocationIds.containsKey(flocation))
{
return "0";
}
if ( ! flocationIds.containsKey(flocation)) return "0";
return flocationIds.get(flocation).getHostFactionID();
}
public static TerritoryAccess getTerritoryAccessAt(FLocation flocation)
{
if ( ! flocationIds.containsKey(flocation))
flocationIds.put(flocation, new TerritoryAccess("0"));
return flocationIds.get(flocation);
}
public static Faction getFactionAt(FLocation flocation)
{
return Factions.i.get(getIdAt(flocation));
@@ -54,11 +59,9 @@ public class Board
public static void setIdAt(String id, FLocation flocation)
{
if (id == "0")
{
removeAt(flocation);
}
flocationIds.put(flocation, id);
flocationIds.put(flocation, new TerritoryAccess(id));
}
public static void setFactionAt(Faction faction, FLocation flocation)
@@ -76,11 +79,11 @@ public class Board
public static void unclaimAll(String factionId)
{
Iterator<Entry<FLocation, String>> iter = flocationIds.entrySet().iterator();
Iterator<Entry<FLocation, TerritoryAccess>> iter = flocationIds.entrySet().iterator();
while (iter.hasNext())
{
Entry<FLocation, String> entry = iter.next();
if (entry.getValue().equals(factionId))
Entry<FLocation, TerritoryAccess> entry = iter.next();
if (entry.getValue().getHostFactionID().equals(factionId))
{
if(Conf.onUnclaimResetLwcLocks && LWCFeatures.getEnabled())
LWCFeatures.clearAllChests(entry.getKey());
@@ -119,15 +122,15 @@ public class Board
public static void clean()
{
Iterator<Entry<FLocation, String>> iter = flocationIds.entrySet().iterator();
Iterator<Entry<FLocation, TerritoryAccess>> iter = flocationIds.entrySet().iterator();
while (iter.hasNext()) {
Entry<FLocation, String> entry = iter.next();
if ( ! Factions.i.exists(entry.getValue()))
Entry<FLocation, TerritoryAccess> entry = iter.next();
if ( ! Factions.i.exists(entry.getValue().getHostFactionID()))
{
if(Conf.onUnclaimResetLwcLocks && LWCFeatures.getEnabled())
LWCFeatures.clearAllChests(entry.getKey());
P.p.log("Board cleaner removed "+entry.getValue()+" from "+entry.getKey());
P.p.log("Board cleaner removed "+entry.getValue().getHostFactionID()+" from "+entry.getKey());
iter.remove();
}
}
@@ -140,9 +143,9 @@ public class Board
public static int getFactionCoordCount(String factionId)
{
int ret = 0;
for (String thatFactionId : flocationIds.values())
for (TerritoryAccess thatFactionId : flocationIds.values())
{
if(thatFactionId.equals(factionId))
if(thatFactionId.getHostFactionID().equals(factionId))
{
ret += 1;
}
@@ -159,10 +162,10 @@ public class Board
{
String factionId = faction.getId();
int ret = 0;
Iterator<Entry<FLocation, String>> iter = flocationIds.entrySet().iterator();
Iterator<Entry<FLocation, TerritoryAccess>> iter = flocationIds.entrySet().iterator();
while (iter.hasNext()) {
Entry<FLocation, String> entry = iter.next();
if (entry.getValue().equals(factionId) && entry.getKey().getWorldName().equals(worldName))
Entry<FLocation, TerritoryAccess> entry = iter.next();
if (entry.getValue().getHostFactionID().equals(factionId) && entry.getKey().getWorldName().equals(worldName))
{
ret += 1;
}
@@ -252,48 +255,48 @@ public class Board
// Persistance
// -------------------------------------------- //
public static Map<String,Map<String,String>> dumpAsSaveFormat()
public static Map<String,Map<String,TerritoryAccess>> dumpAsSaveFormat()
{
Map<String,Map<String,String>> worldCoordIds = new HashMap<String,Map<String,String>>();
Map<String,Map<String,TerritoryAccess>> worldCoordIds = new HashMap<String,Map<String,TerritoryAccess>>();
String worldName, coords;
String id;
TerritoryAccess data;
for (Entry<FLocation, String> entry : flocationIds.entrySet())
for (Entry<FLocation, TerritoryAccess> entry : flocationIds.entrySet())
{
worldName = entry.getKey().getWorldName();
coords = entry.getKey().getCoordString();
id = entry.getValue();
data = entry.getValue();
if ( ! worldCoordIds.containsKey(worldName))
{
worldCoordIds.put(worldName, new TreeMap<String,String>());
worldCoordIds.put(worldName, new TreeMap<String,TerritoryAccess>());
}
worldCoordIds.get(worldName).put(coords, id);
worldCoordIds.get(worldName).put(coords, data);
}
return worldCoordIds;
}
public static void loadFromSaveFormat(Map<String,Map<String,String>> worldCoordIds)
public static void loadFromSaveFormat(Map<String,Map<String,TerritoryAccess>> worldCoordIds)
{
flocationIds.clear();
String worldName;
String[] coords;
int x, z;
String factionId;
TerritoryAccess data;
for (Entry<String,Map<String,String>> entry : worldCoordIds.entrySet())
for (Entry<String,Map<String,TerritoryAccess>> entry : worldCoordIds.entrySet())
{
worldName = entry.getKey();
for (Entry<String,String> entry2 : entry.getValue().entrySet())
for (Entry<String,TerritoryAccess> entry2 : entry.getValue().entrySet())
{
coords = entry2.getKey().trim().split("[,\\s]+");
x = Integer.parseInt(coords[0]);
z = Integer.parseInt(coords[1]);
factionId = entry2.getValue();
flocationIds.put(new FLocation(worldName, x, z), factionId);
data = entry2.getValue();
flocationIds.put(new FLocation(worldName, x, z), data);
}
}
}
@@ -329,8 +332,8 @@ public class Board
try
{
Type type = new TypeToken<Map<String,Map<String,String>>>(){}.getType();
Map<String,Map<String,String>> worldCoordIds = P.p.gson.fromJson(DiscUtil.read(file), type);
Type type = new TypeToken<Map<String,Map<String,TerritoryAccess>>>(){}.getType();
Map<String,Map<String,TerritoryAccess>> worldCoordIds = P.p.gson.fromJson(DiscUtil.read(file), type);
loadFromSaveFormat(worldCoordIds);
}
catch (Exception e)