Package org.bukkit.inventory

# Interface ItemFactory

public interface ItemFactory
An instance of the ItemFactory can be obtained with `Server.getItemFactory()`.

The ItemFactory is solely responsible for creating item meta containers to apply on item stacks.

## Method Summary

Modifier and Type
Method
Description
`HoverEvent<HoverEvent.ShowItem>`
`asHoverEvent(@NotNull ItemStack item, UnaryOperator<HoverEvent.ShowItem> op)`
Creates a hover event for the given item.
`@Nullable ItemMeta`
`asMetaFor(@NotNull ItemMeta meta, @NotNull ItemStack stack)`
Returns an appropriate item meta for the specified stack.
`@Nullable ItemMeta`
`asMetaFor(@NotNull ItemMeta meta, @NotNull Material material)`
Returns an appropriate item meta for the specified material.
`Component`
`displayName(@NotNull ItemStack itemStack)`
Get the formatted display name of the `ItemStack`.
`@NotNull ItemStack`
`ensureServerConversions(@NotNull ItemStack item)`
Minecraft updates are converting simple item stacks into more complex NBT oriented Item Stacks.
`boolean`
`equals(@Nullable ItemMeta meta1, @Nullable ItemMeta meta2)`
This method is used to compare two item meta data objects.
`@NotNull Color`
`getDefaultLeatherColor()`
Returns the default color for all leather armor.
`@Nullable String`
`getI18NDisplayName(@Nullable ItemStack item)`
Gets the Display name as seen in the Client.
`ItemMeta`
`getItemMeta(@NotNull Material material)`
This creates a new item meta for the material.
`@Nullable ItemStack`
`getSpawnEgg(EntityType type)`
Get a spawn egg ItemStack from an EntityType
`Content`
`hoverContentOf(@NotNull ItemStack itemStack)`
Creates a `Content` of that ItemStack for displaying.
`Content`
`hoverContentOf(Entity entity)`
Deprecated.
use `HoverEventSource.asHoverEvent()`
`Content`
`hoverContentOf(Entity entity, @NotNull BaseComponent[] customName)`
Deprecated.
use `Entity.asHoverEvent(java.util.function.UnaryOperator)`
`Content`
`hoverContentOf(Entity entity, @Nullable String customName)`
Deprecated.
use `Entity.asHoverEvent(java.util.function.UnaryOperator)`
`Content`
`hoverContentOf(Entity entity, BaseComponent customName)`
Deprecated.
use `Entity.asHoverEvent(java.util.function.UnaryOperator)`
`boolean`
`isApplicable(@Nullable ItemMeta meta, @Nullable 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(@Nullable ItemMeta meta, @Nullable Material material)`
This method checks the item meta to confirm that it is applicable (no data lost if applied) to the specified Material.
`@NotNull Material`
`updateMaterial(@NotNull ItemMeta meta, @NotNull Material material)`
Deprecated.
for internal use only

## Method Details

### getItemMeta

ItemMeta getItemMeta(@NotNull @NotNull Material material)
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 @Nullable ItemMeta meta, @Nullable @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 normal `ItemMeta` from an enchanted dirt block would.

Parameters:
  `meta` - Meta to check
  `stack` - 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 @Nullable ItemMeta meta, @Nullable @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 normal `ItemMeta` from an enchanted dirt block would.

Parameters:
  `meta` - Meta to check
  `material` - 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

boolean equals(@Nullable @Nullable ItemMeta meta1, @Nullable @Nullable ItemMeta meta2) throws IllegalArgumentException
This method is used to compare two item meta data objects.

