Updated Bukkit dependency to 1.3.1-R2.0, added backwards support for NBT access.

Dieser Commit ist enthalten in:
sk89q 2012-08-24 06:43:24 -07:00
Ursprung 41cb2bf3fa
Commit 885b48c15e
2 geänderte Dateien mit 40 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -58,13 +58,13 @@
<dependency> <dependency>
<groupId>org.bukkit</groupId> <groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId> <artifactId>bukkit</artifactId>
<version>1.2.5-R4.1-SNAPSHOT</version> <version>1.3.1-R2.0</version>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.bukkit</groupId> <groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId> <artifactId>craftbukkit</artifactId>
<version>1.2.5-R4.1-SNAPSHOT</version> <version>1.3.1-R2.0</version>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>

Datei anzeigen

@ -18,10 +18,13 @@
package com.sk89q.worldedit.bukkit; package com.sk89q.worldedit.bukkit;
import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.logging.Logger;
import net.minecraft.server.NBTBase; import net.minecraft.server.NBTBase;
import net.minecraft.server.NBTTagByte; import net.minecraft.server.NBTTagByte;
@ -70,6 +73,8 @@ import com.sk89q.worldedit.foundation.Block;
*/ */
class NmsBlock extends BaseBlock implements TileEntityBlock { class NmsBlock extends BaseBlock implements TileEntityBlock {
private static final Logger logger = Logger.getLogger(NmsBlock.class.getCanonicalName());
private static Field compoundMapField;
private NBTTagCompound nbtData = null; private NBTTagCompound nbtData = null;
/** /**
@ -247,13 +252,45 @@ class NmsBlock extends BaseBlock implements TileEntityBlock {
* @param foreign non-native NMS NBT structure * @param foreign non-native NMS NBT structure
* @return native WorldEdit NBT structure * @return native WorldEdit NBT structure
*/ */
@SuppressWarnings("unchecked")
private static Tag toNative(NBTBase foreign) { private static Tag toNative(NBTBase foreign) {
if (foreign == null) { if (foreign == null) {
return null; return null;
} }
if (foreign instanceof NBTTagCompound) { if (foreign instanceof NBTTagCompound) {
Map<String, Tag> values = new HashMap<String, Tag>(); Map<String, Tag> values = new HashMap<String, Tag>();
for (Object obj : ((NBTTagCompound) foreign).d()) { Collection<Object> foreignValues = null;
if (compoundMapField == null) {
try {
// Method name may change!
foreignValues = ((NBTTagCompound) foreign).c();
} catch (Throwable t) {
try {
logger.warning("WorldEdit: Couldn't get NBTTagCompound.c(), " +
"so we're going to try to get at the 'map' field directly from now on");
if (compoundMapField == null) {
compoundMapField = NBTTagCompound.class.getDeclaredField("map");
compoundMapField.setAccessible(true);
}
} catch (Throwable e) {
// Can't do much beyond this
throw new RuntimeException(e);
}
}
}
if (compoundMapField != null) {
try {
foreignValues = ((HashMap<Object, Object>) compoundMapField.get(foreign)).values();
} catch (Throwable e) {
// Can't do much beyond this
throw new RuntimeException(e);
}
}
for (Object obj : foreignValues) {
NBTBase base = (NBTBase) obj; NBTBase base = (NBTBase) obj;
values.put(base.getName(), toNative(base)); values.put(base.getName(), toNative(base));
} }