Gracefully handle the absence of WorldBorder
Additionally move `isOutsideWorldBorder` to FLocation, because it doesn't belong in Board/MemoryBoard.
This commit is contained in:
parent
0aea7c6b9d
commit
2b4e1a1947
@ -45,9 +45,6 @@ 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, int buffer);
|
||||
|
||||
public abstract boolean hasFactionWithin(FLocation flocation, Faction faction, int radius);
|
||||
|
||||
//----------------------------------------------//
|
||||
|
@ -1,10 +1,7 @@
|
||||
package com.massivecraft.factions;
|
||||
|
||||
import com.massivecraft.factions.util.MiscUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -15,10 +12,21 @@ import java.util.Set;
|
||||
|
||||
public class FLocation implements Serializable {
|
||||
private static final long serialVersionUID = -8292915234027387983L;
|
||||
private static final boolean worldBorderSupport;
|
||||
private String worldName = "world";
|
||||
private int x = 0;
|
||||
private int z = 0;
|
||||
|
||||
static {
|
||||
boolean worldBorderClassPresent = false;
|
||||
try {
|
||||
Class.forName("org.bukkit.WorldBorder");
|
||||
worldBorderClassPresent = true;
|
||||
} catch (ClassNotFoundException ignored) {}
|
||||
|
||||
worldBorderSupport = worldBorderClassPresent;
|
||||
}
|
||||
|
||||
//----------------------------------------------//
|
||||
// Constructors
|
||||
//----------------------------------------------//
|
||||
@ -158,6 +166,26 @@ public class FLocation implements Serializable {
|
||||
return loc.getWorld().getName().equalsIgnoreCase(getWorldName()) && chunk.getX() == x && chunk.getZ() == z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the chunk represented by this FLocation is outside the world border
|
||||
*
|
||||
* @param buffer the number of chunks from the border that will be treated as "outside"
|
||||
* @return whether this location is outside of the border
|
||||
*/
|
||||
public boolean isOutsideWorldBorder(int buffer) {
|
||||
if (!worldBorderSupport) {
|
||||
return false;
|
||||
}
|
||||
|
||||
WorldBorder border = getWorld().getWorldBorder();
|
||||
Chunk chunk = border.getCenter().getChunk();
|
||||
|
||||
int lim = FLocation.chunkToRegion((int) border.getSize()) - buffer;
|
||||
int diffX = Math.abs(chunk.getX() - x);
|
||||
int diffZ = Math.abs(chunk.getZ() - z);
|
||||
return diffX > lim || diffZ > lim;
|
||||
}
|
||||
|
||||
//----------------------------------------------//
|
||||
// Some Geometry
|
||||
//----------------------------------------------//
|
||||
|
@ -4,11 +4,7 @@ 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;
|
||||
@ -129,21 +125,6 @@ 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, int buffer) {
|
||||
World world = flocation.getWorld();
|
||||
WorldBorder border = world.getWorldBorder();
|
||||
Chunk chunk = border.getCenter().getChunk();
|
||||
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 > lim || diffZ > lim;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the faction at the flocation is not wilderness and different than given faction.
|
||||
* @param flocation - location to check.
|
||||
|
@ -698,7 +698,7 @@ public abstract class MemoryFPlayer implements FPlayer {
|
||||
}
|
||||
} 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)) {
|
||||
} else if (flocation.isOutsideWorldBorder(worldBuffer)) {
|
||||
if(worldBuffer > 0) {
|
||||
error = P.p.txt.parse(TL.CLAIM_OUTSIDEBORDERBUFFER.format(worldBuffer));
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user