Class ItemUtil

java.lang.Object
net.mathias2246.buildmc.api.item.ItemUtil

public final class ItemUtil extends Object
A helper-class for items.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    editMeta(@NotNull org.bukkit.inventory.ItemStack itemStack, @NotNull Consumer<@NotNull org.bukkit.inventory.meta.ItemMeta> consumer)
    A helper method for editing ItemMeta using a Consumer that takes in an ItemMeta instance.
    static @Nullable AbstractCustomItem
    getCustomItemFromItemStack(@NotNull org.bukkit.inventory.ItemStack itemStack)
    Will try to get a AbstractCustomItem from an ItemStack if it is a custom item.
    static void
    setName(@NotNull org.bukkit.inventory.ItemStack itemStack, @Nullable net.kyori.adventure.text.Component name)
    Sets the name of an ItemStack to the given Component.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ItemUtil

      public ItemUtil()
  • Method Details

    • editMeta

      public static void editMeta(@NotNull @NotNull org.bukkit.inventory.ItemStack itemStack, @NotNull @NotNull Consumer<@NotNull org.bukkit.inventory.meta.ItemMeta> consumer)
      A helper method for editing ItemMeta using a Consumer that takes in an ItemMeta instance.

      The edited ItemMeta instance will be automatically be set on the ItemStack instance after editing.

      If the meta returned by itemStack.getItemMeta(); equals null, nothing will happen.

      Parameters:
      itemStack - The ItemStack that should be edited
      consumer - The consumer used to edit the ItemMeta
    • getCustomItemFromItemStack

      @Nullable public static @Nullable AbstractCustomItem getCustomItemFromItemStack(@NotNull @NotNull org.bukkit.inventory.ItemStack itemStack)
      Will try to get a AbstractCustomItem from an ItemStack if it is a custom item.
      Returns:
      The AbstractCustomItem, or null if not a custom item.
    • setName

      public static void setName(@NotNull @NotNull org.bukkit.inventory.ItemStack itemStack, @Nullable @Nullable net.kyori.adventure.text.Component name)
      Sets the name of an ItemStack to the given Component.