Package ch.njol.skript.aliases
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepresents old ItemData (before aliases rework and MC 1.13).Nested classes/interfaces inherited from interface ch.njol.yggdrasil.YggdrasilSerializable
YggdrasilSerializable.YggdrasilExtendedSerializable, YggdrasilSerializable.YggdrasilRobustEnum, YggdrasilSerializable.YggdrasilRobustSerializable -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic booleanBefore 1.13, data values ("block states") are applicable to items. -
Constructor Summary
ConstructorsConstructorDescriptionItemData()Only to be used for serialization.ItemData(org.bukkit.block.Block block)ItemData(org.bukkit.block.BlockState block)ItemData(org.bukkit.inventory.ItemStack stack)ItemData(org.bukkit.inventory.ItemStack stack, @Nullable BlockValues values)ItemData(org.bukkit.Material type)ItemData(org.bukkit.Material type, int amount) -
Method Summary
Modifier and TypeMethodDescriptionCreates a plain copy of this ItemData.voidapplyMeta(org.bukkit.inventory.meta.ItemMeta meta)Applies an item meta to this item.voidApplies tags to this item.clone()voiddeserialize(Fields fields)Deserialises this object.boolean@Nullable BlockValuesintintorg.bukkit.inventory.meta.ItemMetaorg.bukkit.inventory.ItemStackgetStack()Returns the ItemStack backing this ItemData.org.bukkit.MaterialgetType()inthashCode()@Nullable ItemDataintersection(ItemData other)Computes the intersection of two ItemDatas.booleanisAlias()Checks if this item is an alias or a clone of one that has not been modified after loading the aliases.booleanChecks if this item is a 'default' of type.booleanisOfType(@Nullable org.bukkit.inventory.ItemStack item)Tests whether the given item is of this type.booleanisPlain()Checks if this item type was created throughExprPlainand thus has no modifications made to it.matchAlias(ItemData item)Checks how well this item matches the given item.booleanmatchPlain(ItemData other)Compares this ItemData with another to determine if they are matching "plain" items.Serialises this object.voidsetDurability(int durability)voidsetItemMeta(org.bukkit.inventory.meta.ItemMeta meta)voidsetPlain(boolean plain)toString()ReturnsAliases.called with this object and relevant plurarily setting.getMaterialName(ItemData, boolean)toString(boolean debug, boolean plural)
-
Field Details
-
itemDataValues
public static final boolean itemDataValuesBefore 1.13, data values ("block states") are applicable to items.
-
-
Constructor Details
-
ItemData
-
ItemData
public ItemData(org.bukkit.Material type, int amount) -
ItemData
public ItemData(org.bukkit.Material type) -
ItemData
-
ItemData
-
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
ReturnsAliases.called with this object and relevant plurarily setting.getMaterialName(ItemData, boolean) -
toString
-
getGender
public int getGender()- Returns:
- The item's gender or -1 if no name is found
-
equals
-
hashCode
public int hashCode() -
matchAlias
Checks how well this item matches the given item.- Parameters:
item- Other item, preferably an alias.- Returns:
- Match quality, according to following criteria:
MatchQuality.EXACTThis and the given item have exactly same Material,ItemMetaandBlockValues.MatchQuality.SAME_ITEMThis and the given item share a Material.ItemMetaof this item contains all values thatItemMetaof given has. In addition to that, it may contain other values.BlockValuesare handled similarly.MatchQuality.SAME_MATERIALThis and the given item share a material. MatchQuality.DIFFERENTThis 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
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
-
getType
public org.bukkit.Material getType() -
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 throughExprPlainand thus has no modifications made to it.- Returns:
- Whether this item type is 'plain'
-
setPlain
public void setPlain(boolean plain) -
matchPlain
Compares this ItemData with another to determine if they are matching "plain" items. For these ItemDatas to match, they must share aMaterial. 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
Description copied from interface:YggdrasilSerializable.YggdrasilExtendedSerializableSerialises 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:
serializein interfaceYggdrasilSerializable.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
Description copied from interface:YggdrasilSerializable.YggdrasilExtendedSerializableDeserialises 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:
deserializein interfaceYggdrasilSerializable.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 byYggdrasilSerializable.YggdrasilExtendedSerializable.serialize()or Yggrdasil's default serialisation.NotSerializableException
-
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
Applies tags to this item.- Parameters:
tags- Tags in Mojang's JSON format.
-