Class ItemData

java.lang.Object
ch.njol.skript.aliases.ItemData
All Implemented Interfaces:
YggdrasilSerializable, YggdrasilSerializable.YggdrasilExtendedSerializable, Cloneable

public class ItemData extends Object implements Cloneable, YggdrasilSerializable.YggdrasilExtendedSerializable
  • Field Details

    • itemDataValues

      public static final boolean itemDataValues
      Before 1.13, data values ("block states") are applicable to items.
  • Constructor Details

    • ItemData

      public ItemData(org.bukkit.Material type, @Nullable String tags)
    • ItemData

      public ItemData(org.bukkit.Material type, int amount)
    • ItemData

      public ItemData(org.bukkit.Material type)
    • ItemData

      public ItemData(ItemData data)
    • ItemData

      public ItemData(org.bukkit.inventory.ItemStack stack, @Nullable BlockValues values)
    • ItemData

      public ItemData(org.bukkit.inventory.ItemStack stack)
    • ItemData

      public ItemData(org.bukkit.block.BlockState block)
    • ItemData

      public ItemData(org.bukkit.block.Block block)
    • ItemData

      public ItemData()
      Only to be used for serialization.
  • Method Details

    • isOfType

      public boolean isOfType(@Nullable org.bukkit.inventory.ItemStack item)
      Tests whether the given item is of this type.
      Parameters:
      item -
      Returns:
      Whether the given item is of this type.
    • toString

      public String toString()
      Returns Aliases.getMaterialName(ItemData, boolean) called with this object and relevant plurarily setting.
      Overrides:
      toString in class Object
    • toString

      public String toString(boolean debug, boolean plural)
    • getGender

      public int getGender()
      Returns:
      The item's gender or -1 if no name is found
    • equals

      public boolean equals(@Nullable Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • matchAlias

      public MatchQuality matchAlias(ItemData item)
      Checks how well this item matches the given item.
      Parameters:
      item - Other item, preferably an alias.
      Returns:
      Match quality, according to following criteria:
      MatchQuality.EXACT This and the given item have exactly same Material, ItemMeta and BlockValues.
      MatchQuality.SAME_ITEM This and the given item share a Material. ItemMeta of this item contains all values that ItemMeta of given has. In addition to that, it may contain other values. BlockValues are handled similarly.
      MatchQuality.SAME_MATERIAL This and the given item share a material.
      MatchQuality.DIFFERENT This and the given item do not meet any of above criteria. They are completely different.
    • isDefault

      public boolean isDefault()
      Checks if this item is a 'default' of type. Default items must have not had their ItemMeta (tags) modified or have block states. Only aliases can be default items.
      Returns:
      If this item can be considered the default item of its type.
    • isAlias

      public boolean isAlias()
      Checks if this item is an alias or a clone of one that has not been modified after loading the aliases.
      Returns:
      True if is an alias or unmodified clone
    • intersection

      public @Nullable ItemData intersection(ItemData other)
      Computes the intersection of two ItemDatas. The data range of the returned item data will be the real intersection of the two data ranges, and the type id will be the one set if any.
      Parameters:
      other -
      Returns:
      A new ItemData which is the intersection of the given types, or null if the intersection of the data ranges is empty or both datas have an id != -1 which are not the same.
    • getStack

      public org.bukkit.inventory.ItemStack getStack()
      Returns the ItemStack backing this ItemData. It is not a copy, so please be careful.
      Returns:
      Item stack.
    • clone

      public ItemData clone()
      Overrides:
      clone in class Object
    • getType

      public org.bukkit.Material getType()
    • getBlockValues

      public @Nullable BlockValues getBlockValues()
    • getItemMeta

      public org.bukkit.inventory.meta.ItemMeta getItemMeta()
    • setItemMeta

      public void setItemMeta(org.bukkit.inventory.meta.ItemMeta meta)
    • getDurability

      public int getDurability()
    • setDurability

      public void setDurability(int durability)
    • isPlain

      public boolean isPlain()
      Checks if this item type was created through ExprPlain and thus has no modifications made to it.
      Returns:
      Whether this item type is 'plain'
    • setPlain

      public void setPlain(boolean plain)
    • matchPlain

      public boolean matchPlain(ItemData other)
      Compares this ItemData with another to determine if they are matching "plain" items. For these ItemDatas to match, they must share a Material. One of the following must also be true:
      • This ItemData is plain AND the other ItemData is plain
      • This ItemData is plain AND the other ItemData is an alias
      • This ItemData is an alias AND the other ItemData is plain
      Parameters:
      other - The ItemData to compare with.
      Returns:
      Whether these items can be "plain matched"
      See Also:
      ExprPlain
    • serialize

      public Fields serialize() throws NotSerializableException
      Description copied from interface: YggdrasilSerializable.YggdrasilExtendedSerializable
      Serialises this object. Only fields contained in the returned Fields object will be written to stream.

      You can use return new Fields(this); to emulate the default behaviour.

      Specified by:
      serialize in interface YggdrasilSerializable.YggdrasilExtendedSerializable
      Returns:
      A Fields object containing all fields that should be written to stream
      Throws:
      NotSerializableException - If this object or one of its fields is not serialisable
    • deserialize

      public void deserialize(Fields fields) throws StreamCorruptedException, NotSerializableException
      Description copied from interface: YggdrasilSerializable.YggdrasilExtendedSerializable
      Deserialises this object. No fields have been set when this method is called, use fields.setFields(this, yggdrasil) to set all compatible non-transient and non-static fields (and call incompatible/missing field handlers if applicable – this implies that errors will be thrown if the fields object is invalid).

      You can use fields.setFields(this); to emulate the default behaviour.

      Specified by:
      deserialize in interface YggdrasilSerializable.YggdrasilExtendedSerializable
      Parameters:
      fields - A Fields object containing all fields read from stream
      Throws:
      StreamCorruptedException - If the Fields object is invalid, i.e. was not written by YggdrasilSerializable.YggdrasilExtendedSerializable.serialize() or Yggrdasil's default serialisation.
      NotSerializableException
    • aliasCopy

      public ItemData aliasCopy()
      Creates a plain copy of this ItemData. It will have same material, amount of 1 and same block values. Tags will also be copied, with following exceptions:
      • Damage: 1.13 tag-damage is only used for actual durability. Present on 1.12 and older versions.
      • Name: custom names made with anvil do not change item type
      Returns:
      A modified copy of this item data.
    • applyMeta

      public void applyMeta(org.bukkit.inventory.meta.ItemMeta meta)
      Applies an item meta to this item. Currently, it copies the following, provided that they exist in given meta:
      • Lore
      • Display name
      • Enchantments
      • Item flags
      Parameters:
      meta - Item meta.
    • applyTags

      public void applyTags(String tags)
      Applies tags to this item.
      Parameters:
      tags - Tags in Mojang's JSON format.