From d69f9e56887c99ec4b4b0a8f12ee453afdb9dd8f Mon Sep 17 00:00:00 2001 From: Nick Porillo Date: Tue, 17 Feb 2015 19:21:46 -0500 Subject: [PATCH] Handle buffers --- .../java/com/massivecraft/factions/Board.java | 4 ++-- .../factions/zcore/persist/MemoryBoard.java | 6 +++--- .../factions/zcore/persist/MemoryFPlayer.java | 17 +++++++++++------ .../massivecraft/factions/zcore/util/TL.java | 4 ++-- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/Board.java b/src/main/java/com/massivecraft/factions/Board.java index 04279b38..5780dfcd 100644 --- a/src/main/java/com/massivecraft/factions/Board.java +++ b/src/main/java/com/massivecraft/factions/Board.java @@ -45,8 +45,8 @@ 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); + // Is this location outside the world border? + public abstract boolean isOutsideWorldBorder(FLocation flocation, int buffer); 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 6e06d708..85ad4971 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryBoard.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryBoard.java @@ -134,14 +134,14 @@ public abstract class MemoryBoard extends Board { * @param flocation claim chunk * @return if claim chunk is outside world border */ - public boolean isOutsideWorldBorder(FLocation flocation) { + public boolean isOutsideWorldBorder(FLocation flocation, int buffer) { World world = flocation.getWorld(); WorldBorder border = world.getWorldBorder(); Chunk chunk = border.getCenter().getChunk(); - int lim = FLocation.blockToChunk((int) border.getSize()); + int lim = FLocation.chunkToRegion((int) border.getSize()) - buffer; int diffX = (int) Math.abs(chunk.getX() - flocation.getX()); int diffZ = (int) Math.abs(chunk.getZ() - flocation.getZ()); - return diffX + diffZ > lim; + return diffX > lim || diffZ > lim; } /** 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 f86a3320..b7f7298b 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java @@ -658,7 +658,8 @@ 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); + int factionBuffer = P.p.getConfig().getInt("hcf.buffer-zone", 0); + int worldBuffer = P.p.getConfig().getInt("world-border.buffer", 0); if (Conf.worldGuardChecking && Worldguard.checkForRegionsInChunk(location)) { // Checks for WorldGuard regions in the chunk attempting to be claimed @@ -695,10 +696,14 @@ 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 (Board.getInstance().isOutsideWorldBorder(flocation)) { - error = P.p.txt.parse(TL.CLAIM_OUTSIDEWORLDBORDER.toString()); + } else if (factionBuffer > 0 && Board.getInstance().hasFactionWithin(flocation, myFaction, factionBuffer)) { + error = P.p.txt.parse(TL.CLAIM_TOOCLOSETOOTHERFACTION.format(factionBuffer)); + } else if (Board.getInstance().isOutsideWorldBorder(flocation, worldBuffer)) { + if(worldBuffer > 0) { + error = P.p.txt.parse(TL.CLAIM_OUTSIDEBORDERBUFFER.format(worldBuffer)); + } else { + 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)); @@ -856,4 +861,4 @@ public abstract class MemoryFPlayer implements FPlayer { public void setId(String id) { this.id = id; } -} \ No newline at end of file +} 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 82b28b25..365a68c1 100644 --- a/src/main/java/com/massivecraft/factions/zcore/util/TL.java +++ b/src/main/java/com/massivecraft/factions/zcore/util/TL.java @@ -538,8 +538,8 @@ 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."), - + CLAIM_OUTSIDEWORLDBORDER("Your claim is outside the border."), + CLAIM_OUTSIDEBORDERBUFFER("Your claim is outside the border. %d chunks away world edge required."), /** * More generic, or less easily categorisable translations, which may apply to more than one class */