Interface ItemFactory
Server.getItemFactory()
.
The ItemFactory is solely responsible for creating item meta containers to apply on item stacks.
-
Method Summary
Modifier and TypeMethodDescriptionCreates a hover event for the given item.Returns an appropriate item meta for the specified stack.Returns an appropriate item meta for the specified material.createItemStack
(@NotNull String input) Create a newItemStack
given the supplied input.displayName
(@NotNull ItemStack itemStack) Get the formatted display name of theItemStack
.enchantWithLevels
(@NotNull ItemStack itemStack, @org.jetbrains.annotations.Range(from=1L, to=30L) int levels, boolean allowTreasure, Random random) Randomly enchants a copy of the providedItemStack
using the given experience levels.Minecraft updates are converting simple item stacks into more complex NBT oriented Item Stacks.boolean
This method is used to compare two item meta data objects.Returns the default color for all leather armor.Deprecated.getItemMeta
(@NotNull Material material) This creates a new item meta for the material.getSpawnEgg
(EntityType type) Get a spawn egg ItemStack from an EntityTypenet.md_5.bungee.api.chat.hover.content.Content
hoverContentOf
(@NotNull ItemStack itemStack) Creates aContent
of that ItemStack for displaying.net.md_5.bungee.api.chat.hover.content.Content
hoverContentOf
(Entity entity) Deprecated.net.md_5.bungee.api.chat.hover.content.Content
hoverContentOf
(Entity entity, @NotNull net.md_5.bungee.api.chat.BaseComponent[] customName) Deprecated.net.md_5.bungee.api.chat.hover.content.Content
hoverContentOf
(Entity entity, @Nullable String customName) Deprecated.net.md_5.bungee.api.chat.hover.content.Content
hoverContentOf
(Entity entity, net.md_5.bungee.api.chat.BaseComponent customName) Deprecated.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.updateMaterial
(@NotNull ItemMeta meta, @NotNull Material material) Deprecated.for internal use only
-
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 @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 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 @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 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
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 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 @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 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 @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 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
@NotNull @NotNull ItemStack createItemStack(@NotNull @NotNull String input) throws IllegalArgumentException 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{Enchantments:[{id:"minecraft:sharpness", lvl:3}]}" would yield an ItemStack ofMaterial.DIAMOND_SWORD
with anItemMeta
containing a level 3Enchantment.DAMAGE_ALL
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
-
updateMaterial
@Deprecated @NotNull @NotNull Material updateMaterial(@NotNull @NotNull ItemMeta meta, @NotNull @NotNull Material material) throws IllegalArgumentException Deprecated.for internal use onlyApply a material change for an item meta. Do not use under any circumstances.- Parameters:
meta
- metamaterial
- material- Returns:
- updated material
- Throws:
IllegalArgumentException
- if bad material or data
-
enchantWithLevels
@NotNull @NotNull ItemStack enchantWithLevels(@NotNull @NotNull ItemStack itemStack, @org.jetbrains.annotations.Range(from=1L, to=30L) int levels, boolean allowTreasure, @NotNull Random random) Randomly enchants a copy of the providedItemStack
using the given experience levels.If the provided ItemStack is already enchanted, the existing enchants will be removed before enchanting.
Levels must be in range
[1, 30]
.- Parameters:
itemStack
- ItemStack to enchantlevels
- levels to use for enchantingallowTreasure
- whether to allow enchantments whereEnchantment.isTreasure()
returns truerandom
-Random
instance to use for enchanting- Returns:
- enchanted copy of the provided ItemStack
- Throws:
IllegalArgumentException
- on bad arguments
-
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
Get the formatted display name of theItemStack
. -
getI18NDisplayName
Deprecated.ItemStack
implementsTranslatable
; use that andComponent.translatable(net.kyori.adventure.translation.Translatable)
instead.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
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 net.md_5.bungee.api.chat.hover.content.Content hoverContentOf(@NotNull @NotNull ItemStack itemStack) Creates aContent
of that ItemStack for displaying.- Parameters:
itemStack
-- Returns:
- the
Content
of that ItemStack
-
hoverContentOf
@NotNull @Deprecated net.md_5.bungee.api.chat.hover.content.Content hoverContentOf(@NotNull Entity entity) Deprecated.Creates aContent
of thatEntity
for displaying. Uses the display name of the entity, if present.- Parameters:
entity
- Entity to create the HoverEvent for- Returns:
- the
Content
of thatEntity
-
hoverContentOf
@NotNull @Deprecated net.md_5.bungee.api.chat.hover.content.Content hoverContentOf(@NotNull Entity entity, @Nullable @Nullable String customName) Deprecated.Creates aContent
of thatEntity
for displaying.- Parameters:
entity
- Entity to create the HoverEvent forcustomName
- a custom name that should be displayed, if not passed entity name will be displayed- Returns:
- the
Content
of thatEntity
-
hoverContentOf
@NotNull @Deprecated net.md_5.bungee.api.chat.hover.content.Content hoverContentOf(@NotNull Entity entity, @Nullable net.md_5.bungee.api.chat.BaseComponent customName) Deprecated.Creates aContent
of thatEntity
for displaying.- Parameters:
entity
- Entity to create the HoverEvent forcustomName
- a custom name that should be displayed, if not passed entity name will be displayed- Returns:
- the
Content
of thatEntity
-
hoverContentOf
@NotNull @Deprecated net.md_5.bungee.api.chat.hover.content.Content hoverContentOf(@NotNull Entity entity, @NotNull @NotNull net.md_5.bungee.api.chat.BaseComponent[] customName) Deprecated.Creates aContent
of thatEntity
for displaying.- Parameters:
entity
- Entity to create the HoverEvent forcustomName
- a custom name that should be displayed, if not passed entity name will be displayed- Returns:
- the
Content
of thatEntity
-
getSpawnEgg
Get a spawn egg ItemStack from an EntityType- Parameters:
type
- EntityType- Returns:
- ItemStack spawner egg
-
ItemStack
implementsTranslatable
; use that andComponent.translatable(net.kyori.adventure.translation.Translatable)
instead.