Package ch.njol.skript.aliases
Class ItemType
java.lang.Object
ch.njol.skript.aliases.ItemType
- All Implemented Interfaces:
Unit
,Container<org.bukkit.inventory.ItemStack>
,YggdrasilSerializable
,YggdrasilSerializable.YggdrasilExtendedSerializable
,Cloneable
,Iterable<ItemData>
@ContainerType(org.bukkit.inventory.ItemStack.class)
public class ItemType
extends Object
implements Unit, Iterable<ItemData>, Container<org.bukkit.inventory.ItemStack>, YggdrasilSerializable.YggdrasilExtendedSerializable
-
Nested Class Summary
Nested classes/interfaces inherited from interface ch.njol.skript.util.Container
Container.ContainerType
Nested classes/interfaces inherited from interface ch.njol.yggdrasil.YggdrasilSerializable
YggdrasilSerializable.YggdrasilExtendedSerializable, YggdrasilSerializable.YggdrasilRobustEnum, YggdrasilSerializable.YggdrasilRobustSerializable
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
void
addAll(Collection<ItemData> types)
void
addEnchantments(EnchantmentType... enchantments)
Adds the given enchantments to the item type.void
addEnchantments(Map<org.bukkit.enchantments.Enchantment,Integer> enchantments)
Deprecated.@Nullable org.bukkit.inventory.ItemStack
addTo(@Nullable org.bukkit.inventory.ItemStack item)
Adds this ItemType to the given item stackvoid
Adds this ItemType to the given list, without filling existing stacks.boolean
addTo(org.bukkit.inventory.Inventory invi)
Tries to add this ItemType to the given inventory.boolean
addTo(org.bukkit.inventory.ItemStack[] buf)
void
Clears all enchantments from this item type except the ones that are defined for individual item datas only.void
Clears item meta from this type.clone()
Iterator<org.bukkit.inventory.ItemStack>
void
deserialize(Fields fields)
Deserialises this object.boolean
Iterable<org.bukkit.inventory.ItemStack>
getAll()
Gets all ItemStacks this ItemType represents.int
Returns amount of the item in stack that this type represents.Returns a base item type of this.getBlock()
static org.bukkit.inventory.ItemStack[]
getCopiedContents(org.bukkit.inventory.Inventory invi)
Deprecated.@Nullable EnchantmentType[]
Gets all enchantments of this item.int
Only use this method if you know what you're doing.getItem()
org.bukkit.inventory.meta.ItemMeta
Gets item meta that applies to all items represented by this type.org.bukkit.Material
org.bukkit.inventory.ItemStack
Gets raw item names ("minecraft:some_item").static org.bukkit.inventory.ItemStack[]
getStorageContents(org.bukkit.inventory.Inventory invi)
Gets copy of storage contents, i.e.getTypes()
boolean
hasAnyEnchantments(org.bukkit.enchantments.Enchantment... enchantments)
Checks whether this item type contains at most one of the given enchantments.boolean
hasBlock()
boolean
Checks whether this item type has enchantments.boolean
hasEnchantments(EnchantmentType... enchantments)
Checks whether this item type contains the given enchantments.boolean
hasEnchantments(org.bukkit.enchantments.Enchantment... enchantments)
Checks whether this item type has the given enchantments.int
hashCode()
boolean
hasItem()
boolean
hasSpace(org.bukkit.inventory.Inventory invi)
Test whether this ItemType can be put into the given inventory completely.@Nullable ItemType
intersection(ItemType other)
Intersects all ItemDatas with all ItemDatas of the given ItemType, returning an ItemType with at most n*m ItemDatas, where n = #ItemDatas of this ItemType, and m = #ItemDatas of the argument.boolean
isAll()
Checks if this item type represents one of its items (OR) or all of them (AND).boolean
isContainedIn(Iterable<org.bukkit.inventory.ItemStack> items)
boolean
isContainedIn(org.bukkit.inventory.ItemStack[] items)
boolean
isOfType(@Nullable org.bukkit.block.Block block)
boolean
isOfType(@Nullable org.bukkit.block.BlockState block)
boolean
isOfType(@Nullable org.bukkit.inventory.ItemStack item)
boolean
boolean
isOfType(org.bukkit.Material id)
boolean
boolean
Compares two ItemTypes, ignoring stack size.static boolean
Tests whether a given set of ItemTypes is a subset of another set of ItemTypes.boolean
isSupertypeOf(ItemType other)
Checks if this type represents all the items represented by given item type.iterator()
void
modified()
Removes the item and block aliases from this alias as it now represents a different item.int
numItems()
int
numTypes()
void
@Nullable org.bukkit.inventory.ItemStack
removeAll(@Nullable org.bukkit.inventory.ItemStack item)
boolean
boolean
removeAll(org.bukkit.inventory.Inventory invi)
void
removeEnchantments(EnchantmentType... enchantments)
Removes the given enchantments from this item type.@Nullable org.bukkit.inventory.ItemStack
removeFrom(@Nullable org.bukkit.inventory.ItemStack item)
Removes this type from the item stack if appropriateboolean
removeFrom(List<org.bukkit.inventory.ItemStack>... lists)
boolean
removeFrom(org.bukkit.inventory.Inventory invi)
Removes this type from the given inventory.void
sendBlockChange(org.bukkit.entity.Player player, org.bukkit.Location location)
Send a block change to a playerSerialises this object.void
setAll(boolean all)
void
setAmount(double amount)
void
setAmount(int amount)
boolean
setBlock(org.bukkit.block.Block block, boolean applyPhysics)
Sets the given block to this ItemTypevoid
setItemMeta(org.bukkit.inventory.meta.ItemMeta meta)
Sets item meta that is applied for everything this type represents.void
toString()
toString(int flags)
static String
toString(org.bukkit.block.Block b, int flags)
static String
toString(org.bukkit.inventory.ItemStack i)
static String
toString(org.bukkit.inventory.ItemStack i, int flags)
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
ItemType
public ItemType() -
ItemType
public ItemType(org.bukkit.Material id) -
ItemType
-
ItemType
-
ItemType
public ItemType(org.bukkit.inventory.ItemStack i) -
ItemType
public ItemType(org.bukkit.block.BlockState b) -
ItemType
public ItemType(org.bukkit.block.Block block)
-
-
Method Details
-
setTo
-
modified
public void modified()Removes the item and block aliases from this alias as it now represents a different item. -
getAmount
public int getAmount()Returns amount of the item in stack that this type represents. -
getInternalAmount
public int getInternalAmount()Only use this method if you know what you're doing.- Returns:
- The internal amount, i.e. same as
getAmount()
or additive inverse number of it.
-
setAmount
public void setAmount(double amount) -
setAmount
public void setAmount(int amount) -
isAll
public boolean isAll()Checks if this item type represents one of its items (OR) or all of them (AND). If this has only one item, it doesn't matter.- Returns:
- Whether all of the items are represented.
-
setAll
public void setAll(boolean all) -
isOfType
public boolean isOfType(@Nullable org.bukkit.inventory.ItemStack item) -
isOfType
public boolean isOfType(@Nullable org.bukkit.block.BlockState block) -
isOfType
public boolean isOfType(@Nullable org.bukkit.block.Block block) -
isOfType
-
isOfType
-
isOfType
public boolean isOfType(org.bukkit.Material id) -
isSupertypeOf
Checks if this type represents all the items represented by given item type. This type may of course also represent other items.- Parameters:
other
- Another item type.- Returns:
- Whether this is supertype of the given item type.
-
getItem
-
getBlock
-
hasItem
public boolean hasItem()- Returns:
- Whether this ItemType has at least one ItemData that represents an item
-
hasBlock
public boolean hasBlock()- Returns:
- Whether this ItemType has at least one ItemData that represents a block
-
setBlock
public boolean setBlock(org.bukkit.block.Block block, boolean applyPhysics)Sets the given block to this ItemType- Parameters:
block
- The block to setapplyPhysics
- Whether to run a physics check just after setting the block- Returns:
- Whether the block was successfully set
-
sendBlockChange
public void sendBlockChange(org.bukkit.entity.Player player, org.bukkit.Location location)Send a block change to a playerThis will send a fake block change to the player, and will not change the block on the server.
- Parameters:
player
- Player to send change tolocation
- Location of block to change
-
intersection
Intersects all ItemDatas with all ItemDatas of the given ItemType, returning an ItemType with at most n*m ItemDatas, where n = #ItemDatas of this ItemType, and m = #ItemDatas of the argument.- Parameters:
other
-- Returns:
- A new item type which is the intersection of the two item types or null if the intersection is empty.
- See Also:
ItemData.intersection(ItemData)
-
add
- Parameters:
type
- Some ItemData. Only a copy of it will be stored.
-
addAll
-
remove
-
containerIterator
- Specified by:
containerIterator
in interfaceContainer<org.bukkit.inventory.ItemStack>
- Returns:
- All element within this container in no particular order
-
getAll
Gets all ItemStacks this ItemType represents. Only use this if you know what you're doing, as it returns only one element if this is not an 'every' alias.- Returns:
- An Iterable whose iterator will always return the same item(s)
-
removeAll
public @Nullable org.bukkit.inventory.ItemStack removeAll(@Nullable org.bukkit.inventory.ItemStack item) -
removeFrom
public @Nullable org.bukkit.inventory.ItemStack removeFrom(@Nullable org.bukkit.inventory.ItemStack item)Removes this type from the item stack if appropriate- Parameters:
item
-- Returns:
- The passed ItemStack or null if the resulting amount is <= 0
-
addTo
public @Nullable org.bukkit.inventory.ItemStack addTo(@Nullable org.bukkit.inventory.ItemStack item)Adds this ItemType to the given item stack- Parameters:
item
-- Returns:
- The passed ItemStack or a new one if the passed is null or air
-
clone
-
getRandom
public org.bukkit.inventory.ItemStack getRandom()- Returns:
- One random ItemStack that this ItemType represents. If you have a List or an Inventory, use
addTo(Inventory)
oraddTo(List)
respectively. - See Also:
addTo(Inventory)
,addTo(ItemStack)
,addTo(ItemStack[])
,addTo(List)
,removeFrom(Inventory)
,removeFrom(ItemStack)
,removeFrom(List...)
-
hasSpace
public boolean hasSpace(org.bukkit.inventory.Inventory invi)Test whether this ItemType can be put into the given inventory completely.REMIND If this ItemType represents multiple items with OR, this function will immediately return false.
CondCanHold currently blocks aliases without 'every'/'all' as temporary solution.- Parameters:
invi
-- Returns:
- Whether this item type can be added to the given inventory
-
getCopiedContents
public static org.bukkit.inventory.ItemStack[] getCopiedContents(org.bukkit.inventory.Inventory invi) -
getStorageContents
public static org.bukkit.inventory.ItemStack[] getStorageContents(org.bukkit.inventory.Inventory invi)Gets copy of storage contents, i.e. ignores armor and off hand. This is due to Spigot 1.9 added armor slots, and off hand to default inventory index.- Parameters:
invi
- Inventory- Returns:
- Copied storage contents
-
getTypes
- Returns:
- List of ItemDatas. The returned list is not modifiable, use
add(ItemData)
andremove(ItemData)
if you need to change the list, or use theiterator()
.
-
numTypes
public int numTypes() -
numItems
public int numItems()- Returns:
- How many different items this item type represents
-
iterator
-
isContainedIn
-
isContainedIn
public boolean isContainedIn(org.bukkit.inventory.ItemStack[] items) -
removeAll
public boolean removeAll(org.bukkit.inventory.Inventory invi) -
removeFrom
public boolean removeFrom(org.bukkit.inventory.Inventory invi)Removes this type from the given inventory. Does not call updateInventory for players.- Parameters:
invi
-- Returns:
- Whether everything could be removed from the inventory
-
removeAll
-
removeFrom
- Parameters:
lists
- The lists to remove this type from. Each list should implementRandomAccess
.- Returns:
- Whether this whole item type could be removed (i.e. returns false if the lists didn't contain this item type completely)
-
addTo
Adds this ItemType to the given list, without filling existing stacks.- Parameters:
list
-
-
addTo
public boolean addTo(org.bukkit.inventory.Inventory invi)Tries to add this ItemType to the given inventory. Does not call updateInventory for players.- Parameters:
invi
-- Returns:
- Whether everything could be added to the inventory
-
addTo
public boolean addTo(org.bukkit.inventory.ItemStack[] buf) -
isSubset
Tests whether a given set of ItemTypes is a subset of another set of ItemTypes.This method works differently that normal set operations, as is e.g. returns true if set == {everything}.
- Parameters:
set
-sub
-- Returns:
- Whether all item types in sub have at least one
super type
in set
-
equals
-
isSimilar
Compares two ItemTypes, ignoring stack size. Please note that ItemTypes do not need to be EXACTLY the same outside of stack size for this method to return true. Several factors influence theMatchQuality
required for this method to return true. For example, if the other ItemType is an alias and this one is not, the ItemTypes must only share a material. In general though, this ItemType must have all of the qualities of the other ItemType. It may have additional qualities that the other ItemType does not have though.- Parameters:
other
- The ItemType to compare with.- Returns:
- Whether this ItemType is similar to the other ItemType.
-
hashCode
public int hashCode() -
toString
-
toString
-
toString
-
toString
-
toString
-
toString
-
getDebugMessage
-
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
-
getRawNames
Gets raw item names ("minecraft:some_item"). If they are not available, empty list will be returned.- Returns:
- names List of names that could be retrieved.
-
getEnchantments
Deprecated.Gets all enchantments of this item.- Returns:
- Enchantments.
-
addEnchantments
@Deprecated public void addEnchantments(Map<org.bukkit.enchantments.Enchantment,Integer> enchantments)Deprecated.Adds enchantments to this item type.- Parameters:
enchantments
- Enchantments.
-
getEnchantmentTypes
Gets all enchantments of this item.- Returns:
- the enchantments of this item type.
-
hasEnchantments
public boolean hasEnchantments()Checks whether this item type has enchantments. -
hasEnchantments
public boolean hasEnchantments(org.bukkit.enchantments.Enchantment... enchantments)Checks whether this item type has the given enchantments.- Parameters:
enchantments
- the enchantments to be checked.
-
hasAnyEnchantments
public boolean hasAnyEnchantments(org.bukkit.enchantments.Enchantment... enchantments)Checks whether this item type contains at most one of the given enchantments.- Parameters:
enchantments
- The enchantments to be checked.
-
hasEnchantments
Checks whether this item type contains the given enchantments. Also checks the enchantment level.- Parameters:
enchantments
- The enchantments to be checked.
-
addEnchantments
Adds the given enchantments to the item type.- Parameters:
enchantments
- The enchantments to be added.
-
removeEnchantments
Removes the given enchantments from this item type.- Parameters:
enchantments
- The enchantments to be removed.
-
clearEnchantments
public void clearEnchantments()Clears all enchantments from this item type except the ones that are defined for individual item datas only. -
getItemMeta
public org.bukkit.inventory.meta.ItemMeta getItemMeta()Gets item meta that applies to all items represented by this type.- Returns:
- Item meta.
-
setItemMeta
public void setItemMeta(org.bukkit.inventory.meta.ItemMeta meta)Sets item meta that is applied for everything this type represents. Note that previous item meta is overridden if it exists.- Parameters:
meta
- New item meta.
-
clearItemMeta
public void clearItemMeta()Clears item meta from this type. Metas which individual item dates may have will not be touched. -
getMaterial
public org.bukkit.Material getMaterial() -
getBaseType
Returns a base item type of this. Essentially, this callsItemData.aliasCopy()
on all datas and creates a new type containing the results.- Returns:
- Base item type.
-
addEnchantments(EnchantmentType...)