mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-11-27 20:58:40 +01:00
Start Spigot 1.8 support (doesn't work yet....)
This commit is contained in:
parent
0f722da05d
commit
b0d9f5541a
@ -5,6 +5,7 @@ import java.lang.reflect.InvocationTargetException;
|
|||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
@ -58,7 +59,7 @@ public class BukkitVersionHelperCB extends BukkitVersionHelperGeneric {
|
|||||||
biomebaselist = getPrivateField(biomebase, new String[] { "biomes" }, biomebasearray);
|
biomebaselist = getPrivateField(biomebase, new String[] { "biomes" }, biomebasearray);
|
||||||
biomebasetemp = getField(biomebase, new String[] { "temperature", "F" }, float.class);
|
biomebasetemp = getField(biomebase, new String[] { "temperature", "F" }, float.class);
|
||||||
biomebasehumi = getField(biomebase, new String[] { "humidity", "G" }, float.class);
|
biomebasehumi = getField(biomebase, new String[] { "humidity", "G" }, float.class);
|
||||||
biomebaseidstring = getField(biomebase, new String[] { "y", "af" }, String.class);
|
biomebaseidstring = getField(biomebase, new String[] { "y", "af", "ah" }, String.class);
|
||||||
biomebaseid = getField(biomebase, new String[] { "id" }, int.class);
|
biomebaseid = getField(biomebase, new String[] { "id" }, int.class);
|
||||||
/* n.m.s.World */
|
/* n.m.s.World */
|
||||||
nmsworld = getNMSClass("net.minecraft.server.WorldServer");
|
nmsworld = getNMSClass("net.minecraft.server.WorldServer");
|
||||||
@ -82,7 +83,7 @@ public class BukkitVersionHelperCB extends BukkitVersionHelperGeneric {
|
|||||||
nmschunk = getNMSClass("net.minecraft.server.Chunk");
|
nmschunk = getNMSClass("net.minecraft.server.Chunk");
|
||||||
nmsc_removeentities = getMethod(nmschunk, new String[] { "removeEntities" }, new Class[0]);
|
nmsc_removeentities = getMethod(nmschunk, new String[] { "removeEntities" }, new Class[0]);
|
||||||
nmsc_tileentities = getField(nmschunk, new String[] { "tileEntities" }, Map.class);
|
nmsc_tileentities = getField(nmschunk, new String[] { "tileEntities" }, Map.class);
|
||||||
nmsc_inhabitedticks = getFieldNoFail(nmschunk, new String[] { "s", "q" }, long.class);
|
nmsc_inhabitedticks = getFieldNoFail(nmschunk, new String[] { "s", "q", "u" }, long.class);
|
||||||
if (nmsc_inhabitedticks == null) {
|
if (nmsc_inhabitedticks == null) {
|
||||||
Log.info("inhabitedTicks field not found - inhabited shader not functional");
|
Log.info("inhabitedTicks field not found - inhabited shader not functional");
|
||||||
}
|
}
|
||||||
@ -111,9 +112,18 @@ public class BukkitVersionHelperCB extends BukkitVersionHelperGeneric {
|
|||||||
/** Tile entity */
|
/** Tile entity */
|
||||||
nms_tileentity = getNMSClass("net.minecraft.server.TileEntity");
|
nms_tileentity = getNMSClass("net.minecraft.server.TileEntity");
|
||||||
nmst_readnbt = getMethod(nms_tileentity, new String[] { "b" }, new Class[] { nbttagcompound });
|
nmst_readnbt = getMethod(nms_tileentity, new String[] { "b" }, new Class[] { nbttagcompound });
|
||||||
nmst_x = getField(nms_tileentity, new String[] { "x" }, int.class);
|
nmst_getposition = getMethodNoFail(nms_tileentity, new String[] { "getPosition" }, new Class[0]); // Try 1.8 method
|
||||||
nmst_y = getField(nms_tileentity, new String[] { "y" }, int.class);
|
if (nmst_getposition == null) {
|
||||||
nmst_z = getField(nms_tileentity, new String[] { "z" }, int.class);
|
nmst_x = getField(nms_tileentity, new String[] { "x" }, int.class);
|
||||||
|
nmst_y = getField(nms_tileentity, new String[] { "y" }, int.class);
|
||||||
|
nmst_z = getField(nms_tileentity, new String[] { "z" }, int.class);
|
||||||
|
}
|
||||||
|
else { /* BlockPosition */
|
||||||
|
nms_blockposition = getNMSClass("net.minecraft.server.BlockPosition");
|
||||||
|
nmsbp_getx = getMethod(nms_blockposition, new String[] { "getX" }, new Class[0]);
|
||||||
|
nmsbp_gety = getMethod(nms_blockposition, new String[] { "getY" }, new Class[0]);
|
||||||
|
nmsbp_getz = getMethod(nms_blockposition, new String[] { "getZ" }, new Class[0]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void unloadChunkNoSave(World w, Chunk c, int cx, int cz) {
|
public void unloadChunkNoSave(World w, Chunk c, int cx, int cz) {
|
||||||
|
@ -83,6 +83,13 @@ public abstract class BukkitVersionHelperGeneric extends BukkitVersionHelper {
|
|||||||
protected Field nmst_x;
|
protected Field nmst_x;
|
||||||
protected Field nmst_y;
|
protected Field nmst_y;
|
||||||
protected Field nmst_z;
|
protected Field nmst_z;
|
||||||
|
protected Method nmst_getposition;
|
||||||
|
/** BlockPosition */
|
||||||
|
protected Class<?> nms_blockposition;
|
||||||
|
protected Method nmsbp_getx;
|
||||||
|
protected Method nmsbp_gety;
|
||||||
|
protected Method nmsbp_getz;
|
||||||
|
|
||||||
/** Server */
|
/** Server */
|
||||||
protected Method server_getonlineplayers;
|
protected Method server_getonlineplayers;
|
||||||
/** Player */
|
/** Player */
|
||||||
@ -231,6 +238,17 @@ public abstract class BukkitVersionHelperGeneric extends BukkitVersionHelper {
|
|||||||
failed = true;
|
failed = true;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
protected Method getMethodNoFail(Class<?> cls, String[] ids, Class[] args) {
|
||||||
|
if(cls == null) return null;
|
||||||
|
for(String id : ids) {
|
||||||
|
try {
|
||||||
|
return cls.getMethod(id, args);
|
||||||
|
} catch (SecurityException e) {
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
private Object callMethod(Object obj, Method meth, Object[] args, Object def) {
|
private Object callMethod(Object obj, Method meth, Object[] args, Object def) {
|
||||||
if((obj == null) || (meth == null)) {
|
if((obj == null) || (meth == null)) {
|
||||||
return def;
|
return def;
|
||||||
@ -333,19 +351,37 @@ public abstract class BukkitVersionHelperGeneric extends BukkitVersionHelper {
|
|||||||
* Get X coordinate of tile entity
|
* Get X coordinate of tile entity
|
||||||
*/
|
*/
|
||||||
public int getTileEntityX(Object te) {
|
public int getTileEntityX(Object te) {
|
||||||
return (Integer)getFieldValue(te, nmst_x, 0);
|
if (nmst_getposition == null) {
|
||||||
|
return (Integer)getFieldValue(te, nmst_x, 0);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Object pos = callMethod(te, nmst_getposition, nullargs, null);
|
||||||
|
return (Integer) callMethod(pos, nmsbp_getx, nullargs, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Get Y coordinate of tile entity
|
* Get Y coordinate of tile entity
|
||||||
*/
|
*/
|
||||||
public int getTileEntityY(Object te) {
|
public int getTileEntityY(Object te) {
|
||||||
return (Integer)getFieldValue(te, nmst_y, 0);
|
if (nmst_getposition == null) {
|
||||||
|
return (Integer)getFieldValue(te, nmst_y, 0);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Object pos = callMethod(te, nmst_getposition, nullargs, null);
|
||||||
|
return (Integer) callMethod(pos, nmsbp_gety, nullargs, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Get Z coordinate of tile entity
|
* Get Z coordinate of tile entity
|
||||||
*/
|
*/
|
||||||
public int getTileEntityZ(Object te) {
|
public int getTileEntityZ(Object te) {
|
||||||
return (Integer)getFieldValue(te, nmst_z, 0);
|
if (nmst_getposition == null) {
|
||||||
|
return (Integer)getFieldValue(te, nmst_z, 0);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Object pos = callMethod(te, nmst_getposition, nullargs, null);
|
||||||
|
return (Integer) callMethod(pos, nmsbp_getz, nullargs, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Read tile entity NBT
|
* Read tile entity NBT
|
||||||
|
Loading…
Reference in New Issue
Block a user