Add showworldborder setting, 1.8 vanilla world border support

This commit is contained in:
Mike Primm 2015-02-15 12:40:30 -06:00
parent 2e5d27d0d5
commit 0a4b1fd14b
6 changed files with 67 additions and 5 deletions

View File

@ -13,6 +13,7 @@ import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.dynmap.Log;
import org.dynmap.utils.Polygon;
/**
* Helper for isolation of bukkit version specific issues
@ -143,4 +144,8 @@ public abstract class BukkitVersionHelper {
* Get player health
*/
public abstract double getHealth(Player p);
/**
* Get world border
*/
public Polygon getWorldBorder(World world) { return null; }
}

View File

@ -12,6 +12,7 @@ import org.bukkit.Server;
import org.bukkit.World;
import org.dynmap.Log;
import org.dynmap.common.BiomeMap;
import org.dynmap.utils.Polygon;
/**
* Helper for isolation of bukkit version specific issues
@ -24,6 +25,12 @@ public class BukkitVersionHelperCB extends BukkitVersionHelperGeneric {
private Field blockname;
private Field material;
private Method blockbyidfunc; // 1.7+ method for getting block by id
private Method getworldborder; // 1.8+ method for getting world border
private Class<?> nmsworldborder;
private Method worldborderminx;
private Method worldbordermaxx;
private Method worldborderminz;
private Method worldbordermaxz;
BukkitVersionHelperCB() {
}
@ -65,6 +72,7 @@ public class BukkitVersionHelperCB extends BukkitVersionHelperGeneric {
nmsworld = getNMSClass("net.minecraft.server.WorldServer");
chunkprovserver = getNMSClass("net.minecraft.server.ChunkProviderServer");
nmsw_chunkproviderserver = getField(nmsworld, new String[] { "chunkProviderServer" }, chunkprovserver);
getworldborder = getMethodNoFail(nmsworld, new String[] { "af" }, nulltypes);
longhashset = getOBCClassNoFail("org.bukkit.craftbukkit.util.LongHashSet");
if(longhashset != null) {
@ -81,12 +89,21 @@ public class BukkitVersionHelperCB extends BukkitVersionHelperGeneric {
}
/** n.m.s.Chunk */
nmschunk = getNMSClass("net.minecraft.server.Chunk");
nmsc_removeentities = getMethod(nmschunk, new String[] { "removeEntities" }, new Class[0]);
nmsc_removeentities = getMethod(nmschunk, new String[] { "removeEntities" }, nulltypes);
nmsc_tileentities = getField(nmschunk, new String[] { "tileEntities" }, Map.class);
nmsc_inhabitedticks = getFieldNoFail(nmschunk, new String[] { "s", "q", "u" }, long.class);
if (nmsc_inhabitedticks == null) {
Log.info("inhabitedTicks field not found - inhabited shader not functional");
}
/** n.m.s.WorldBorder */
nmsworldborder = getNMSClassNoFail("net.minecraft.server.WorldBorder");
if (nmsworldborder != null) {
worldborderminx = getMethod(nmsworldborder, new String[] { "b" }, nulltypes);
worldborderminz = getMethod(nmsworldborder, new String[] { "c" }, nulltypes);
worldbordermaxx = getMethod(nmsworldborder, new String[] { "d" }, nulltypes);
worldbordermaxz = getMethod(nmsworldborder, new String[] { "e" }, nulltypes);
}
/** nbt classes */
nbttagcompound = getNMSClass("net.minecraft.server.NBTTagCompound");
nbttagbyte = getNMSClass("net.minecraft.server.NBTTagByte");
@ -229,4 +246,28 @@ public class BukkitVersionHelperCB extends BukkitVersionHelperGeneric {
}
return new int[0];
}
@Override
public Polygon getWorldBorder(World world) {
Polygon p = null;
if ((getworldborder == null) || (world == null)) {
return null;
}
Object cw = getNMSWorld(world);
if (cw == null) return null;
Object wb = callMethod(cw, getworldborder, nullargs, null);
if (wb != null) {
double minx = (Double) callMethod(wb, worldborderminx, nullargs, Double.MIN_VALUE);
double minz = (Double) callMethod(wb, worldborderminz, nullargs, Double.MIN_VALUE);
double maxx = (Double) callMethod(wb, worldbordermaxx, nullargs, Double.MAX_VALUE);
double maxz = (Double) callMethod(wb, worldbordermaxz, nullargs, Double.MAX_VALUE);
if (maxx < 1E7) {
p = new Polygon();
p.addVertex(minx, minz);
p.addVertex(minx, maxz);
p.addVertex(maxx, maxz);
p.addVertex(maxx, minz);
}
}
return p;
}
}

View File

@ -23,7 +23,8 @@ public abstract class BukkitVersionHelperGeneric extends BukkitVersionHelper {
private String obc_package; // Package used for org.bukkit.craftbukkit
protected String nms_package; // Package used for net.minecraft.server
private boolean failed;
private static final Object[] nullargs = new Object[0];
protected static final Object[] nullargs = new Object[0];
protected static final Class[] nulltypes = new Class[0];
private static final Map nullmap = Collections.emptyMap();
/** CraftChunkSnapshot */
@ -143,7 +144,11 @@ public abstract class BukkitVersionHelperGeneric extends BukkitVersionHelper {
protected Class<?> getNMSClass(String classname) {
return getClassByName(classname, "net.minecraft.server", nms_package, false);
}
protected Class<?> getNMSClassNoFail(String classname) {
return getClassByName(classname, "net.minecraft.server", nms_package, true);
}
protected Class<?> getClassByName(String classname, String base, String mapping, boolean nofail) {
String n = classname;
int idx = classname.indexOf(base);
@ -249,7 +254,7 @@ public abstract class BukkitVersionHelperGeneric extends BukkitVersionHelper {
}
return null;
}
private Object callMethod(Object obj, Method meth, Object[] args, Object def) {
protected Object callMethod(Object obj, Method meth, Object[] args, Object def) {
if((obj == null) || (meth == null)) {
return def;
}

View File

@ -18,6 +18,7 @@ import org.dynmap.DynmapChunk;
import org.dynmap.DynmapLocation;
import org.dynmap.DynmapWorld;
import org.dynmap.utils.MapChunkCache;
import org.dynmap.utils.Polygon;
import org.dynmap.utils.TileFlags;
public class BukkitWorld extends DynmapWorld {
@ -242,5 +243,8 @@ public class BukkitWorld extends DynmapWorld {
}
return cnt;
}
@Override
public Polygon getWorldBorder() {
return DynmapPlugin.plugin.getWorldBorder(world);
}
}

View File

@ -94,6 +94,7 @@ import org.dynmap.hdmap.HDMap;
import org.dynmap.markers.MarkerAPI;
import org.dynmap.modsupport.ModSupportImpl;
import org.dynmap.utils.MapChunkCache;
import org.dynmap.utils.Polygon;
import org.dynmap.utils.VisibilityLimit;
public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
@ -1619,4 +1620,8 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
String[] lines, String playerid) {
core.processSignChange(blkid, world, x, y, z, lines, playerid);
}
Polygon getWorldBorder(World w) {
return helper.getWorldBorder(w);
}
}

View File

@ -125,6 +125,8 @@ components:
spawnbedhidebydefault: true
spawnbedminzoom: 0
spawnbedformat: "%name%'s bed"
# (optional) show world border (vanilla 1.8+)
showworldborder: true
- class: org.dynmap.ClientComponent
type: chat