use of com.bergerkiller.bukkit.common.nbt.CommonTagList in project BKCommonLib by bergerhealer.
the class NBTTest method testNBTListAddGetSet.
@Test
public void testNBTListAddGetSet() {
CommonTagList list = new CommonTagList();
list.addValue("one");
list.addValue("two");
assertEquals("one", list.getValue(0));
assertEquals("two", list.getValue(1));
list.setValue(0, "hello");
list.setValue(1, "world");
assertEquals("hello", list.getValue(0));
assertEquals("world", list.getValue(1));
}
use of com.bergerkiller.bukkit.common.nbt.CommonTagList in project BKCommonLib by bergerhealer.
the class ItemUtil method equalsIgnoreAmount.
/**
* Checks whether two item stacks equal, while ignoring the item amounts
*
* @param item1 to check
* @param item2 to check
* @return True if the items have the same type, data and enchantments,
* False if not
*/
public static boolean equalsIgnoreAmount(org.bukkit.inventory.ItemStack item1, org.bukkit.inventory.ItemStack item2) {
if (item1 == null || item2 == null) {
return false;
}
if (item1.getType() != item2.getType() || MaterialUtil.getRawData(item1) != MaterialUtil.getRawData(item2)) {
return false;
}
// Metadata checks
boolean hasMeta = hasMetaTag(item1);
if (hasMeta != hasMetaTag(item2)) {
return false;
} else if (!hasMeta) {
// No further data to test
return true;
}
if (!item1.getItemMeta().equals(item2.getItemMeta())) {
return false;
}
// Not included in metadata checks: Item attributes (Bukkit needs to update)
CommonTagList item1Attr = getMetaTag(item1).get("AttributeModifiers", CommonTagList.class);
CommonTagList item2Attr = getMetaTag(item2).get("AttributeModifiers", CommonTagList.class);
return LogicUtil.bothNullOrEqual(item1Attr, item2Attr);
}
use of com.bergerkiller.bukkit.common.nbt.CommonTagList in project BKCommonLib by bergerhealer.
the class NBTTest method testNBTCompoundWithList.
@Test
public void testNBTCompoundWithList() {
CommonTagCompound compound = new CommonTagCompound();
CommonTagList list = compound.createList("key");
list.addValue("Value1");
list.addValue("Value2");
assertEquals(2, list.size());
assertEquals("Value1", list.getValue(0));
assertEquals("Value2", list.getValue(1));
list = compound.get("key", CommonTagList.class);
assertNotNull(list);
assertEquals(2, list.size());
assertEquals("Value1", list.getValue(0));
assertEquals("Value2", list.getValue(1));
}
use of com.bergerkiller.bukkit.common.nbt.CommonTagList 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());
}
Aggregations