diff --git a/src/main/java/com/massivecraft/factions/Board.java b/src/main/java/com/massivecraft/factions/Board.java index 3b96d0a4..5f565bf9 100644 --- a/src/main/java/com/massivecraft/factions/Board.java +++ b/src/main/java/com/massivecraft/factions/Board.java @@ -45,6 +45,7 @@ public abstract class Board { // Is this coord connected to any coord claimed by the specified faction? public abstract boolean isConnectedLocation(FLocation flocation, Faction faction); + public abstract boolean hasFactionWithin(FLocation flocation, Faction faction, int radius); //----------------------------------------------// // Cleaner. Remove orphaned foreign keys 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 e476d6f8..e9aa9cd1 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryBoard.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryBoard.java @@ -104,6 +104,39 @@ public abstract class MemoryBoard extends Board { return faction == getFactionAt(a) || faction == getFactionAt(b) || faction == getFactionAt(c) || faction == getFactionAt(d); } + /** + * 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. + * @return true if another Faction is within the radius, otherwise false. + */ + public boolean hasFactionWithin(FLocation flocation, Faction faction, int radius) { + for(int i = 1; i <= radius; i++) { + FLocation a = flocation.getRelative(i, 0); + FLocation b = flocation.getRelative(-i, 0); + FLocation c = flocation.getRelative(0, i); + FLocation d = flocation.getRelative(0, -i); + if(isDifferentFaction(a, faction) || isDifferentFaction(b, faction) || isDifferentFaction(c, faction) || isDifferentFaction(d, faction)) { + return false; // Return if the Faction found is a different one. + } + } + return false; + } + + /** + * Checks if the faction at the flocation is not wilderness and different than given faction. + * @param flocation - location to check. + * @param faction - faction to compare. + * @return true if not wilderness, safezone, or warzone and different faction, otherwise false. + */ + private boolean isDifferentFaction(FLocation flocation, Faction faction) { + Faction other = getFactionAt(flocation); + // Check if faction is + return other.isNormal() && other != faction; + } + //----------------------------------------------// // Cleaner. Remove orphaned foreign keys diff --git a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java index df571a94..0d0c8564 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java @@ -658,6 +658,7 @@ public abstract class MemoryFPlayer implements FPlayer { Faction myFaction = getFaction(); Faction currentFaction = Board.getInstance().getFactionAt(flocation); int ownedLand = forFaction.getLandRounded(); + int buffer = P.p.getConfig().getInt("hcf.buffer-zone", 0); if (Conf.worldGuardChecking && Worldguard.checkForRegionsInChunk(location)) { // Checks for WorldGuard regions in the chunk attempting to be claimed @@ -694,6 +695,8 @@ public abstract class MemoryFPlayer implements FPlayer { } else { error = P.p.txt.parse(TL.CLAIM_FACTIONCONTIGUOUS.toString()); } + } else if (buffer > 0 && Board.getInstance().hasFactionWithin(flocation, myFaction, buffer)) { + error = P.p.txt.parse(TL.CLAIM_TOOCLOSETOOTHERFACTION.format(buffer)); } else if (currentFaction.isNormal()) { if (myFaction.isPeaceful()) { error = P.p.txt.parse(TL.CLAIM_PEACEFUL.toString(), currentFaction.getTag(this)); diff --git a/src/main/java/com/massivecraft/factions/zcore/util/TL.java b/src/main/java/com/massivecraft/factions/zcore/util/TL.java index a385db5a..ad7b65ce 100644 --- a/src/main/java/com/massivecraft/factions/zcore/util/TL.java +++ b/src/main/java/com/massivecraft/factions/zcore/util/TL.java @@ -537,6 +537,7 @@ public enum TL { CLAIM_CLAIMED("%s claimed land for %s from %s."), CLAIM_CLAIMEDLOG("%s claimed land at (%s) for the faction: %s"), CLAIM_OVERCLAIM_DISABLED("Over claiming is disabled on this server."), + CLAIM_TOOCLOSETOOTHERFACTION("Your claim is too close to another Faction. Buffer required is %d"), /** * More generic, or less easily categorisable translations, which may apply to more than one class diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 1f09df97..4d62631a 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -188,4 +188,16 @@ hcf: # After a player dies, how long should the faction not be able to regen power? # This resets on each death but does not accumulate. # Set to 0 for no freeze. Time is in seconds. - powerfreeze: 0 \ No newline at end of file + powerfreeze: 0 + + # Buffer Zone + # Buffer Zone is an chunk area required between claims of different Factions. + # This is default to 0 and has always been that way. Meaning Factions can have + # claims that border each other. + # If this is set to 3, then Factions need to have 3 chunks between their claim + # and another Faction's claim. + # It's recommended to keep this pretty low as the radius check could be a + # heavy operation if set to a large number. + # If this is set to 0, we won't even bother checking which is how Factions has + # always been. + buffer-zone: 0 \ No newline at end of file