Search in sources :

Example 1 with CommonTag

use of com.bergerkiller.bukkit.common.nbt.CommonTag in project BKCommonLib by bergerhealer.

the class NBTTest method testNBTCreateTagForData.

@Test
public void testNBTCreateTagForData() {
    CommonTag tag;
    tag = CommonTag.createForData("String");
    assertTrue(NBTBaseHandle.NBTTagStringHandle.class.isAssignableFrom(tag.getBackingHandle().getClass()));
    assertEquals("String", tag.getData());
    tag = CommonTag.createForData((byte) 12);
    assertTrue(NBTBaseHandle.NBTTagByteHandle.class.isAssignableFrom(tag.getBackingHandle().getClass()));
    assertEquals((byte) 12, tag.getData());
    tag = CommonTag.createForData((short) 12);
    assertTrue(NBTBaseHandle.NBTTagShortHandle.class.isAssignableFrom(tag.getBackingHandle().getClass()));
    assertEquals((short) 12, tag.getData());
    tag = CommonTag.createForData(12);
    assertTrue(NBTBaseHandle.NBTTagIntHandle.class.isAssignableFrom(tag.getBackingHandle().getClass()));
    assertEquals(12, tag.getData());
    tag = CommonTag.createForData(12L);
    assertTrue(NBTBaseHandle.NBTTagLongHandle.class.isAssignableFrom(tag.getBackingHandle().getClass()));
    assertEquals(12L, tag.getData());
    tag = CommonTag.createForData(12F);
    assertTrue(NBTBaseHandle.NBTTagFloatHandle.class.isAssignableFrom(tag.getBackingHandle().getClass()));
    assertEquals(12F, tag.getData());
    tag = CommonTag.createForData(12D);
    assertTrue(NBTBaseHandle.NBTTagDoubleHandle.class.isAssignableFrom(tag.getBackingHandle().getClass()));
    assertEquals(12D, tag.getData());
    tag = CommonTag.createForData(new byte[] { 12, 13, 14 });
    assertTrue(NBTBaseHandle.NBTTagByteArrayHandle.class.isAssignableFrom(tag.getBackingHandle().getClass()));
    assertTrue(Arrays.equals(new byte[] { 12, 13, 14 }, (byte[]) tag.getData()));
    tag = CommonTag.createForData(new int[] { 12, 13, 14 });
    assertTrue(NBTBaseHandle.NBTTagIntArrayHandle.class.isAssignableFrom(tag.getBackingHandle().getClass()));
    assertTrue(Arrays.equals(new int[] { 12, 13, 14 }, (int[]) tag.getData()));
    if (NBTBaseHandle.NBTTagLongArrayHandle.T.isAvailable()) {
        tag = CommonTag.createForData(new long[] { 12, 13, 14 });
        assertTrue(NBTBaseHandle.NBTTagLongArrayHandle.class.isAssignableFrom(tag.getBackingHandle().getClass()));
        assertTrue(Arrays.equals(new long[] { 12, 13, 14 }, (long[]) tag.getData()));
    }
    // List with 3 values. Verify the second value is NBTTagInt with value 13
    tag = CommonTag.createForData(Arrays.asList(12, 13, 14));
    assertTrue(tag instanceof CommonTagList);
    assertTrue(NBTTagListHandle.class.isAssignableFrom(tag.getBackingHandle().getClass()));
    CommonTagList tag_list = (CommonTagList) tag;
    assertEquals(3, tag_list.size());
    tag = tag_list.get(1);
    assertTrue(NBTBaseHandle.NBTTagIntHandle.class.isAssignableFrom(tag.getBackingHandle().getClass()));
    assertEquals(13, tag.getData());
}
Also used : CommonTagList(com.bergerkiller.bukkit.common.nbt.CommonTagList) CommonTag(com.bergerkiller.bukkit.common.nbt.CommonTag) NBTTagListHandle(com.bergerkiller.generated.net.minecraft.nbt.NBTTagListHandle) Test(org.junit.Test)

Aggregations

CommonTag (com.bergerkiller.bukkit.common.nbt.CommonTag)1 CommonTagList (com.bergerkiller.bukkit.common.nbt.CommonTagList)1 NBTTagListHandle (com.bergerkiller.generated.net.minecraft.nbt.NBTTagListHandle)1 Test (org.junit.Test)1