Interface ItemFactory
Server.getItemFactory()
.
The ItemFactory is solely responsible for creating item meta containers to apply on item stacks.
-
Method Summary
Modifier and TypeMethodDescriptionReturns an appropriate item meta for the specified stack.Returns an appropriate item meta for the specified material.createItemStack
(String input) Create a newItemStack
given the supplied input.enchantItem
(Entity entity, ItemStack item, int level, boolean allowTreasures) Enchants the given item at the provided level.enchantItem
(ItemStack item, int level, boolean allowTreasures) Enchants the given item at the provided level.enchantItem
(World world, ItemStack item, int level, boolean allowTreasures) Enchants the given item at the provided level.boolean
This method is used to compare two item meta data objects.Returns the default color for all leather armor.getItemMeta
(Material material) This creates a new item meta for the material.getSpawnEgg
(EntityType type) Gets aMaterial
representing the spawn egg for the providedEntityType
.boolean
isApplicable
(ItemMeta meta, ItemStack stack) This method checks the item meta to confirm that it is applicable (no data lost if applied) to the specified ItemStack.boolean
isApplicable
(ItemMeta meta, Material material) This method checks the item meta to confirm that it is applicable (no data lost if applied) to the specified Material.
-
Method Details
-
getItemMeta
This creates a new item meta for the material.- Parameters:
material
- The material to consider as base for the meta- Returns:
- a new ItemMeta that could be applied to an item stack of the specified material
-
isApplicable
boolean isApplicable(@Nullable ItemMeta meta, @Nullable ItemStack stack) throws IllegalArgumentException This method checks the item meta to confirm that it is applicable (no data lost if applied) to the specified ItemStack.A
SkullMeta
would not be valid for a sword, but a normalItemMeta
from an enchanted dirt block would.- Parameters:
meta
- Meta to checkstack
- Item that meta will be applied to- Returns:
- true if the meta can be applied without losing data, false otherwise
- Throws:
IllegalArgumentException
- if the meta was not created by this factory
-
isApplicable
boolean isApplicable(@Nullable ItemMeta meta, @Nullable Material material) throws IllegalArgumentException This method checks the item meta to confirm that it is applicable (no data lost if applied) to the specified Material.A
SkullMeta
would not be valid for a sword, but a normalItemMeta
from an enchanted dirt block would.- Parameters:
meta
- Meta to checkmaterial
- Material that meta will be applied to- Returns:
- true if the meta can be applied without losing data, false otherwise
- Throws:
IllegalArgumentException
- if the meta was not created by this factory
-
equals
This method is used to compare two item meta data objects.- Parameters:
meta1
- First meta to compare, and may be null to indicate no datameta2
- Second meta to compare, and may be null to indicate no data- Returns:
- false if one of the meta has data the other does not, otherwise true
- Throws:
IllegalArgumentException
- if either meta was not created by this factory
-
asMetaFor
@Nullable ItemMeta asMetaFor(@NotNull ItemMeta meta, @NotNull ItemStack stack) throws IllegalArgumentException Returns an appropriate item meta for the specified stack.The item meta returned will always be a valid meta for a given ItemStack of the specified material. It may be a more or less specific meta, and could also be the same meta or meta type as the parameter. The item meta returned will also always be the most appropriate meta.
Example, if a
SkullMeta
is being applied to a book, this method would return aBookMeta
containing all information in the specified meta that is applicable to anItemMeta
, the highest common interface.- Parameters:
meta
- the meta to convertstack
- the stack to convert the meta for- Returns:
- An appropriate item meta for the specified item stack. No guarantees are made as to if a copy is returned. This will be null for a stack of air.
- Throws:
IllegalArgumentException
- if the specified meta was not created by this factory
-
asMetaFor
@Nullable ItemMeta asMetaFor(@NotNull ItemMeta meta, @NotNull Material material) throws IllegalArgumentException Returns an appropriate item meta for the specified material.The item meta returned will always be a valid meta for a given ItemStack of the specified material. It may be a more or less specific meta, and could also be the same meta or meta type as the parameter. The item meta returned will also always be the most appropriate meta.
Example, if a
SkullMeta
is being applied to a book, this method would return aBookMeta
containing all information in the specified meta that is applicable to anItemMeta
, the highest common interface.- Parameters:
meta
- the meta to convertmaterial
- the material to convert the meta for- Returns:
- An appropriate item meta for the specified item material. No guarantees are made as to if a copy is returned. This will be null for air.
- Throws:
IllegalArgumentException
- if the specified meta was not created by this factory
-
getDefaultLeatherColor
Returns the default color for all leather armor.- Returns:
- the default color for leather armor
-
createItemStack
Create a newItemStack
given the supplied input.The input should match the same input as expected by Minecraft's
/give
command. For example,"minecraft:diamond_sword[minecraft:enchantments={levels:{"minecraft:sharpness": 3}}]"
would yield an ItemStack ofMaterial.DIAMOND_SWORD
with anItemMeta
containing a level 3Enchantment.SHARPNESS
enchantment.- Parameters:
input
- the item input string- Returns:
- the created ItemStack
- Throws:
IllegalArgumentException
- if the input string was provided in an invalid or unsupported format
-
getSpawnEgg
Gets aMaterial
representing the spawn egg for the providedEntityType
.
Will return null for EntityTypes that do not have a corresponding spawn egg.- Parameters:
type
- the entity type- Returns:
- the Material of this EntityTypes spawn egg or null
-
enchantItem
@NotNull ItemStack enchantItem(@NotNull Entity entity, @NotNull ItemStack item, int level, boolean allowTreasures) Enchants the given item at the provided level.
If an item that is air is passed through an error is thrown.- Parameters:
entity
- the entity to use as a source of randomnessitem
- the item to enchantlevel
- the level to use, which is the level in the enchantment tableallowTreasures
- allows treasure enchants, e.g. mending, if true.- Returns:
- a new ItemStack containing the result of the Enchantment
-
enchantItem
@NotNull ItemStack enchantItem(@NotNull World world, @NotNull ItemStack item, int level, boolean allowTreasures) Enchants the given item at the provided level.
If an item that is air is passed through an error is thrown.- Parameters:
world
- the world to use as a source of randomnessitem
- the item to enchantlevel
- the level to use, which is the level in the enchantment tableallowTreasures
- allow the treasure enchants, e.g. mending, if true.- Returns:
- a new ItemStack containing the result of the Enchantment
-
enchantItem
Enchants the given item at the provided level.
If an item that is air is passed through an error is thrown.- Parameters:
item
- the item to enchantlevel
- the level to use, which is the level in the enchantment tableallowTreasures
- allow treasure enchantments, e.g. mending, if true.- Returns:
- a new ItemStack containing the result of the Enchantment
-