Add supporting code to help with CTM support (block names, biome names)

This commit is contained in:
Mike Primm 2013-04-18 01:20:59 -05:00
parent bcd0acec33
commit 7c6e660cf0
4 changed files with 61 additions and 3 deletions

View File

@ -116,4 +116,12 @@ public abstract class BukkitVersionHelper {
* Unload chunk no save needed * Unload chunk no save needed
*/ */
public abstract void unloadChunkNoSave(World w, Chunk c, int cx, int cz); public abstract void unloadChunkNoSave(World w, Chunk c, int cx, int cz);
/**
* Get block short name list
*/
public abstract String[] getBlockShortNames();
/**
* Get biome name list
*/
public abstract String[] getBiomeNames();
} }

View File

@ -1,5 +1,6 @@
package org.dynmap.bukkit; package org.dynmap.bukkit;
import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Map; import java.util.Map;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -7,12 +8,17 @@ import org.bukkit.Chunk;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.World; import org.bukkit.World;
import org.dynmap.Log; import org.dynmap.Log;
import org.dynmap.common.BiomeMap;
/** /**
* Helper for isolation of bukkit version specific issues * Helper for isolation of bukkit version specific issues
*/ */
public class BukkitVersionHelperCB extends BukkitVersionHelperGeneric { public class BukkitVersionHelperCB extends BukkitVersionHelperGeneric {
private Class<?> nmsblock;
private Class<?> nmsblockarray;
private Field blockbyid;
private Field blockname;
BukkitVersionHelperCB() { BukkitVersionHelperCB() {
} }
@Override @Override
@ -30,6 +36,12 @@ public class BukkitVersionHelperCB extends BukkitVersionHelperGeneric {
} }
@Override @Override
protected void loadNMS() { protected void loadNMS() {
// Get block fields
nmsblock = getNMSClass("net.minecraft.server.Block");
nmsblockarray = getNMSClass("[Lnet.minecraft.server.Block;");
blockbyid = getField(nmsblock, new String[] { "byId" }, nmsblockarray);
blockname = getPrivateField(nmsblock, new String[] { "name" }, String.class);
/* Set up biomebase fields */ /* Set up biomebase fields */
biomebase = getNMSClass("net.minecraft.server.BiomeBase"); biomebase = getNMSClass("net.minecraft.server.BiomeBase");
biomebasearray = getNMSClass("[Lnet.minecraft.server.BiomeBase;"); biomebasearray = getNMSClass("[Lnet.minecraft.server.BiomeBase;");
@ -94,5 +106,41 @@ public class BukkitVersionHelperCB extends BukkitVersionHelperGeneric {
this.removeEntitiesFromChunk(c); this.removeEntitiesFromChunk(c);
w.unloadChunk(cx, cz, false, false); w.unloadChunk(cx, cz, false, false);
} }
/**
* Get block short name list
*/
@Override
public String[] getBlockShortNames() {
try {
Object[] byid = (Object[])blockbyid.get(nmsblock);
String[] names = new String[byid.length];
for (int i = 0; i < names.length; i++) {
if (byid[i] != null) {
names[i] = (String)blockname.get(byid[i]);
}
}
return names;
} catch (IllegalArgumentException e) {
} catch (IllegalAccessException e) {
}
return new String[0];
}
/**
* Get biome name list
*/
@Override
public String[] getBiomeNames() {
String[] names;
/* Find array of biomes in biomebase */
Object[] biomelist = getBiomeBaseList();
names = new String[biomelist.length];
/* Loop through list, starting afer well known biomes */
for(int i = 0; i < biomelist.length; i++) {
Object bb = biomelist[i];
if(bb != null) {
names[i] = getBiomeBaseIDString(bb);
}
}
return names;
}
} }

View File

@ -174,7 +174,7 @@ public abstract class BukkitVersionHelperGeneric extends BukkitVersionHelper {
/** /**
* Get private field * Get private field
*/ */
private Field getPrivateField(Class<?> cls, String[] ids, Class<?> type) { protected Field getPrivateField(Class<?> cls, String[] ids, Class<?> type) {
if((cls == null) || (type == null)) return null; if((cls == null) || (type == null)) return null;
for(String id : ids) { for(String id : ids) {
try { try {

View File

@ -749,6 +749,8 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
core.setMinecraftVersion(mcver); core.setMinecraftVersion(mcver);
core.setDataFolder(dataDirectory); core.setDataFolder(dataDirectory);
core.setServer(new BukkitServer()); core.setServer(new BukkitServer());
core.setBlockNames(helper.getBlockShortNames());
core.setBiomeNames(helper.getBiomeNames());
/* Load configuration */ /* Load configuration */
if(!core.initConfiguration(enabCoreCB)) { if(!core.initConfiguration(enabCoreCB)) {