Search in sources :

Example 1 with Overridden

use of org.bukkit.craftbukkit.v1_16_R3.Overridden in project Mohist by MohistMC.

the class CraftMetaItem method applyToItem.

@Overridden
void applyToItem(CompoundTag itemTag) {
    if (hasDisplayName()) {
        setDisplayTag(itemTag, NAME.NBT, StringTag.valueOf(displayName));
    }
    if (hasLocalizedName()) {
        setDisplayTag(itemTag, LOCNAME.NBT, StringTag.valueOf(locName));
    }
    if (lore != null) {
        setDisplayTag(itemTag, LORE.NBT, createStringList(lore));
    }
    if (hasCustomModelData()) {
        itemTag.putInt(CUSTOM_MODEL_DATA.NBT, customModelData);
    }
    if (hasBlockData()) {
        itemTag.put(BLOCK_DATA.NBT, blockData);
    }
    if (hideFlag != 0) {
        itemTag.putInt(HIDEFLAGS.NBT, hideFlag);
    }
    applyEnchantments(enchantments, itemTag, ENCHANTMENTS);
    applyModifiers(attributeModifiers, itemTag, ATTRIBUTES);
    if (hasRepairCost()) {
        itemTag.putInt(REPAIR.NBT, repairCost);
    }
    if (isUnbreakable()) {
        itemTag.putBoolean(UNBREAKABLE.NBT, unbreakable);
    }
    if (hasDamage()) {
        itemTag.putInt(DAMAGE.NBT, damage);
    }
    for (Map.Entry<String, Tag> e : unhandledTags.entrySet()) {
        itemTag.put(e.getKey(), e.getValue());
    }
    if (!persistentDataContainer.isEmpty()) {
        CompoundTag bukkitCustomCompound = new CompoundTag();
        Map<String, Tag> rawPublicMap = persistentDataContainer.getRaw();
        for (Map.Entry<String, Tag> nbtBaseEntry : rawPublicMap.entrySet()) {
            bukkitCustomCompound.put(nbtBaseEntry.getKey(), nbtBaseEntry.getValue());
        }
        itemTag.put(BUKKIT_CUSTOM_TAG.NBT, bukkitCustomCompound);
    }
}
Also used : StringTag(net.minecraft.nbt.StringTag) CompoundTag(net.minecraft.nbt.CompoundTag) Tag(net.minecraft.nbt.Tag) ListTag(net.minecraft.nbt.ListTag) CraftAttributeMap(org.bukkit.craftbukkit.v1_18_R2.attribute.CraftAttributeMap) ImmutableMap(com.google.common.collect.ImmutableMap) CompoundTag(net.minecraft.nbt.CompoundTag) Overridden(org.bukkit.craftbukkit.v1_18_R2.Overridden)

Example 2 with Overridden

use of org.bukkit.craftbukkit.v1_16_R3.Overridden in project LoliServer by Loli-Server.

the class CraftMetaItem method serialize.

