Archiviert
13
0

Ensure that we can create compounds and lists.

Dieser Commit ist enthalten in:
Kristian S. Stangeland 2013-01-07 20:15:21 +01:00
Ursprung 671654aaaf
Commit 8abb93114f
4 geänderte Dateien mit 38 neuen und 12 gelöschten Zeilen

Datei anzeigen

@ -36,10 +36,10 @@ public class NbtCompound implements NbtWrapper<Map<String, NbtBase<?>>>, Iterabl
* @param list - the list of elements to add. * @param list - the list of elements to add.
* @return The new wrapped NBT compound. * @return The new wrapped NBT compound.
*/ */
public static <T> NbtCompound fromList(String name, Collection<? extends NbtBase<T>> list) { public static NbtCompound fromList(String name, Collection<? extends NbtBase<?>> list) {
NbtCompound copy = new NbtCompound(name); NbtCompound copy = fromName(name);
for (NbtBase<T> base : list) for (NbtBase<?> base : list)
copy.getValue().put(base.getName(), base); copy.getValue().put(base.getName(), base);
return copy; return copy;
} }
@ -80,14 +80,6 @@ public class NbtCompound implements NbtWrapper<Map<String, NbtBase<?>>>, Iterabl
return getValue().keySet(); return getValue().keySet();
} }
/**
* Retrieve a Collection view of the entries in this compound.
* @return A view of each NBT tag in this compound.
*/
public Collection<NbtBase<?>> asCollection(){
return getValue().values();
}
@Override @Override
public Map<String, NbtBase<?>> getValue() { public Map<String, NbtBase<?>> getValue() {
// Return a wrapper map // Return a wrapper map

Datei anzeigen

@ -165,10 +165,19 @@ public class NbtFactory {
* @param list - the list of elements to add. * @param list - the list of elements to add.
* @return The new wrapped NBT compound. * @return The new wrapped NBT compound.
*/ */
public static <T> NbtCompound ofCompound(String name, Collection<? extends NbtBase<T>> list) { public static NbtCompound ofCompound(String name, Collection<? extends NbtBase<?>> list) {
return NbtCompound.fromList(name, list); return NbtCompound.fromList(name, list);
} }
/**
* Construct a new NBT compound wrapper.
* @param name - the name of the compound wrapper.
* @return The new wrapped NBT compound.
*/
public static NbtCompound ofCompound(String name) {
return NbtCompound.fromName(name);
}
/** /**
* Construct a NBT list of out an array of values. * Construct a NBT list of out an array of values.
* @param name - name of this list. * @param name - name of this list.

Datei anzeigen

@ -4,6 +4,8 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import com.google.common.primitives.Primitives;
/** /**
* Represents all the element types * Represents all the element types
* *
@ -88,6 +90,11 @@ public enum NbtType {
for (NbtType type : values) { for (NbtType type : values) {
lookup[type.getRawID()] = type; lookup[type.getRawID()] = type;
classLookup.put(type.getValueType(), type); classLookup.put(type.getValueType(), type);
// Add a wrapper type
if (type.getValueType().isPrimitive()) {
classLookup.put(Primitives.wrap(type.getValueType()), type);
}
} }
} }

Datei anzeigen

@ -32,6 +32,8 @@ import com.comphenix.protocol.wrappers.BukkitConverters;
import com.comphenix.protocol.wrappers.ChunkPosition; import com.comphenix.protocol.wrappers.ChunkPosition;
import com.comphenix.protocol.wrappers.WrappedDataWatcher; import com.comphenix.protocol.wrappers.WrappedDataWatcher;
import com.comphenix.protocol.wrappers.WrappedWatchableObject; import com.comphenix.protocol.wrappers.WrappedWatchableObject;
import com.comphenix.protocol.wrappers.nbt.NbtCompound;
import com.comphenix.protocol.wrappers.nbt.NbtFactory;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
@ -233,6 +235,22 @@ public class PacketContainerTest {
assertEquals(testValue, worldAccess.read(0)); assertEquals(testValue, worldAccess.read(0));
} }
@Test
public void testGetNbtModifier() {
PacketContainer updateTileEntity = new PacketContainer(132);
NbtCompound compound = NbtFactory.ofCompound("test");
compound.put("test", "name");
compound.put(NbtFactory.ofList("ages", 1, 2, 3));
updateTileEntity.getNbtModifier().write(0, compound);
NbtCompound result = (NbtCompound) updateTileEntity.getNbtModifier().read(0);
assertEquals(compound.getString("test"), result.getString("test"));
assertEquals(compound.getList("ages"), result.getList("ages"));
}
@Test @Test
public void testGetDataWatcherModifier() { public void testGetDataWatcherModifier() {
PacketContainer mobSpawnPacket = new PacketContainer(Packets.Server.MOB_SPAWN); PacketContainer mobSpawnPacket = new PacketContainer(Packets.Server.MOB_SPAWN);