From 13974fd2811907378566a0cbe9b4c3fcd24b01de Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Mon, 6 Feb 2012 23:22:50 -0600 Subject: [PATCH] Update for 1.1-R3 - use native getLightFromSky and getLightFromBlocks APIs --- pom.xml | 2 +- .../java/org/dynmap/mobs/BlockLightLevel.java | 79 ------------------- .../org/dynmap/mobs/DynmapMobsPlugin.java | 19 ++--- 3 files changed, 8 insertions(+), 92 deletions(-) delete mode 100644 src/main/java/org/dynmap/mobs/BlockLightLevel.java diff --git a/pom.xml b/pom.xml index 321317c..67b2b19 100644 --- a/pom.xml +++ b/pom.xml @@ -54,7 +54,7 @@ org.bukkit bukkit - [1.0.0-R1-SNAPSHOT,) + [1.1-R3-SNAPSHOT,) compile diff --git a/src/main/java/org/dynmap/mobs/BlockLightLevel.java b/src/main/java/org/dynmap/mobs/BlockLightLevel.java deleted file mode 100644 index bb4bb08..0000000 --- a/src/main/java/org/dynmap/mobs/BlockLightLevel.java +++ /dev/null @@ -1,79 +0,0 @@ -package org.dynmap.mobs; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -import org.bukkit.block.Block; - -/** - * Wrapper for accessing raw light levels for given block - */ -public class BlockLightLevel { - private Method gethandle; - private Method getrawlight; - private Object enum_sky; - private Object enum_block; - private boolean ready; - - @SuppressWarnings({ "unchecked", "rawtypes" }) - public BlockLightLevel() { - /* Get CraftChunk.getChunkSnapshot(boolean,boolean,boolean) and CraftChunk.getHandle() */ - try { - Class c = Class.forName("org.bukkit.craftbukkit.CraftChunk"); - gethandle = c.getDeclaredMethod("getHandle", new Class[0]); - Class enumskyblock = Class.forName("net.minecraft.server.EnumSkyBlock"); - Object[] enumvals = enumskyblock.getEnumConstants(); - for(int i = 0; i < enumvals.length; i++) { - String ev = enumvals[i].toString(); - if(ev.equals("Sky")) { - enum_sky = enumvals[i]; - } - else if(ev.equals("Block")) { - enum_block = enumvals[i]; - } - } - Class cc = Class.forName("net.minecraft.server.Chunk"); - getrawlight = cc.getDeclaredMethod("a", new Class[] { enumskyblock, int.class, int.class, int.class }); - } catch (ClassNotFoundException cnfx) { - } catch (NoSuchMethodException nsmx) { - } - if((gethandle != null) && (enum_sky != null) && (enum_block != null) && (getrawlight != null)) { - ready = true; - } - else { - DynmapMobsPlugin.info("Block raw light level API not available"); - } - } - - public boolean isReady() { - return ready; - } - - public int getSkyLightLevel(Block b) { - try { - Object hand = gethandle.invoke(b.getChunk()); - if(hand != null) { - Integer v = (Integer)getrawlight.invoke(hand, enum_sky, b.getX() & 0xF, b.getY() & 0x7F, b.getZ() & 0xF); - return v; - } - } catch (InvocationTargetException itx) { - } catch (IllegalArgumentException e) { - } catch (IllegalAccessException e) { - } - return -1; - } - - public int getBlockLightLevel(Block b) { - try { - Object hand = gethandle.invoke(b.getChunk()); - if(hand != null) { - Integer v = (Integer)getrawlight.invoke(hand, enum_block, b.getX() & 0xF, b.getY() & 0x7F, b.getZ() & 0xF); - return v; - } - } catch (InvocationTargetException itx) { - } catch (IllegalArgumentException e) { - } catch (IllegalAccessException e) { - } - return -1; - } -} diff --git a/src/main/java/org/dynmap/mobs/DynmapMobsPlugin.java b/src/main/java/org/dynmap/mobs/DynmapMobsPlugin.java index 7151431..558a20e 100644 --- a/src/main/java/org/dynmap/mobs/DynmapMobsPlugin.java +++ b/src/main/java/org/dynmap/mobs/DynmapMobsPlugin.java @@ -8,6 +8,7 @@ import org.bukkit.Location; import org.bukkit.OfflinePlayer; import org.bukkit.World; +import org.bukkit.block.Block; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.AnimalTamer; import org.bukkit.entity.LivingEntity; @@ -41,7 +42,6 @@ public class DynmapMobsPlugin extends JavaPlugin { boolean tinyicons; boolean nolabels; boolean stop; - BlockLightLevel bll = new BlockLightLevel(); /* Mapping of mobs to icons */ private static class MobMapping { @@ -140,22 +140,17 @@ else if(mobs[i].mobid.equals("wolf")) { /* Check for tamed wolf */ continue; Location loc = le.getLocation(); - + Block blk = null; if(hideifshadow < 15) { - if(loc.getBlock().getLightLevel() <= hideifshadow) { + blk = loc.getBlock(); + if(blk.getLightLevel() <= hideifshadow) { continue; } } if(hideifundercover < 15) { - if(bll.isReady()) { - if(bll.getSkyLightLevel(loc.getBlock()) <= hideifundercover) { - continue; - } - } - else { - if(loc.getWorld().getHighestBlockYAt(loc) > loc.getBlockY()) { - continue; - } + if(blk == null) blk = loc.getBlock(); + if(blk.getLightFromSky() <= hideifundercover) { + continue; } }