Parameters:
  `meta1` - First meta to compare, and may be null to indicate no data
  `meta2` - 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 @Nullable ItemMeta asMetaFor(@NotNull @NotNull ItemMeta meta, @NotNull @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 a `BookMeta` containing all information in the specified meta that is applicable to an `ItemMeta`, the highest common interface.

Parameters:
  `meta` - the meta to convert
  `stack` - 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 @Nullable ItemMeta asMetaFor(@NotNull @NotNull ItemMeta meta, @NotNull @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 a `BookMeta` containing all information in the specified meta that is applicable to an `ItemMeta`, the highest common interface.

Parameters:
  `meta` - the meta to convert
  `material` - 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

@NotNull @NotNull Color getDefaultLeatherColor()
Returns the default color for all leather armor.

Returns:
  the default color for leather armor

### updateMaterial

@Deprecated @NotNull @NotNull Material updateMaterial(@NotNull @NotNull ItemMeta meta, @NotNull @NotNull Material material) throws IllegalArgumentException
Deprecated.
for internal use only
Apply a material change for an item meta. Do not use under any circumstances.

Parameters:
  `meta` - meta
  `material` - material
Returns:
  updated material
Throws:
  `IllegalArgumentException` - if bad material or data

### asHoverEvent

@NotNull HoverEvent<HoverEvent.ShowItem> asHoverEvent(@NotNull @NotNull ItemStack item, @NotNull UnaryOperator<HoverEvent.ShowItem> op)
Creates a hover event for the given item.

Parameters:
  `item` - The item
Returns:
  A hover event

### displayName

@NotNull Component displayName(@NotNull @NotNull ItemStack itemStack)
Get the formatted display name of the `ItemStack`.

Parameters:
  `itemStack` - the `ItemStack`
Returns:
  display name of the `ItemStack`

### getI18NDisplayName

@Nullable @Nullable String getI18NDisplayName(@Nullable @Nullable ItemStack item)
Gets the Display name as seen in the Client. Currently the server only supports the English language. To override this, You must replace the language file embedded in the server jar.

Parameters:
  `item` - Item to return Display name of
Returns:
  Display name of Item

### ensureServerConversions

@NotNull @NotNull ItemStack ensureServerConversions(@NotNull @NotNull ItemStack item)
Minecraft updates are converting simple item stacks into more complex NBT oriented Item Stacks. Use this method to to ensure any desired data conversions are processed. The input itemstack will not be the same as the returned itemstack.

Parameters:
  `item` - The item to process conversions on
Returns:
  A potentially Data Converted ItemStack

### hoverContentOf

@NotNull Content hoverContentOf(@NotNull @NotNull ItemStack itemStack)
Creates a `Content` of that ItemStack for displaying.

Parameters:
  `itemStack` -
Returns:
  the `Content` of that ItemStack

### hoverContentOf

@NotNull @Deprecated Content hoverContentOf(@NotNull Entity entity)
Deprecated.
use `HoverEventSource.asHoverEvent()`
Creates a `Content` of that `Entity` for displaying. Uses the display name of the entity, if present.

Parameters:
  `entity` - Entity to create the HoverEvent for
Returns:
  the `Content` of that `Entity`

### hoverContentOf

@NotNull @Deprecated Content hoverContentOf(@NotNull Entity entity, @Nullable @Nullable String customName)
Deprecated.
use `Entity.asHoverEvent(java.util.function.UnaryOperator)`
Creates a `Content` of that `Entity` for displaying.

Parameters:
  `entity` - Entity to create the HoverEvent for
  `customName` - a custom name that should be displayed, if not passed entity name will be displayed
Returns:
  the `Content` of that `Entity`

### hoverContentOf

@NotNull @Deprecated Content hoverContentOf(@NotNull Entity entity, @Nullable BaseComponent customName)
Deprecated.
use `Entity.asHoverEvent(java.util.function.UnaryOperator)`
Creates a `Content` of that `Entity` for displaying.

Parameters:
  `entity` - Entity to create the HoverEvent for
  `customName` - a custom name that should be displayed, if not passed entity name will be displayed
Returns:
  the `Content` of that `Entity`

### hoverContentOf

@NotNull @Deprecated Content hoverContentOf(@NotNull Entity entity, @NotNull @NotNull BaseComponent[] customName)
Deprecated.
use `Entity.asHoverEvent(java.util.function.UnaryOperator)`
Creates a `Content` of that `Entity` for displaying.

Parameters:
  `entity` - Entity to create the HoverEvent for
  `customName` - a custom name that should be displayed, if not passed entity name will be displayed
Returns:
  the `Content` of that `Entity`

### getSpawnEgg

@Nullable @Nullable ItemStack getSpawnEgg(@Nullable EntityType type)
Get a spawn egg ItemStack from an EntityType

Parameters:
  `type` - EntityType
Returns:
  ItemStack spawner egg