public static GameProfile deserialize(NBTCompound tag) { String name = NBTString.getValueOrNull(tag.getTagOfType(NAME_KEY, NBTType.STRING)); UUID uuid = null; try { uuid = UUID.fromString(NBTString.getValueOrNull(tag.getTagOfType(UUID_KEY, NBTType.STRING))); } catch (Throwable t) { } if (StringUtils.isEmpty(name) && (uuid == null)) { return null; } GameProfile gameProfile = new GameProfile(uuid, name); NBTCompound propertiesTag = tag.getTagOfType(PROPERTIES_KEY, NBTType.COMPOUND); if (propertiesTag != null) { for (String propertyName : propertiesTag.getTagNames()) { NBTList<NBTCompound> propertiesListTag = propertiesTag.getTagListOfType(propertyName, NBTType.COMPOUND); if (propertiesListTag != null) { for (NBTCompound propertyTag : propertiesListTag.getTags()) { gameProfile.addProperty(new ProfileProperty( propertyName, NBTString.getValueOrNull(propertyTag.getTagOfType(PROPERTY_VALUE_KEY, NBTType.STRING)), NBTString.getValueOrNull(propertyTag.getTagOfType(PROPERTY_SIGNATURE_KEY, NBTType.STRING)) )); } } } } return gameProfile; }
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; }
@Override public NetworkItemStack remap(ProtocolVersion version, String locale, NetworkItemStack itemstack) { NBTCompound tag = itemstack.getNBT(); if (tag == null) { return itemstack; } String potion = NBTString.getValueOrNull(tag.getTagOfType("Potion", NBTType.STRING)); NBTList<NBTCompound> customPotionEffects = tag.getTagListOfType("CustomPotionEffects", NBTType.COMPOUND); if ((customPotionEffects != null) && (customPotionEffects.size() >= 1)) { potion = PotionData.getNameById(customPotionEffects.getTag(0).getNumberTag("Id").getAsInt()); } if (potion != null) { itemstack.setLegacyData(LegacyPotionId.toLegacyId(potion, isThrowablePotion)); String basicTypeName = LegacyPotionId.getBasicTypeName(potion); if (basicTypeName != null) { NBTCompound display = CommonNBT.getOrCreateDisplayTag(tag); display.setTag(CommonNBT.DISPLAY_NAME, new NBTString(ChatAPI.toJSON(new TextComponent(TranslationAPI.translate(locale, basicTypeName))))); } } return itemstack; }