use of com.bergerkiller.bukkit.common.nbt.CommonTagCompound in project BKCommonLib by bergerhealer.
the class ItemUtil method clearLoreNames.
/**
* Removes all lores from an item that are set, if they are set
*
* @param itemStack
*/
public static void clearLoreNames(org.bukkit.inventory.ItemStack itemStack) {
CommonTagCompound meta = ItemUtil.getMetaTag(itemStack, false);
if (meta == null)
return;
CommonTagCompound display = meta.get("display", CommonTagCompound.class);
if (display == null)
return;
display.remove("Lore");
}
use of com.bergerkiller.bukkit.common.nbt.CommonTagCompound in project BKCommonLib by bergerhealer.
the class CommonMapController method handleItemSync.
/**
* Adjusts the internal remapping from UUID to Map Id taking into account the new item
* being synchronized to the player. If the item is that of a virtual map, the map Id
* of the item is updated. NBT data that should not be synchronized is dropped.
*
* @param item
* @param tileX the X-coordinate of the tile in which the item is displayed
* @param tileY the Y-coordinate of the tile in which the item is displayed
* @return True if the item was changed and needs to be updated in the packet
*/
public ItemStack handleItemSync(ItemStack item, int tileX, int tileY) {
if (!CommonMapUUIDStore.isMap(item)) {
return null;
}
// When a map UUID is specified, use that to dynamically allocate a map Id to use
CommonTagCompound tag = ItemUtil.getMetaTag(item, false);
if (tag != null) {
UUID mapUUID = tag.getUUID("mapDisplay");
if (mapUUID != null) {
item = trimExtraData(item);
int id = getMapId(new MapUUID(mapUUID, tileX, tileY));
CommonMapUUIDStore.setItemMapId(item, id);
return item;
}
}
// Static map Id MUST be enforced
int mapId = CommonMapUUIDStore.getItemMapId(item);
if (mapId != -1) {
storeStaticMapId(mapId);
}
return null;
}
use of com.bergerkiller.bukkit.common.nbt.CommonTagCompound in project BKCommonLib by bergerhealer.
the class ChunkBlockStateChangeConverter method convertInput.
@Override
public BlockStateChange convertInput(Object value) {
final ClientboundLevelChunkPacketDataHandle.BlockEntityDataHandle handle;
handle = ClientboundLevelChunkPacketDataHandle.BlockEntityDataHandle.createHandle(value);
// Deferred readout of metadata for performance, as we're using reflection
IntVector3 position = handle.getPosition(this.chunkX, this.chunkZ);
BlockStateType type = handle.getType();
CommonTagCompound initialMetadata = handle.getTag();
if (initialMetadata != null) {
// Constant value
return BlockStateChange.deferred(position, type, LogicUtil.constantSupplier(initialMetadata), () -> true);
} else {
// Initialize when first called
final DeferredSupplier<CommonTagCompound> metadataSupplier = DeferredSupplier.of(() -> {
CommonTagCompound metadata = new CommonTagCompound();
handle.setTag(metadata);
return metadata;
});
return BlockStateChange.deferred(position, type, metadataSupplier, metadataSupplier::isInitialized);
}
}
use of com.bergerkiller.bukkit.common.nbt.CommonTagCompound 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.CommonTagCompound in project BKCommonLib by bergerhealer.
the class NBTTest method testNBTCompoundGetPut.
@Test
public void testNBTCompoundGetPut() {
CommonTagCompound compound = new CommonTagCompound();
testGetPutRemove(compound, "integerType", 12);
testGetPutRemove(compound, "longType", 15L);
testGetPutRemove(compound, "doubleType", 12D);
testGetPutRemove(compound, "floatType", 12F);
testGetPutRemove(compound, "byteType", (byte) 12);
testGetPutRemove(compound, "stringType", "hello, world!");
testGetPutRemove(compound, "blockPos", new BlockLocation("World2", 4, 6, 8));
testGetPutRemove(compound, "intVector3Pos", new IntVector3(20, 44, 66));
testGetPutRemove(compound, "random", UUID.randomUUID());
testGetPutRemove(compound, "face", BlockFace.EAST);
testGetPutRemove(compound, "perm", PermissionDefault.OP);
testGetPutRemove(compound, "boolT", Boolean.TRUE);
testGetPutRemove(compound, "boolF", Boolean.FALSE);
}
Aggregations