Strip out obsolete pre 1.1 bukkit workarounds, fixes

This commit is contained in:
Mike Primm 2012-02-14 20:54:36 -06:00
parent 71185b06d6
commit 5ad4ba285b
3 changed files with 2 additions and 133 deletions

View File

@ -1,80 +0,0 @@
package org.dynmap.bukkit;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.bukkit.block.Block;
import org.dynmap.Log;
/**
* 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 {
Log.warning("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;
}
}

View File

@ -13,7 +13,6 @@ import org.dynmap.utils.MapChunkCache;
public class BukkitWorld extends DynmapWorld {
private World world;
private static BlockLightLevel bll = new BlockLightLevel();
public BukkitWorld(World w) {
super(w.getName(), w.getMaxHeight());
@ -67,12 +66,12 @@ public class BukkitWorld extends DynmapWorld {
/* Test if sky light level is requestable */
@Override
public boolean canGetSkyLightLevel() {
return bll.isReady();
return true;
}
/* Return sky light level */
@Override
public int getSkyLightLevel(int x, int y, int z) {
return bll.getSkyLightLevel(world.getBlockAt(x, y, z));
return world.getBlockAt(x, y, z).getLightFromSky();
}
/**
* Get world environment ID (lower case - normal, the_end, nether)

View File

@ -6,19 +6,16 @@ import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
import java.util.TreeSet;
import org.bukkit.World;
import org.bukkit.Chunk;
import org.bukkit.block.Biome;
import org.bukkit.entity.Entity;
import org.bukkit.ChunkSnapshot;
import org.dynmap.DynmapAPI;
import org.dynmap.DynmapChunk;
import org.dynmap.DynmapCore;
import org.dynmap.DynmapWorld;
import org.dynmap.Log;
import org.dynmap.MapManager;
import org.dynmap.common.BiomeMap;
import org.dynmap.utils.MapChunkCache;
import org.dynmap.utils.MapIterator;
@ -35,13 +32,8 @@ public class NewMapChunkCache implements MapChunkCache {
private static Method removeentities = null;
private static Method getworldhandle = null;
private static Field chunkbiome = null;
private static Field ticklist = null;
private static Method processticklist = null;
private static boolean use_spout = false;
private static final int MAX_PROCESSTICKS = 20;
private static final int MAX_TICKLIST = 20000;
private World w;
private DynmapWorld dw;
private Object craftworld;
@ -57,7 +49,6 @@ public class NewMapChunkCache implements MapChunkCache {
private boolean do_save = false;
private boolean isempty = true;
private ChunkSnapshot[] snaparray; /* Index = (x-x_min) + ((z-z_min)*x_dim) */
private TreeSet<?> ourticklist;
private byte[][] swampcnt;
private BiomeMap[][] biomemap;
@ -520,22 +511,6 @@ public class NewMapChunkCache implements MapChunkCache {
} catch (ClassNotFoundException cnfx) {
} catch (NoSuchFieldException nsmx) {
}
/* ticklist for World */
try {
Class c = Class.forName("net.minecraft.server.World");
try {
ticklist = c.getDeclaredField("K"); /* 1.0.0 */
} catch (NoSuchFieldException nsfx) {
ticklist = c.getDeclaredField("N"); /* 1.8.1 */
}
ticklist.setAccessible(true);
if(ticklist.getType().isAssignableFrom(TreeSet.class) == false)
ticklist = null;
processticklist = c.getDeclaredMethod("a", new Class[] { boolean.class } );
} catch (ClassNotFoundException cnfx) {
} catch (NoSuchFieldException nsmx) {
} catch (NoSuchMethodException nsmx) {
}
use_spout = DynmapPlugin.plugin.hasSpout();
init = true;
@ -547,8 +522,6 @@ public class NewMapChunkCache implements MapChunkCache {
if((getworldhandle != null) && (craftworld == null)) {
try {
craftworld = getworldhandle.invoke(w); /* World.getHandle() */
if(ticklist != null)
ourticklist = (TreeSet<?>)ticklist.get(craftworld);
} catch (Exception x) {
}
}
@ -597,8 +570,6 @@ public class NewMapChunkCache implements MapChunkCache {
if(iterator == null)
iterator = chunks.listIterator();
checkTickList();
DynmapCore.setIgnoreChunkLoads(true);
//boolean isnormral = w.getEnvironment() == Environment.NORMAL;
// Load the required chunks.
@ -893,27 +864,6 @@ public class NewMapChunkCache implements MapChunkCache {
return exceptions;
}
private boolean checkTickList() {
boolean isok = true;
if((ourticklist != null) && (processticklist != null)) {
int cnt = 0;
int ticksize = ourticklist.size();
while((cnt < MAX_PROCESSTICKS) && (ticksize > MAX_TICKLIST) && (ourticklist.size() > MAX_TICKLIST)) {
try {
processticklist.invoke(craftworld, true);
} catch (Exception x) {
}
ticksize -= 1000;
cnt++;
MapManager.mapman.incExtraTickList();
}
if(cnt >= MAX_PROCESSTICKS) { /* If still behind, delay processing */
isok = false;
}
}
return isok;
}
static {
Biome[] b = Biome.values();
BiomeMap[] bm = BiomeMap.values();