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
Modifier and TypeClassDescriptionstatic class
Represents 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
Modifier and TypeFieldDescriptionstatic boolean
Before 1.13, data values ("block states") are applicable to items. -
Constructor Summary
ConstructorDescriptionItemData()
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.void
applyMeta(org.bukkit.inventory.meta.ItemMeta meta)
Applies an item meta to this item.void
Applies tags to this item.clone()
void
deserialize(Fields fields)
Deserialises this object.boolean
@Nullable BlockValues
int
int
org.bukkit.inventory.meta.ItemMeta
org.bukkit.inventory.ItemStack
getStack()
Returns the ItemStack backing this ItemData.org.bukkit.Material
getType()
int
hashCode()
@Nullable ItemData
intersection(ItemData other)
Computes the intersection of two ItemDatas.boolean
isAlias()
Checks if this item is an alias or a clone of one that has not been modified after loading the aliases.boolean
Checks if this item is a 'default' of type.boolean
isOfType(@Nullable org.bukkit.inventory.ItemStack item)
Tests whether the given item is of this type.boolean
isPlain()
Checks if this item type was created throughExprPlain
and thus has no modifications made to it.matchAlias(ItemData item)
Checks how well this item matches the given item.boolean
matchPlain(ItemData other)
Compares this ItemData with another to determine if they are matching "plain" items.Serialises this object.void
setDurability(int durability)
void
setItemMeta(org.bukkit.inventory.meta.ItemMeta meta)
void
setPlain(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.EXACT
This and the given item have exactly same Material
,ItemMeta
andBlockValues
.MatchQuality.SAME_ITEM
This and the given item share a Material
.ItemMeta
of this item contains all values thatItemMeta
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
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 throughExprPlain
and 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.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 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.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 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.
-