From 9076e780cfb1688e875d94cda5235c33a5525cb9 Mon Sep 17 00:00:00 2001 From: drtshock Date: Sun, 26 Apr 2015 00:02:30 -0500 Subject: [PATCH] Add method to get all claims for a given faction. --- .../java/com/massivecraft/factions/Board.java | 5 +++ .../com/massivecraft/factions/Faction.java | 2 ++ .../factions/zcore/persist/MemoryBoard.java | 31 ++++++++++++++----- .../factions/zcore/persist/MemoryFaction.java | 4 +++ 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/Board.java b/src/main/java/com/massivecraft/factions/Board.java index 5f565bf9..1ae9fb17 100644 --- a/src/main/java/com/massivecraft/factions/Board.java +++ b/src/main/java/com/massivecraft/factions/Board.java @@ -3,6 +3,7 @@ package com.massivecraft.factions; import com.massivecraft.factions.zcore.persist.json.JSONBoard; import java.util.ArrayList; +import java.util.Set; public abstract class Board { @@ -33,6 +34,10 @@ public abstract class Board { public abstract void removeAt(FLocation flocation); + public abstract Set getAllClaims(String factionId); + + public abstract Set getAllClaims(Faction faction); + // not to be confused with claims, ownership referring to further member-specific ownership of a claim public abstract void clearOwnershipAt(FLocation flocation); diff --git a/src/main/java/com/massivecraft/factions/Faction.java b/src/main/java/com/massivecraft/factions/Faction.java index a0b8d041..1bae5742 100644 --- a/src/main/java/com/massivecraft/factions/Faction.java +++ b/src/main/java/com/massivecraft/factions/Faction.java @@ -232,5 +232,7 @@ public interface Faction extends EconomyParticipator { // ----------------------------------------------// public void remove(); + public Set getAllClaims(); + public void setId(String id); } diff --git a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryBoard.java b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryBoard.java index 3e28ff9e..89251133 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryBoard.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryBoard.java @@ -6,10 +6,7 @@ import com.massivecraft.factions.util.AsciiCompass; import com.massivecraft.factions.util.LazyLocation; import org.bukkit.ChatColor; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; +import java.util.*; import java.util.Map.Entry; @@ -57,6 +54,22 @@ public abstract class MemoryBoard extends Board { flocationIds.remove(flocation); } + public Set getAllClaims(String factionId) { + Set locs = new HashSet(); + Iterator> iter = flocationIds.entrySet().iterator(); + while (iter.hasNext()) { + Entry entry = iter.next(); + if (entry.getValue().equals(factionId)) { + locs.add(entry.getKey()); + } + } + return locs; + } + + public Set getAllClaims(Faction faction) { + return getAllClaims(faction.getId()); + } + // not to be confused with claims, ownership referring to further member-specific ownership of a claim public void clearOwnershipAt(FLocation flocation) { Faction faction = getFactionAt(flocation); @@ -105,11 +118,13 @@ public abstract class MemoryBoard extends Board { } /** - * Checks if there is another faction within a given radius other than Wilderness. - * Used for HCF feature that requires a 'buffer' between factions. + * Checks if there is another faction within a given radius other than Wilderness. Used for HCF feature that + * requires a 'buffer' between factions. + * * @param flocation - center location. - * @param faction - faction checking for. - * @param radius - chunk radius to check. + * @param faction - faction checking for. + * @param radius - chunk radius to check. + * * @return true if another Faction is within the radius, otherwise false. */ public boolean hasFactionWithin(FLocation flocation, Faction faction, int radius) { diff --git a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java index 5914098c..aef9a557 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java @@ -787,4 +787,8 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator { fPlayer.resetFactionData(false); } } + + public Set getAllClaims() { + return Board.getInstance().getAllClaims(this); + } }