Archiviert
13
0

Add block data to the cloning mechanism

Dieser Commit ist enthalten in:
Dan Mulloy 2016-06-30 12:34:13 -04:00
Ursprung a88347dfe6
Commit a995866d5b
2 geänderte Dateien mit 18 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -25,6 +25,7 @@ import com.comphenix.protocol.wrappers.BlockPosition;
import com.comphenix.protocol.wrappers.BukkitConverters;
import com.comphenix.protocol.wrappers.ChunkPosition;
import com.comphenix.protocol.wrappers.MinecraftKey;
import com.comphenix.protocol.wrappers.WrappedBlockData;
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
import com.comphenix.protocol.wrappers.WrappedServerPing;
import com.google.common.collect.Maps;
@ -61,6 +62,11 @@ public class BukkitCloner implements Cloner {
addClass(5, MinecraftReflection.getDataWatcherSerializerClass());
addClass(6, MinecraftReflection.getMinecraftKeyClass());
}
try {
addClass(7, MinecraftReflection.getIBlockDataClass());
} catch (Throwable ex) {
}
}
private void addClass(int id, Class<?> clazz) {
@ -112,7 +118,10 @@ public class BukkitCloner implements Cloner {
return source;
case 6:
EquivalentConverter<MinecraftKey> keyConverter = MinecraftKey.getConverter();
return keyConverter.getGeneric(clonableClasses.get(5), keyConverter.getSpecific(source));
return keyConverter.getGeneric(clonableClasses.get(6), keyConverter.getSpecific(source));
case 7:
EquivalentConverter<WrappedBlockData> blockDataConverter = BukkitConverters.getWrappedBlockDataConverter();
return blockDataConverter.getGeneric(clonableClasses.get(7), blockDataConverter.getSpecific(source).deepClone());
default:
throw new IllegalArgumentException("Cannot clone objects of type " + source.getClass());
}

Datei anzeigen

@ -149,6 +149,14 @@ public class WrappedBlockData extends AbstractWrapper {
return new WrappedBlockData(blockData);
}
/**
* Retrieve a deep copy of the current wrapper object.
* @return The cloned object.
*/
public WrappedBlockData deepClone() {
return WrappedBlockData.createData(getType(), getData());
}
@Override
public String toString() {
return "WrappedBlockData[handle=" + handle + "]";