mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-11-24 03:05:28 +01:00
Add showworldborder setting, 1.8 vanilla world border support
This commit is contained in:
parent
2e5d27d0d5
commit
0a4b1fd14b
@ -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; }
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user