Add WorldBorder support

- Uses API in spigot to get world border
- Blocks faction claims that are outside the world border

Improved border detection

This is the updated border detection, this method is extremely accurate
and does not over partition claim space like before.

Takes the border and divides by two, and then converts the block
distance into a chunk distance.
Ex. Border = 100, Chunks = 6 vertically, 6 horizontally.

We get the absolute value difference between the center chunk and the
claim chunk, for both X and Z. We add both diffs, and if they are
greater than the limit, then we know the chunk is outside the border!
This commit is contained in:
Nick Porillo 2015-02-13 20:37:52 -05:00 committed by drtshock
parent e6aa3116ac
commit 5a9112ad37
5 changed files with 32 additions and 0 deletions

View File

@ -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);
//----------------------------------------------//

View File

@ -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.

View File

@ -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));

View File

@ -538,6 +538,7 @@ public enum TL {
CLAIM_CLAIMEDLOG("%s claimed land at (%s) for the faction: %s"),
CLAIM_OVERCLAIM_DISABLED("<i>Over claiming is disabled on this server."),
CLAIM_TOOCLOSETOOTHERFACTION("<i>Your claim is too close to another Faction. Buffer required is %d"),
CLAIM_OUTSIDEWORLDBORDER("<i>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

View File

@ -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