diff --git a/src/main/java/com/massivecraft/factions/Board.java b/src/main/java/com/massivecraft/factions/Board.java index 5f565bf9..04279b38 100644 --- a/src/main/java/com/massivecraft/factions/Board.java +++ b/src/main/java/com/massivecraft/factions/Board.java @@ -45,6 +45,9 @@ public abstract class Board { // Is this coord connected to any coord claimed by the specified faction? public abstract boolean isConnectedLocation(FLocation flocation, Faction faction); + // Is this location outside the world border? + public abstract boolean isOutsideWorldBorder(FLocation flocation); + public abstract boolean hasFactionWithin(FLocation flocation, Faction faction, int radius); //----------------------------------------------// 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 e9aa9cd1..6e06d708 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryBoard.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryBoard.java @@ -4,7 +4,11 @@ import com.massivecraft.factions.*; import com.massivecraft.factions.struct.Relation; import com.massivecraft.factions.util.AsciiCompass; import com.massivecraft.factions.util.LazyLocation; + import org.bukkit.ChatColor; +import org.bukkit.Chunk; +import org.bukkit.World; +import org.bukkit.WorldBorder; import java.util.ArrayList; import java.util.HashMap; @@ -124,6 +128,21 @@ public abstract class MemoryBoard extends Board { } return false; } + + /** + * Checks if a claim chunk is outside the world border + * @param flocation claim chunk + * @return if claim chunk is outside world border + */ + public boolean isOutsideWorldBorder(FLocation flocation) { + World world = flocation.getWorld(); + WorldBorder border = world.getWorldBorder(); + Chunk chunk = border.getCenter().getChunk(); + int lim = FLocation.blockToChunk((int) border.getSize()); + int diffX = (int) Math.abs(chunk.getX() - flocation.getX()); + int diffZ = (int) Math.abs(chunk.getZ() - flocation.getZ()); + return diffX + diffZ > lim; + } /** * Checks if the faction at the flocation is not wilderness and different than given faction. 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 a819fb88..f86a3320 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java @@ -697,6 +697,8 @@ public abstract class MemoryFPlayer implements FPlayer { } } else if (buffer > 0 && Board.getInstance().hasFactionWithin(flocation, myFaction, buffer)) { error = P.p.txt.parse(TL.CLAIM_TOOCLOSETOOTHERFACTION.format(buffer)); + } else if (Board.getInstance().isOutsideWorldBorder(flocation)) { + error = P.p.txt.parse(TL.CLAIM_OUTSIDEWORLDBORDER.toString()); } 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 ad7b65ce..82b28b25 100644 --- a/src/main/java/com/massivecraft/factions/zcore/util/TL.java +++ b/src/main/java/com/massivecraft/factions/zcore/util/TL.java @@ -538,6 +538,7 @@ public enum TL { 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"), + CLAIM_OUTSIDEWORLDBORDER("Your claim is outside the border. Buffer is %d chunks from world edge."), /** * 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 4d62631a..124164e6 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -169,6 +169,13 @@ max-relations: neutral: -1 enemy: 10 +# WorldBorder support +# A buffer of 0 means faction claims can go right up to the border of the world. +# The buffer is in chunks, so 1 as a buffer means an entire chunk of buffer between +# the border of the world and what can be claimed to factions +world-border: + buffer: 0 + # Raids # Allow a faction to be raided if they have more land than power. # This will make claimed territory lose all protections