Search in sources :

Example 6 with Overridden

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

the class CraftMetaItem method clone.

@Overridden
@Override
public CraftMetaItem clone() {
    try {
        CraftMetaItem clone = (CraftMetaItem) super.clone();
        if (this.lore != null) {
            clone.lore = new ArrayList<String>(this.lore);
        }
        clone.customModelData = this.customModelData;
        clone.blockData = this.blockData;
        if (this.enchantments != null) {
            clone.enchantments = new LinkedHashMap<Enchantment, Integer>(this.enchantments);
        }
        if (this.hasAttributeModifiers()) {
            clone.attributeModifiers = LinkedHashMultimap.create(this.attributeModifiers);
        }
        clone.persistentDataContainer = new CraftPersistentDataContainer(this.persistentDataContainer.getRaw(), DATA_TYPE_REGISTRY);
        clone.hideFlag = this.hideFlag;
        clone.unbreakable = this.unbreakable;
        clone.damage = this.damage;
        clone.version = this.version;
        return clone;
    } catch (CloneNotSupportedException e) {
        throw new Error(e);
    }
}
Also used : CraftPersistentDataContainer(org.bukkit.craftbukkit.v1_18_R2.persistence.CraftPersistentDataContainer) Enchantment(org.bukkit.enchantments.Enchantment) Overridden(org.bukkit.craftbukkit.v1_18_R2.Overridden)

Example 7 with Overridden

use of org.bukkit.craftbukkit.v1_12_R1.Overridden in project PaperDev by Kamillaova.

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.set(e.getKey(), e.getValue());
        }
        try {
            ByteArrayOutputStream buf = new ByteArrayOutputStream();
            NBTCompressedStreamTools.a(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.server.v1_12_R1.NBTTagCompound) NBTTagString(net.minecraft.server.v1_12_R1.NBTTagString) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) NBTBase(net.minecraft.server.v1_12_R1.NBTBase) ItemFlag(org.bukkit.inventory.ItemFlag) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) TreeMap(java.util.TreeMap) Overridden(org.bukkit.craftbukkit.v1_12_R1.Overridden)

Example 8 with Overridden

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

the class CraftMetaItem method applyToItem.

@Overridden
void applyToItem(CompoundNBT itemTag) {
    if (hasDisplayName()) {
        setDisplayTag(itemTag, NAME.NBT, StringNBT.valueOf(displayName));
    }
    if (hasLocalizedName()) {
        setDisplayTag(itemTag, LOCNAME.NBT, StringNBT.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, INBT> e : unhandledTags.entrySet()) {
        itemTag.put(e.getKey(), e.getValue());
    }
    if (!persistentDataContainer.isEmpty()) {
        CompoundNBT bukkitCustomCompound = new CompoundNBT();
        Map<String, INBT> rawPublicMap = persistentDataContainer.getRaw();
        for (Map.Entry<String, INBT> nbtBaseEntry : rawPublicMap.entrySet()) {
            bukkitCustomCompound.put(nbtBaseEntry.getKey(), nbtBaseEntry.getValue());
        }
        itemTag.put(BUKKIT_CUSTOM_TAG.NBT, bukkitCustomCompound);
    }
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) INBT(net.minecraft.nbt.INBT) 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 9 with Overridden

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

the class CraftMetaItem method clone.

@Overridden
@Override
public CraftMetaItem clone() {
    try {
        CraftMetaItem clone = (CraftMetaItem) super.clone();
        if (this.lore != null) {
            clone.lore = new ArrayList<String>(this.lore);
        }
        clone.customModelData = this.customModelData;
        clone.blockData = this.blockData;
        if (this.enchantments != null) {
            clone.enchantments = new LinkedHashMap<Enchantment, Integer>(this.enchantments);
        }
        if (this.hasAttributeModifiers()) {
            clone.attributeModifiers = LinkedHashMultimap.create(this.attributeModifiers);
        }
        clone.persistentDataContainer = new CraftPersistentDataContainer(this.persistentDataContainer.getRaw(), DATA_TYPE_REGISTRY);
        clone.hideFlag = this.hideFlag;
        clone.unbreakable = this.unbreakable;
        clone.damage = this.damage;
        clone.version = this.version;
        return clone;
    } catch (CloneNotSupportedException e) {
        throw new Error(e);
    }
}
Also used : CraftPersistentDataContainer(org.bukkit.craftbukkit.v1_16_R3.persistence.CraftPersistentDataContainer) Enchantment(org.bukkit.enchantments.Enchantment) Overridden(org.bukkit.craftbukkit.v1_16_R3.Overridden)

Example 10 with Overridden

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

the class CraftMetaItem method applyToItem.

@Overridden
void applyToItem(CompoundNBT itemTag) {
    if (hasDisplayName()) {
        setDisplayTag(itemTag, NAME.NBT, StringNBT.valueOf(displayName));
    }
    if (hasLocalizedName()) {
        setDisplayTag(itemTag, LOCNAME.NBT, StringNBT.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, INBT> e : unhandledTags.entrySet()) {
        itemTag.put(e.getKey(), e.getValue());
    }
    if (!persistentDataContainer.isEmpty()) {
        CompoundNBT bukkitCustomCompound = new CompoundNBT();
        Map<String, INBT> rawPublicMap = persistentDataContainer.getRaw();
        for (Map.Entry<String, INBT> nbtBaseEntry : rawPublicMap.entrySet()) {
            bukkitCustomCompound.put(nbtBaseEntry.getKey(), nbtBaseEntry.getValue());
        }
        itemTag.put(BUKKIT_CUSTOM_TAG.NBT, bukkitCustomCompound);
    }
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) INBT(net.minecraft.nbt.INBT) 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)

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