@Overridden
ImmutableMap.Builder<String, Object> serialize(ImmutableMap.Builder<String, Object> builder) {
    if (hasDisplayName()) {
        builder.put(NAME.BUKKIT, displayName);
    }
    if (hasLocalizedName()) {
        builder.put(LOCNAME.BUKKIT, locName);
    }
    if (hasLore()) {
        builder.put(LORE.BUKKIT, ImmutableList.copyOf(lore));
    }
    if (hasCustomModelData()) {
        builder.put(CUSTOM_MODEL_DATA.BUKKIT, customModelData);
    }
    if (hasBlockData()) {
        builder.put(BLOCK_DATA.BUKKIT, CraftNBTTagConfigSerializer.serialize(blockData));
    }
    serializeEnchantments(enchantments, builder, ENCHANTMENTS);
    serializeModifiers(attributeModifiers, builder, ATTRIBUTES);
    if (hasRepairCost()) {
        builder.put(REPAIR.BUKKIT, repairCost);
    }
    List<String> hideFlags = new ArrayList<String>();
    for (ItemFlag hideFlagEnum : getItemFlags()) {
        hideFlags.add(hideFlagEnum.name());
    }
    if (!hideFlags.isEmpty()) {
        builder.put(HIDEFLAGS.BUKKIT, hideFlags);
    }
    if (isUnbreakable()) {
        builder.put(UNBREAKABLE.BUKKIT, unbreakable);
    }
    if (hasDamage()) {
        builder.put(DAMAGE.BUKKIT, damage);
    }
    final Map<String, INBT> internalTags = new HashMap<String, INBT>(unhandledTags);
    serializeInternal(internalTags);
    if (!internalTags.isEmpty()) {
        CompoundNBT internal = new CompoundNBT();
        for (Map.Entry<String, INBT> e : internalTags.entrySet()) {
            internal.put(e.getKey(), e.getValue());
        }
        try {
            ByteArrayOutputStream buf = new ByteArrayOutputStream();
            CompressedStreamTools.writeCompressed(internal, buf);
            builder.put("internal", Base64.encodeBase64String(buf.toByteArray()));
        } catch (IOException ex) {
            Logger.getLogger(CraftMetaItem.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    if (!persistentDataContainer.isEmpty()) {
        // Store custom tags, wrapped in their compound
        builder.put(BUKKIT_CUSTOM_TAG.BUKKIT, persistentDataContainer.serialize());
    }
    return builder;
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) INBT(net.minecraft.nbt.INBT) ItemFlag(org.bukkit.inventory.ItemFlag) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) CraftAttributeMap(org.bukkit.craftbukkit.v1_16_R3.attribute.CraftAttributeMap) Overridden(org.bukkit.craftbukkit.v1_16_R3.Overridden)

Example 3 with Overridden

use of org.bukkit.craftbukkit.v1_16_R3.Overridden in project Magma-1.16.x by magmafoundation.

the class CraftMetaItem method serialize.

@Overridden
ImmutableMap.Builder<String, Object> serialize(ImmutableMap.Builder<String, Object> builder) {
    if (hasDisplayName()) {
        builder.put(NAME.BUKKIT, displayName);
    }
    if (hasLocalizedName()) {
        builder.put(LOCNAME.BUKKIT, locName);
    }
    if (hasLore()) {
        builder.put(LORE.BUKKIT, ImmutableList.copyOf(lore));
    }
    if (hasCustomModelData()) {
        builder.put(CUSTOM_MODEL_DATA.BUKKIT, customModelData);
    }
    if (hasBlockData()) {
        builder.put(BLOCK_DATA.BUKKIT, CraftNBTTagConfigSerializer.serialize(blockData));
    }
    serializeEnchantments(enchantments, builder, ENCHANTMENTS);
    serializeModifiers(attributeModifiers, builder, ATTRIBUTES);
    if (hasRepairCost()) {
        builder.put(REPAIR.BUKKIT, repairCost);
    }
    List<String> hideFlags = new ArrayList<String>();
    for (ItemFlag hideFlagEnum : getItemFlags()) {
        hideFlags.add(hideFlagEnum.name());
    }
    if (!hideFlags.isEmpty()) {
        builder.put(HIDEFLAGS.BUKKIT, hideFlags);
    }
    if (isUnbreakable()) {
        builder.put(UNBREAKABLE.BUKKIT, unbreakable);
    }
    if (hasDamage()) {
        builder.put(DAMAGE.BUKKIT, damage);
    }
    final Map<String, INBT> internalTags = new HashMap<String, INBT>(unhandledTags);
    serializeInternal(internalTags);
    if (!internalTags.isEmpty()) {
        CompoundNBT internal = new CompoundNBT();
        for (Map.Entry<String, INBT> e : internalTags.entrySet()) {
            internal.put(e.getKey(), e.getValue());
        }
        try {
            ByteArrayOutputStream buf = new ByteArrayOutputStream();
            CompressedStreamTools.writeCompressed(internal, buf);
            builder.put("internal", Base64.encodeBase64String(buf.toByteArray()));
        } catch (IOException ex) {
            Logger.getLogger(CraftMetaItem.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    if (!persistentDataContainer.isEmpty()) {
        // Store custom tags, wrapped in their compound
        builder.put(BUKKIT_CUSTOM_TAG.BUKKIT, persistentDataContainer.serialize());
    }
    return builder;
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) INBT(net.minecraft.nbt.INBT) ItemFlag(org.bukkit.inventory.ItemFlag) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) CraftAttributeMap(org.bukkit.craftbukkit.v1_16_R3.attribute.CraftAttributeMap) Overridden(org.bukkit.craftbukkit.v1_16_R3.Overridden)

Example 4 with Overridden

use of org.bukkit.craftbukkit.v1_16_R3.Overridden in project Magma by magmafoundation.

the class CraftMetaItem method serialize.

@Overridden
ImmutableMap.Builder<String, Object> serialize(ImmutableMap.Builder<String, Object> builder) {
    if (hasDisplayName()) {
        builder.put(NAME.BUKKIT, displayName);
    }
    if (hasLocalizedName()) {
        builder.put(LOCNAME.BUKKIT, locName);
    }
    if (hasLore()) {
        builder.put(LORE.BUKKIT, ImmutableList.copyOf(lore));
    }
    serializeEnchantments(enchantments, builder, ENCHANTMENTS);
    if (hasRepairCost()) {
        builder.put(REPAIR.BUKKIT, repairCost);
    }
    List<String> hideFlags = new ArrayList<String>();
    for (ItemFlag hideFlagEnum : getItemFlags()) {
        hideFlags.add(hideFlagEnum.name());
    }
    if (!hideFlags.isEmpty()) {
        builder.put(HIDEFLAGS.BUKKIT, hideFlags);
    }
    if (isUnbreakable()) {
        builder.put(UNBREAKABLE.BUKKIT, unbreakable);
    }
    final Map<String, NBTBase> internalTags = new HashMap<String, NBTBase>(unhandledTags);
    serializeInternal(internalTags);
    if (!internalTags.isEmpty()) {
        NBTTagCompound internal = new NBTTagCompound();
        for (Map.Entry<String, NBTBase> e : internalTags.entrySet()) {
            internal.setTag(e.getKey(), e.getValue());
        }
        try {
            ByteArrayOutputStream buf = new ByteArrayOutputStream();
            CompressedStreamTools.writeCompressed(internal, buf);
            builder.put("internal", Base64.encodeBase64String(buf.toByteArray()));
        } catch (IOException ex) {
            Logger.getLogger(CraftMetaItem.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    return builder;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagString(net.minecraft.nbt.NBTTagString) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) NBTBase(net.minecraft.nbt.NBTBase) ItemFlag(org.bukkit.inventory.ItemFlag) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Overridden(org.bukkit.craftbukkit.v1_12_R1.Overridden)

Example 5 with Overridden

use of org.bukkit.craftbukkit.v1_16_R3.Overridden in project Mohist by MohistMC.

the class CraftMetaItem method serialize.

@Overridden
ImmutableMap.Builder<String, Object> serialize(ImmutableMap.Builder<String, Object> builder) {
    if (hasDisplayName()) {
        builder.put(NAME.BUKKIT, displayName);
    }
    if (hasLocalizedName()) {
        builder.put(LOCNAME.BUKKIT, locName);
    }
    if (lore != null) {
        builder.put(LORE.BUKKIT, ImmutableList.copyOf(lore));
    }
    if (hasCustomModelData()) {
        builder.put(CUSTOM_MODEL_DATA.BUKKIT, customModelData);
    }
    if (hasBlockData()) {
        builder.put(BLOCK_DATA.BUKKIT, CraftNBTTagConfigSerializer.serialize(blockData));
    }
    serializeEnchantments(enchantments, builder, ENCHANTMENTS);
    serializeModifiers(attributeModifiers, builder, ATTRIBUTES);
    if (hasRepairCost()) {
        builder.put(REPAIR.BUKKIT, repairCost);
    }
    List<String> hideFlags = new ArrayList<String>();
    for (ItemFlag hideFlagEnum : getItemFlags()) {
        hideFlags.add(hideFlagEnum.name());
    }
    if (!hideFlags.isEmpty()) {
        builder.put(HIDEFLAGS.BUKKIT, hideFlags);
    }
    if (isUnbreakable()) {
        builder.put(UNBREAKABLE.BUKKIT, unbreakable);
    }
    if (hasDamage()) {
        builder.put(DAMAGE.BUKKIT, damage);
    }
    final Map<String, Tag> internalTags = new HashMap<String, Tag>(unhandledTags);
    serializeInternal(internalTags);
    if (!internalTags.isEmpty()) {
        CompoundTag internal = new CompoundTag();
        for (Map.Entry<String, Tag> e : internalTags.entrySet()) {
            internal.put(e.getKey(), e.getValue());
        }
        try {
            ByteArrayOutputStream buf = new ByteArrayOutputStream();
            NbtIo.writeCompressed(internal, buf);
            builder.put("internal", Base64.getEncoder().encodeToString(buf.toByteArray()));
        } catch (IOException ex) {
            Logger.getLogger(CraftMetaItem.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    if (!persistentDataContainer.isEmpty()) {
        // Store custom tags, wrapped in their compound
        builder.put(BUKKIT_CUSTOM_TAG.BUKKIT, persistentDataContainer.serialize());
    }
    return builder;
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) StringTag(net.minecraft.nbt.StringTag) CompoundTag(net.minecraft.nbt.CompoundTag) Tag(net.minecraft.nbt.Tag) ListTag(net.minecraft.nbt.ListTag) ItemFlag(org.bukkit.inventory.ItemFlag) CraftAttributeMap(org.bukkit.craftbukkit.v1_18_R2.attribute.CraftAttributeMap) ImmutableMap(com.google.common.collect.ImmutableMap) CompoundTag(net.minecraft.nbt.CompoundTag) Overridden(org.bukkit.craftbukkit.v1_18_R2.Overridden)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)8 HashMap (java.util.HashMap)6 Map (java.util.Map)6 Overridden (org.bukkit.craftbukkit.v1_16_R3.Overridden)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 IOException (java.io.IOException)5 ItemFlag (org.bukkit.inventory.ItemFlag)5 ArrayList (java.util.ArrayList)4 LinkedHashMap (java.util.LinkedHashMap)4 CompoundNBT (net.minecraft.nbt.CompoundNBT)4 INBT (net.minecraft.nbt.INBT)4 CraftAttributeMap (org.bukkit.craftbukkit.v1_16_R3.attribute.CraftAttributeMap)4 Overridden (org.bukkit.craftbukkit.v1_18_R2.Overridden)3 Enchantment (org.bukkit.enchantments.Enchantment)3 CompoundTag (net.minecraft.nbt.CompoundTag)2 ListTag (net.minecraft.nbt.ListTag)2 StringTag (net.minecraft.nbt.StringTag)2 Tag (net.minecraft.nbt.Tag)2 Overridden (org.bukkit.craftbukkit.v1_12_R1.Overridden)2 CraftPersistentDataContainer (org.bukkit.craftbukkit.v1_16_R3.persistence.CraftPersistentDataContainer)2