@Override public NBTCompound remapTag(ProtocolVersion version, String locale, NetworkItemStack itemstack, NBTCompound tag) { if (tag.getTagListOfType("pages", NBTType.STRING) == null) { NBTList<NBTString> pages = new NBTList<>(NBTType.STRING); pages.addTag(new NBTString("")); tag.setTag("pages", pages); } return tag; }
protected NBTList<NBTCompound> filterEnchantList(ProtocolVersion version, NBTList<NBTCompound> oldList) { if (oldList == null) { return null; } GenericSkippingTable<String> enchSkip = GenericIdSkipper.ENCHANT.getTable(version); NBTList<NBTCompound> newList = new NBTList<>(NBTType.COMPOUND); for (NBTCompound enchData : oldList.getTags()) { if (!enchSkip.shouldSkip(NBTString.getValueOrDefault(enchData.getTagOfType("id", NBTType.STRING), ""))) { newList.addTag(enchData); } } return newList; }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testList() { NBTList<NBTInt> list = new NBTList<>(NBTType.INT); list.addTag(new NBTInt(30)); list.addTag(new NBTInt(30)); Assertions.assertTrue(list.getTagsType() == NBTType.INT); Assertions.assertTrue(list.size() == 2); Assertions.assertThrows(IllegalArgumentException.class, () -> ((NBTList) list).addTag(new NBTShort((short) 0))); }
@Override public NBTCompound remapTag(ProtocolVersion version, String locale, NetworkItemStack itemstack, NBTCompound tag) { NBTList<NBTString> pages = tag.getTagListOfType("pages", NBTType.STRING); if (pages != null) { NBTList<NBTString> newPages = new NBTList<>(NBTType.STRING); for (NBTString page : pages.getTags()) { newPages.addTag(new NBTString(ChatAPI.fromJSON(page.getValue()).toLegacyText(locale))); } tag.setTag("pages", newPages); } return tag; }
protected NBTList<NBTCompound> remapEnchantList(NBTList<NBTCompound> oldList) { NBTList<NBTCompound> newList = new NBTList<>(NBTType.COMPOUND); for (NBTCompound enchData : oldList.getTags()) { Enchantment ench = Enchantment.getByKey(NamespacedKeyUtils.fromString(NBTString.getValueOrNull(enchData.getTagOfType("id", NBTType.STRING)))); if (ench != null) { enchData.setTag("id", new NBTShort(LegacyEnchantmentId.getId(ench))); newList.addTag(enchData); } } return newList; }
list.addTag(readTag(stream, valueType));
protected NBTList<NBTCompound> remapEnchantList(NBTList<NBTCompound> oldList) { NBTList<NBTCompound> newList = new NBTList<>(NBTType.COMPOUND); for (NBTCompound enchData : oldList.getTags()) { NBTNumber enchId = enchData.getNumberTag("id"); if (enchId != null) { Enchantment ench = LegacyEnchantmentId.getById(enchId.getAsInt()); if (ench != null) { enchData.setTag("id", new NBTString(ench.getKey().toString())); newList.addTag(enchData); } } } return newList; }
public static NBTCompound serialize(GameProfile gameProfile) { NBTCompound tag = new NBTCompound(); if (!StringUtils.isEmpty(gameProfile.getName())) { tag.setTag(NAME_KEY, new NBTString(gameProfile.getName())); } if (gameProfile.getUUID() != null) { tag.setTag(UUID_KEY, new NBTString(gameProfile.getUUID().toString())); } if (!gameProfile.getProperties().isEmpty()) { NBTCompound propertiesTag = new NBTCompound(); for (Entry<String, Set<ProfileProperty>> entry : gameProfile.getProperties().entrySet()) { NBTList<NBTCompound> propertiesListTag = new NBTList<>(NBTType.COMPOUND); for (ProfileProperty property : entry.getValue()) { NBTCompound propertyTag = new NBTCompound(); propertyTag.setTag(PROPERTY_VALUE_KEY, new NBTString(property.getValue())); if (property.hasSignature()) { propertyTag.setTag(PROPERTY_SIGNATURE_KEY, new NBTString(property.getSignature())); } propertiesListTag.addTag(propertyTag); } propertiesTag.setTag(entry.getKey(), propertiesListTag); } tag.setTag(PROPERTIES_KEY, propertiesTag); } return tag; }
loreNBT.addTag(new NBTString(lore));
protected RecyclableCollection<ServerBoundPacketData> transformBookSign() { ProtocolVersion version = connection.getVersion(); String locale = connection.getCache().getAttributesCache().getLocale(); NetworkItemStack book = ItemStackSerializer.readItemStack(data, version, locale); if (!book.isNull()) { book.setTypeId(ItemMaterialLookup.getRuntimeId(Material.WRITABLE_BOOK)); if (connection.getVersion() == ProtocolVersion.MINECRAFT_1_8) { NBTCompound rootTag = book.getNBT(); if (rootTag != null) { NBTList<NBTString> pages = rootTag.getTagListOfType("pages", NBTType.STRING); if (pages != null) { NBTList<NBTString> newPages = new NBTList<>(NBTType.STRING); for (NBTString page : pages.getTags()) { newPages.addTag(new NBTString(ChatAPI.fromJSON(page.getValue()).toLegacyText(locale))); } rootTag.setTag("pages", newPages); book.setNBT(rootTag); } } } return RecyclableSingletonList.create(MiddleEditBook.create(book, true, UsedHand.MAIN)); } else { return RecyclableEmptyList.get(); } }
@Test public void testCompound() { String testtagname = "test"; NBTCompound compound = new NBTCompound(); compound.setTag(testtagname, new NBTShort((short) 20)); String testlisttagname = "testlist"; NBTList<NBTInt> list = new NBTList<>(NBTType.INT); list.addTag(new NBTInt(30)); compound.setTag(testlisttagname, list); Assertions.assertNotNull(compound.getTag(testtagname)); Assertions.assertNotNull(compound.getTagOfType(testtagname, NBTType.SHORT)); Assertions.assertNull(compound.getTagOfType(testtagname, NBTType.INT)); Assertions.assertNotNull(compound.getNumberTag(testtagname)); Assertions.assertNotNull(compound.getTag(testlisttagname)); Assertions.assertNotNull(compound.getTagOfType(testlisttagname, NBTType.LIST)); Assertions.assertNull(compound.getTagOfType(testlisttagname, NBTType.DOUBLE)); Assertions.assertNotNull(compound.getTagListOfType(testlisttagname, NBTType.INT)); Assertions.assertNull(compound.getTagListOfType(testlisttagname, NBTType.SHORT)); Assertions.assertNotNull(compound.getNumberTagList(testlisttagname)); }