From a7f0218d0fd6e9e311eb3976d7620a9111cea381 Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Sun, 12 Oct 2014 17:40:14 -0500 Subject: [PATCH 01/12] Prepare for 2.0.0. release --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d0bbc5ac..623a8564 100644 --- a/pom.xml +++ b/pom.xml @@ -162,5 +162,5 @@ 2.10.1 - 2.0.0-SNAPSHOT + 2.0.0 From af1bcd1094f9c8363afb641a8d6b57226874bfcb Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Mon, 13 Oct 2014 09:12:01 -0500 Subject: [PATCH 02/12] Bump to 2.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 623a8564..b452b8bd 100644 --- a/pom.xml +++ b/pom.xml @@ -162,5 +162,5 @@ 2.10.1 - 2.0.0 + 2.1-SNAPSHOT From 0f722da05dd56219af2cde8bebe689497cf47e65 Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Mon, 13 Oct 2014 09:41:14 -0500 Subject: [PATCH 03/12] Update to use Bukkit 1.7.10-R0.1 API, rip out old SpoutPlugin support --- pom.xml | 10 +- .../dynmap/bukkit/BukkitVersionHelper.java | 2 +- .../bukkit/BukkitVersionHelperGeneric.java | 3 +- .../bukkit/BukkitVersionHelperGlowstone.java | 2 +- .../java/org/dynmap/bukkit/DynmapPlugin.java | 57 +--- .../org/dynmap/bukkit/NewMapChunkCache.java | 18 -- .../org/dynmap/bukkit/SpoutPluginBlocks.java | 268 ------------------ 7 files changed, 9 insertions(+), 351 deletions(-) delete mode 100644 src/main/java/org/dynmap/bukkit/SpoutPluginBlocks.java diff --git a/pom.xml b/pom.xml index b452b8bd..9c46d4bb 100644 --- a/pom.xml +++ b/pom.xml @@ -96,14 +96,6 @@ - - - - - - bukkit-repo - http://repo.bukkit.org/content/repositories/releases/ - @@ -122,7 +114,7 @@ org.bukkit bukkit - 1.4.7-R1.0 + 1.7.10-R0.1-SNAPSHOT us.dynmap diff --git a/src/main/java/org/dynmap/bukkit/BukkitVersionHelper.java b/src/main/java/org/dynmap/bukkit/BukkitVersionHelper.java index 65206bc0..6dbcefce 100644 --- a/src/main/java/org/dynmap/bukkit/BukkitVersionHelper.java +++ b/src/main/java/org/dynmap/bukkit/BukkitVersionHelper.java @@ -142,5 +142,5 @@ public abstract class BukkitVersionHelper { /** * Get player health */ - public abstract int getHealth(Player p); + public abstract double getHealth(Player p); } diff --git a/src/main/java/org/dynmap/bukkit/BukkitVersionHelperGeneric.java b/src/main/java/org/dynmap/bukkit/BukkitVersionHelperGeneric.java index 93782a51..c50a3323 100644 --- a/src/main/java/org/dynmap/bukkit/BukkitVersionHelperGeneric.java +++ b/src/main/java/org/dynmap/bukkit/BukkitVersionHelperGeneric.java @@ -416,7 +416,8 @@ public abstract class BukkitVersionHelperGeneric extends BukkitVersionHelper { /** * Get player health */ - public int getHealth(Player p) { + @Override + public double getHealth(Player p) { Object health = callMethod(p, player_gethealth, nullargs, null); if (health instanceof Integer) { return (Integer) health; diff --git a/src/main/java/org/dynmap/bukkit/BukkitVersionHelperGlowstone.java b/src/main/java/org/dynmap/bukkit/BukkitVersionHelperGlowstone.java index 0d3a3bb0..6c117116 100644 --- a/src/main/java/org/dynmap/bukkit/BukkitVersionHelperGlowstone.java +++ b/src/main/java/org/dynmap/bukkit/BukkitVersionHelperGlowstone.java @@ -444,7 +444,7 @@ public class BukkitVersionHelperGlowstone extends BukkitVersionHelper { } @Override - public int getHealth(Player p) { + public double getHealth(Player p) { return p.getHealth(); } diff --git a/src/main/java/org/dynmap/bukkit/DynmapPlugin.java b/src/main/java/org/dynmap/bukkit/DynmapPlugin.java index bb5c68ee..c0121a7e 100644 --- a/src/main/java/org/dynmap/bukkit/DynmapPlugin.java +++ b/src/main/java/org/dynmap/bukkit/DynmapPlugin.java @@ -2,11 +2,9 @@ package org.dynmap.bukkit; import java.io.File; import java.io.IOException; -import java.io.InputStream; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.InetSocketAddress; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; @@ -103,11 +101,9 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI { private PermissionProvider permissions; private String version; public SnapshotCache sscache; - private boolean has_spout = false; public PlayerList playerList; private MapManager mapManager; public static DynmapPlugin plugin; - public SpoutPluginBlocks spb; public PluginManager pm; private Metrics metrics; private BukkitEnableCoreCallback enabCoreCB = new BukkitEnableCoreCallback(); @@ -169,26 +165,10 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI { private class BukkitEnableCoreCallback extends DynmapCore.EnableCoreCallbacks { @Override public void configurationLoaded() { - /* Check for Spout */ - if(detectSpout()) { - if(core.configuration.getBoolean("spout/enabled", true)) { - has_spout = true; - Log.info("Detected Spout"); - if(spb == null) { - spb = new SpoutPluginBlocks(DynmapPlugin.this); - } - modsused.add("SpoutPlugin"); - } - else { - Log.info("Detected Spout - Support Disabled"); - } + File st = new File(core.getDataFolder(), "renderdata/spout-texture.txt"); + if(st.exists()) { + st.delete(); } - if(!has_spout) { /* If not, clean up old spout texture, if needed */ - File st = new File(core.getDataFolder(), "renderdata/spout-texture.txt"); - if(st.exists()) - st.delete(); - } - } } @@ -634,7 +614,7 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI { return false; } @Override - public int getHealth() { + public double getHealth() { if(player != null) return helper.getHealth(player); else @@ -842,7 +822,6 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI { @EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true) public void onPluginEnabled(PluginEnableEvent evt) { if (!readyToEnable()) { - spb.markPluginEnabled(evt.getPlugin()); if (readyToEnable()) { /* If we;re ready now, finish enable */ doEnable(); /* Finish enable */ } @@ -867,18 +846,10 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI { } private boolean readyToEnable() { - if (spb != null) { - return spb.isReady(); - } return true; } private void doEnable() { - /* Prep spout support, if needed */ - if(spb != null) { - spb.processSpoutBlocks(this, core); - } - /* Enable core */ if(!core.enableCore(enabCoreCB)) { this.setEnabled(false); @@ -1515,18 +1486,6 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI { } } - private boolean detectSpout() { - Plugin p = this.getServer().getPluginManager().getPlugin("Spout"); - if(p != null) { - return p.isEnabled(); - } - return false; - } - - public boolean hasSpout() { - return has_spout; - } - @Override public void assertPlayerInvisibility(String player, boolean is_invisible, String plugin_id) { @@ -1577,14 +1536,6 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI { return 0; } }); - features.addPlotter(new Metrics.Plotter("Spout") { - @Override - public int getValue() { - if(plugin.has_spout) - return 1; - return 0; - } - }); features.addPlotter(new Metrics.Plotter("Login Security") { @Override public int getValue() { diff --git a/src/main/java/org/dynmap/bukkit/NewMapChunkCache.java b/src/main/java/org/dynmap/bukkit/NewMapChunkCache.java index 9ef2fbc3..de128ebc 100644 --- a/src/main/java/org/dynmap/bukkit/NewMapChunkCache.java +++ b/src/main/java/org/dynmap/bukkit/NewMapChunkCache.java @@ -22,14 +22,12 @@ import org.dynmap.utils.MapChunkCache; import org.dynmap.utils.MapIterator; import org.dynmap.utils.BlockStep; import org.dynmap.utils.VisibilityLimit; -import org.getspout.spoutapi.block.SpoutChunk; /** * Container for managing chunks - dependent upon using chunk snapshots, since rendering is off server thread */ public class NewMapChunkCache extends MapChunkCache { private static boolean init = false; - private static boolean use_spout = false; private World w; private DynmapWorld dw; @@ -737,8 +735,6 @@ public class NewMapChunkCache extends MapChunkCache { */ public NewMapChunkCache() { if(!init) { - use_spout = DynmapPlugin.plugin.hasSpout(); - init = true; } } @@ -781,17 +777,6 @@ public class NewMapChunkCache extends MapChunkCache { isSectionNotEmpty = new boolean[snapcnt][]; } - private ChunkSnapshot checkSpoutData(Chunk c, ChunkSnapshot ss) { - if(c instanceof SpoutChunk) { - SpoutChunk sc = (SpoutChunk)c; - short[] custids = sc.getCustomBlockIds(); - if(custids != null) { - return new SpoutChunkSnapshot(ss, custids, c.getWorld().getMaxHeight()); - } - } - return ss; - } - public int loadChunks(int max_to_load) { if(dw.isLoaded() == false) return 0; @@ -884,9 +869,6 @@ public class NewMapChunkCache extends MapChunkCache { else { if(blockdata || highesty) { ss = c.getChunkSnapshot(highesty, biome, biomeraw); - if(use_spout) { - ss = checkSpoutData(c, ss); - } /* Get tile entity data */ List vals = new ArrayList(); Map tileents = helper.getTileEntitiesForChunk(c); diff --git a/src/main/java/org/dynmap/bukkit/SpoutPluginBlocks.java b/src/main/java/org/dynmap/bukkit/SpoutPluginBlocks.java deleted file mode 100644 index 69155376..00000000 --- a/src/main/java/org/dynmap/bukkit/SpoutPluginBlocks.java +++ /dev/null @@ -1,268 +0,0 @@ -package org.dynmap.bukkit; - -import java.awt.image.BufferedImage; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.lang.reflect.Field; -import java.net.URL; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; - -import javax.imageio.ImageIO; - -import org.bukkit.Material; -import org.bukkit.plugin.Plugin; -import org.dynmap.DynmapCore; -import org.dynmap.Log; -import org.getspout.spoutapi.block.design.BlockDesign; -import org.getspout.spoutapi.block.design.GenericBlockDesign; -import org.getspout.spoutapi.block.design.GenericCuboidBlockDesign; -import org.getspout.spoutapi.block.design.Texture; -import org.getspout.spoutapi.material.CustomBlock; -import org.getspout.spoutapi.material.MaterialData; - -/** - * Handler for pulling spout-defined custom blocks into dynmap - * - * Generates and maintains custom render data file (renderdata/spout-texture.txt) and - * directory of downloaded image files (texturepacks/standard/spout/plugin.blockid.png) - */ -public class SpoutPluginBlocks { - private Field textXPosField; /* float[][] textXPos */ - private Field textYPosField; /* float[][] textYPos */ - private HashSet plugins_pending = new HashSet(); - - public SpoutPluginBlocks(Plugin plugin) { - /* First, see if any spout plugins that need to be enabled */ - for(Plugin p : plugin.getServer().getPluginManager().getPlugins()) { - List dep = p.getDescription().getDepend(); - if((dep != null) && (dep.contains("Spout"))) { - Log.info("Found Spout plugin: " + p.getName()); - if(p.isEnabled() == false) { - plugins_pending.add(p.getName()); - } - } - } - } - - public boolean isReady() { - return plugins_pending.isEmpty(); - } - - public void markPluginEnabled(Plugin p) { - plugins_pending.remove(p.getName()); - } - - private boolean initSpoutAccess() { - boolean success = false; - try { - textXPosField = GenericBlockDesign.class.getDeclaredField("textXPos"); - textXPosField.setAccessible(true); - textYPosField = GenericBlockDesign.class.getDeclaredField("textYPos"); - textYPosField.setAccessible(true); - success = true; - } catch (NoSuchFieldException nsfx) { - Log.severe("Cannot access needed Spout custom block fields!"); - Log.severe(nsfx); - } - return success; - } - private void addDefaultBlock(StringBuilder sb, CustomBlock blk) { - if(blk.isOpaque()) - sb.append("block:id=" + blk.getCustomId() + ",data=*,allfaces=1\n"); - else - sb.append("block:id=" + blk.getCustomId() + ",allfaces=12049,transparency=TRANSPARENT\n"); - } - - private static String fixIDString(String id) { - StringBuilder sb = new StringBuilder(); - int len = id.length(); - sb.setLength(len); - for(int i = 0; i < len; i++) { - char c = id.charAt(i); - if(Character.isJavaIdentifierStart(c)) { - sb.setCharAt(i, c); - } - else { - sb.setCharAt(i, '_'); - } - } - return sb.toString(); - } - - /* Process spout blocks - return true if something changed */ - public boolean processSpoutBlocks(DynmapPlugin plugin, DynmapCore core) { - File datadir = core.getDataFolder(); - if(textYPosField == null) { - if(initSpoutAccess() == false) - return false; - } - HashMap texturelist = new HashMap(); - boolean use_existing_texture = core.configuration.getBoolean("spout/use-existing-textures", true); - - int cnt = 0; - File f = new File(datadir, "texturepacks/standard/spout"); - if(f.exists() == false) - f.mkdirs(); - List blks = new ArrayList(); - CustomBlock[] cb = MaterialData.getCustomBlocks(); - /* Build new texture file as string */ - StringBuilder sb = new StringBuilder(); - /* Loop through blocks - try to freshen files, if needed */ - for(CustomBlock b : cb) { - BlockDesign bd = b.getBlockDesign(); - if(bd == null) continue; - String txtplug = bd.getTexturePlugin(); - if(txtplug == null) continue; - String blkname = b.getName(); - if(blkname == null) continue; - String blkid = txtplug + "." + fixIDString(blkname); - /* If not GenericCubiodBlockDesign, we don't handle it */ - if((bd instanceof GenericCuboidBlockDesign) == false) { - Log.info("Block " + blkid + " not suppored - only cubiod blocks"); - addDefaultBlock(sb, b); - continue; - } - /* Get texture info */ - Texture txt = bd.getTexture(); - int w = txt.getWidth(); - int h = txt.getHeight(); - int sz = txt.getSpriteSize(); - GenericCuboidBlockDesign gbd = (GenericCuboidBlockDesign)bd; - int[] txtidx = new int[6]; - /* Fetch quad fields - figure out which texture for which side */ - try { - float[][] textXPos = (float[][])textXPosField.get(gbd); - float[][] textYPos = (float[][])textYPosField.get(gbd); - /* Quads on cuboid are bottom, west, south, east, north, top */ - for(int i = 0; i < 6; i++) { - float minx = 1.0F; - float miny = 1.0F; - for(int j = 0; j < 4; j++) { - minx = Math.min(minx, textXPos[i][j]); - miny = Math.min(miny, textYPos[i][j]); - } - txtidx[i] = (int)((minx * w)/sz) + (w/sz)*(int)((miny * h)/sz); - } - } catch (Exception iax) { - addDefaultBlock(sb, b); - continue; - } - String txname = bd.getTexureURL(); - - String txtid = texturelist.get(txname); /* Get texture */ - if(txtid == null) { /* Not found yet */ - File imgfile = new File(f, blkid + ".png"); - - /* If not reusing loaded textures OR not previously loaded */ - if((!use_existing_texture) || (!imgfile.exists())) { - BufferedImage img = null; - boolean urlloaded = false; - try { - URL url = new URL(txname); - img = ImageIO.read(url); /* Load skin for player */ - urlloaded = true; - } catch (IOException iox) { - if(txname.startsWith("http") == false) { /* Not URL - try file */ - File tf = new File(txname); - if(tf.exists() == false) { - /* Horrible hack - try to find temp file (some SpoutMaterials versions) */ - try { - File tmpf = File.createTempFile("dynmap", "test"); - - tf = new File(tmpf.getParent(), txname); - tmpf.delete(); - } catch (IOException iox2) {} - } - if(tf.exists()) { - try { - img = ImageIO.read(tf); - urlloaded = true; - } catch (IOException iox3) { - } - } - } - if(img == null) { - Log.severe("Error loading texture for custom block '" + blkid + "' (" + b.getCustomId() + ") from " + txname + "(" + iox.getMessage() + ")"); - if(imgfile.exists()) { - try { - img = ImageIO.read(imgfile); /* Load existing */ - Log.info("Loaded cached texture file for " + blkid); - } catch (IOException iox2) { - Log.severe("Error loading cached texture file for " + blkid + " - " + iox2.getMessage()); - } - } - } - } - if(img != null) { - try { - if(urlloaded) - ImageIO.write(img, "png", imgfile); - } catch (IOException iox) { - Log.severe("Error writing " + blkid + ".png"); - } finally { - img.flush(); - } - } - } - if(imgfile.exists()) { /* If exists now, log it */ - String tfid = "txtid" + texturelist.size(); - sb.append("texturefile:id=" + tfid + ",filename=spout/" + blkid + ".png,xcount=" + w/sz + ",ycount=" + h/sz + "\n"); - texturelist.put(txname, tfid); - } - } - String txfileid = texturelist.get(txname); - if(txfileid != null) { - blks.add(b); - - sb.append("block:id=" + b.getCustomId() + ",data=*,bottom=" + txtidx[0] + ",west=" +txtidx[1] + ",south=" + txtidx[2] + ",east=" + txtidx[3] + ",north="+txtidx[4]+",top="+txtidx[5]); - if(b.getBlockId() == Material.GLASS.getId()) - sb.append(",transparency=TRANSPARENT"); - sb.append(",txtid=" + txfileid + "\n"); - cnt++; - } - } - String rslt = sb.toString(); - /* Now, generate spout texture file - see if changed */ - File renderdata = new File(datadir, "renderdata"); - if (renderdata.exists() == false) - renderdata.mkdirs(); - File st = new File(renderdata, "spout-texture.txt"); - if(st.exists()) { - FileReader fr = null; - StringBuilder sbold = new StringBuilder(); - try { - fr = new FileReader(st); - int len; - char[] buf = new char[512]; - while((len = fr.read(buf)) > 0) { - sbold.append(buf, 0, len); - } - } catch (IOException iox) { - } finally { - if(fr != null) { try { fr.close(); } catch (IOException iox) {} } - } - /* If same, no changes */ - if(sbold.equals(rslt)) { - Log.info("Loaded " + cnt + " Spout custom blocks"); - return false; - } - } - FileWriter fw = null; - try { - fw = new FileWriter(st); - fw.write(rslt); - } catch (IOException iox) { - Log.severe("Error opening spout texture file - " + st.getPath()); - return false; - } finally { - if(fw != null) { try { fw.close(); } catch (IOException iox) {} } - } - Log.info("Loaded " + cnt + " Spout custom blocks"); - return false; - } -} From b0d9f5541ac8754be77e235edea19240ded02876 Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Fri, 28 Nov 2014 11:08:44 -0600 Subject: [PATCH 04/12] Start Spigot 1.8 support (doesn't work yet....) --- .../dynmap/bukkit/BukkitVersionHelperCB.java | 20 ++++++--- .../bukkit/BukkitVersionHelperGeneric.java | 42 +++++++++++++++++-- 2 files changed, 54 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/dynmap/bukkit/BukkitVersionHelperCB.java b/src/main/java/org/dynmap/bukkit/BukkitVersionHelperCB.java index 042dba50..55c72792 100644 --- a/src/main/java/org/dynmap/bukkit/BukkitVersionHelperCB.java +++ b/src/main/java/org/dynmap/bukkit/BukkitVersionHelperCB.java @@ -5,6 +5,7 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Map; + import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.Server; @@ -58,7 +59,7 @@ public class BukkitVersionHelperCB extends BukkitVersionHelperGeneric { biomebaselist = getPrivateField(biomebase, new String[] { "biomes" }, biomebasearray); biomebasetemp = getField(biomebase, new String[] { "temperature", "F" }, 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); /* n.m.s.World */ nmsworld = getNMSClass("net.minecraft.server.WorldServer"); @@ -82,7 +83,7 @@ public class BukkitVersionHelperCB extends BukkitVersionHelperGeneric { nmschunk = getNMSClass("net.minecraft.server.Chunk"); nmsc_removeentities = getMethod(nmschunk, new String[] { "removeEntities" }, new Class[0]); 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) { Log.info("inhabitedTicks field not found - inhabited shader not functional"); } @@ -111,9 +112,18 @@ public class BukkitVersionHelperCB extends BukkitVersionHelperGeneric { /** Tile entity */ nms_tileentity = getNMSClass("net.minecraft.server.TileEntity"); nmst_readnbt = getMethod(nms_tileentity, new String[] { "b" }, new Class[] { nbttagcompound }); - 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); + nmst_getposition = getMethodNoFail(nms_tileentity, new String[] { "getPosition" }, new Class[0]); // Try 1.8 method + if (nmst_getposition == null) { + 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 public void unloadChunkNoSave(World w, Chunk c, int cx, int cz) { diff --git a/src/main/java/org/dynmap/bukkit/BukkitVersionHelperGeneric.java b/src/main/java/org/dynmap/bukkit/BukkitVersionHelperGeneric.java index c50a3323..9cc7e518 100644 --- a/src/main/java/org/dynmap/bukkit/BukkitVersionHelperGeneric.java +++ b/src/main/java/org/dynmap/bukkit/BukkitVersionHelperGeneric.java @@ -83,6 +83,13 @@ public abstract class BukkitVersionHelperGeneric extends BukkitVersionHelper { protected Field nmst_x; protected Field nmst_y; 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 */ protected Method server_getonlineplayers; /** Player */ @@ -231,6 +238,17 @@ public abstract class BukkitVersionHelperGeneric extends BukkitVersionHelper { failed = true; 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) { if((obj == null) || (meth == null)) { return def; @@ -333,19 +351,37 @@ public abstract class BukkitVersionHelperGeneric extends BukkitVersionHelper { * Get X coordinate of tile entity */ 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 */ 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 */ 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 From 274a363a974983444f140ef30086c1fa57dcc3d6 Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Sun, 14 Dec 2014 20:49:38 -0600 Subject: [PATCH 05/12] Avoid trap in Spigot for light levels outside max height --- src/main/java/org/dynmap/bukkit/BukkitWorld.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/dynmap/bukkit/BukkitWorld.java b/src/main/java/org/dynmap/bukkit/BukkitWorld.java index d83b956f..485b88d1 100644 --- a/src/main/java/org/dynmap/bukkit/BukkitWorld.java +++ b/src/main/java/org/dynmap/bukkit/BukkitWorld.java @@ -11,6 +11,7 @@ import java.util.List; import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.World; +import org.bukkit.block.Block; import org.bukkit.permissions.Permission; import org.bukkit.permissions.PermissionDefault; import org.dynmap.DynmapChunk; @@ -124,7 +125,10 @@ public class BukkitWorld extends DynmapWorld { @Override public int getLightLevel(int x, int y, int z) { if(world != null) { - return world.getBlockAt(x, y, z).getLightLevel(); + if ((y >= 0) && (y < this.worldheight)) { + return world.getBlockAt(x, y, z).getLightLevel(); + } + return 0; } else { return -1; @@ -149,7 +153,12 @@ public class BukkitWorld extends DynmapWorld { @Override public int getSkyLightLevel(int x, int y, int z) { if(world != null) { - return world.getBlockAt(x, y, z).getLightFromSky(); + if ((y >= 0) && (y < this.worldheight)) { + return world.getBlockAt(x, y, z).getLightFromSky(); + } + else { + return 15; + } } else { return -1; From 41d1de1fbb59a03098832006e568b581b82d74aa Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Sat, 3 Jan 2015 17:23:40 -0600 Subject: [PATCH 06/12] Fix biome temp/humidity on newer biomes --- .../java/org/dynmap/bukkit/DynmapPlugin.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/dynmap/bukkit/DynmapPlugin.java b/src/main/java/org/dynmap/bukkit/DynmapPlugin.java index c0121a7e..72096b56 100644 --- a/src/main/java/org/dynmap/bukkit/DynmapPlugin.java +++ b/src/main/java/org/dynmap/bukkit/DynmapPlugin.java @@ -718,19 +718,24 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI { Object[] biomelist = helper.getBiomeBaseList(); /* Loop through list, skipping well known biomes */ for(int i = 0; i < biomelist.length; i++) { - if (!BiomeMap.byBiomeID(i).isDefault()) continue; Object bb = biomelist[i]; if(bb != null) { - String id = helper.getBiomeBaseIDString(bb); - if(id == null) { - id = "BIOME_" + i; - } float tmp = helper.getBiomeBaseTemperature(bb); float hum = helper.getBiomeBaseHumidity(bb); - - BiomeMap m = new BiomeMap(i, id, tmp, hum); - Log.verboseinfo("Add custom biome [" + m.toString() + "] (" + i + ")"); - cnt++; + BiomeMap bmap = BiomeMap.byBiomeID(i); + if (bmap.isDefault()) { + String id = helper.getBiomeBaseIDString(bb); + if(id == null) { + id = "BIOME_" + i; + } + BiomeMap m = new BiomeMap(i, id, tmp, hum); + Log.verboseinfo("Add custom biome [" + m.toString() + "] (" + i + ")"); + cnt++; + } + else { + bmap.setTemperature(tmp); + bmap.setRainfall(hum); + } } } if(cnt > 0) { From f80b456b2c073911665675cfd89c42062c7344af Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Mon, 5 Jan 2015 23:02:09 -0600 Subject: [PATCH 07/12] Shift marker persistence off of server thread (lag reduction) --- src/main/java/org/dynmap/bukkit/DynmapPlugin.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/org/dynmap/bukkit/DynmapPlugin.java b/src/main/java/org/dynmap/bukkit/DynmapPlugin.java index 72096b56..2884c26d 100644 --- a/src/main/java/org/dynmap/bukkit/DynmapPlugin.java +++ b/src/main/java/org/dynmap/bukkit/DynmapPlugin.java @@ -256,6 +256,11 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI { return true; return false; } + @Override + public boolean isServerThread() { + return Bukkit.getServer().isPrimaryThread(); + } + @Override public String stripChatColor(String s) { return ChatColor.stripColor(s); From 2e5d27d0d542befa1415dac104ce5a26ce88f3d6 Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Fri, 9 Jan 2015 18:38:52 -0600 Subject: [PATCH 08/12] Bump to 2.2 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9c46d4bb..236576f6 100644 --- a/pom.xml +++ b/pom.xml @@ -154,5 +154,5 @@ 2.10.1 - 2.1-SNAPSHOT + 2.2-SNAPSHOT From ac1d4a8af0ac920ff1688366123062378ffd482b Mon Sep 17 00:00:00 2001 From: Tiger Oakes Date: Tue, 3 Feb 2015 09:08:55 -1000 Subject: [PATCH 09/12] Changed default "skin-url" value With the new skin system introduced in 1.7.10/1.8, Mojang now hosts skins under the minecraft.net domain instead of Amazon's. Since the Amazon link now only provides outdated skins, it would be better to use the new skins.minecraft.net URL as default. --- src/main/resources/configuration.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/configuration.txt b/src/main/resources/configuration.txt index b1d8c1c6..b4d27082 100644 --- a/src/main/resources/configuration.txt +++ b/src/main/resources/configuration.txt @@ -274,7 +274,7 @@ custom-colors-support: true #refreshskins: false # Customize URL used for fetching player skins (%player% is macro for name) -skin-url: "http://s3.amazonaws.com/MinecraftSkins/%player%.png" +skin-url: "http://skins.minecraft.net/MinecraftSkins/%player%.png" # Control behavior for new (1.0+) compass orientation (sunrise moved 90 degrees: east is now what used to be south) # default is 'newrose' (preserve pre-1.0 maps, rotate rose) @@ -473,4 +473,4 @@ verbose: false #debuggers: # - class: org.dynmap.debug.LogDebugger # Debug: dump blocks missing render data -dump-missing-blocks: false \ No newline at end of file +dump-missing-blocks: false From 0a4b1fd14bae41964c4be707f5e249406433b0c6 Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Sun, 15 Feb 2015 12:40:30 -0600 Subject: [PATCH 10/12] Add showworldborder setting, 1.8 vanilla world border support --- .../dynmap/bukkit/BukkitVersionHelper.java | 5 +++ .../dynmap/bukkit/BukkitVersionHelperCB.java | 43 ++++++++++++++++++- .../bukkit/BukkitVersionHelperGeneric.java | 11 +++-- .../java/org/dynmap/bukkit/BukkitWorld.java | 6 ++- .../java/org/dynmap/bukkit/DynmapPlugin.java | 5 +++ src/main/resources/configuration.txt | 2 + 6 files changed, 67 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/dynmap/bukkit/BukkitVersionHelper.java b/src/main/java/org/dynmap/bukkit/BukkitVersionHelper.java index 6dbcefce..21c57b1d 100644 --- a/src/main/java/org/dynmap/bukkit/BukkitVersionHelper.java +++ b/src/main/java/org/dynmap/bukkit/BukkitVersionHelper.java @@ -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; } } diff --git a/src/main/java/org/dynmap/bukkit/BukkitVersionHelperCB.java b/src/main/java/org/dynmap/bukkit/BukkitVersionHelperCB.java index 55c72792..a48bf1b6 100644 --- a/src/main/java/org/dynmap/bukkit/BukkitVersionHelperCB.java +++ b/src/main/java/org/dynmap/bukkit/BukkitVersionHelperCB.java @@ -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; + } } diff --git a/src/main/java/org/dynmap/bukkit/BukkitVersionHelperGeneric.java b/src/main/java/org/dynmap/bukkit/BukkitVersionHelperGeneric.java index 9cc7e518..ee54e5fd 100644 --- a/src/main/java/org/dynmap/bukkit/BukkitVersionHelperGeneric.java +++ b/src/main/java/org/dynmap/bukkit/BukkitVersionHelperGeneric.java @@ -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; } diff --git a/src/main/java/org/dynmap/bukkit/BukkitWorld.java b/src/main/java/org/dynmap/bukkit/BukkitWorld.java index 485b88d1..41b096e1 100644 --- a/src/main/java/org/dynmap/bukkit/BukkitWorld.java +++ b/src/main/java/org/dynmap/bukkit/BukkitWorld.java @@ -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); + } } diff --git a/src/main/java/org/dynmap/bukkit/DynmapPlugin.java b/src/main/java/org/dynmap/bukkit/DynmapPlugin.java index 2884c26d..3fca3595 100644 --- a/src/main/java/org/dynmap/bukkit/DynmapPlugin.java +++ b/src/main/java/org/dynmap/bukkit/DynmapPlugin.java @@ -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); + } } diff --git a/src/main/resources/configuration.txt b/src/main/resources/configuration.txt index b1d8c1c6..5a9f88e2 100644 --- a/src/main/resources/configuration.txt +++ b/src/main/resources/configuration.txt @@ -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 From 3126de8eec841ae39524880a750b81a07afa867f Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Sun, 12 Jul 2015 20:29:37 -0500 Subject: [PATCH 11/12] Bump to 2.2 GA --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 236576f6..8630f323 100644 --- a/pom.xml +++ b/pom.xml @@ -154,5 +154,5 @@ 2.10.1 - 2.2-SNAPSHOT + 2.2 From d579879fbcf3c724ef8b7ca0228b50283bc3063f Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Sun, 12 Jul 2015 22:55:06 -0500 Subject: [PATCH 12/12] Bump to 2.3-SNAPSHOT --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 8630f323..4cb5af87 100644 --- a/pom.xml +++ b/pom.xml @@ -154,5 +154,5 @@ 2.10.1 - 2.2 + 2.3-SNAPSHOT