Class ItemUtils

java.lang.Object
ua.mcchickenstudio.opencreative.utils.ItemUtils

public final class ItemUtils extends Object

ItemUtils

This class represents an utils for changing items.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static @NotNull org.bukkit.inventory.ItemStack
    addLoreAtBegin(@NotNull org.bukkit.inventory.ItemStack item, @NotNull String loreLine)
     
    static @NotNull org.bukkit.inventory.ItemStack
    addLoreAtEnd(@NotNull org.bukkit.inventory.ItemStack item, @NotNull String loreLine)
     
    static @NotNull org.bukkit.inventory.ItemStack
    clearItemFlags(@NotNull org.bukkit.inventory.ItemStack itemStack)
     
    static @NotNull org.bukkit.inventory.ItemStack
    clearItemMeta(@NotNull org.bukkit.inventory.ItemStack itemStack)
     
    static @NotNull org.bukkit.inventory.ItemStack
    createItem(@NotNull org.bukkit.Material material, int amount)
     
    static @NotNull org.bukkit.inventory.ItemStack
    createItem(@NotNull org.bukkit.Material material, int amount, @NotNull String localizationPath)
    Returns item stack with name and description found in localization file.
    static @NotNull org.bukkit.inventory.ItemStack
    createItem(@NotNull org.bukkit.Material material, int amount, @NotNull String localizationPath, @NotNull String persistentData)
    Returns item stack with name, description found in localization file and persistent data.
    static @NotNull org.bukkit.inventory.ItemStack
    createItem(@NotNull org.bukkit.Material material, int amount, @NotNull String localizationPath, Object value)
    Returns item stack with name and description found in localization file.
    static @NotNull org.bukkit.inventory.ItemStack
    createItem(@NotNull org.bukkit.inventory.ItemStack item, @NotNull String localizationPath)
    Returns item stack with name and description found in localization file.
    static @NotNull org.bukkit.inventory.ItemStack
    createItem(@NotNull org.bukkit.inventory.ItemStack item, @NotNull String localizationPath, @NotNull String persistentData)
    Returns item stack with name, description found in localization file and persistent data.
    static boolean
    doesItemRequireSpecialData(@NotNull org.bukkit.inventory.ItemStack item)
    Checks whether item should be saved as bytes array instead of just material.
    static org.bukkit.inventory.ItemStack
    fixItem(@NotNull org.bukkit.inventory.ItemStack item)
    Removes bad things from item: enchants with big level, attribute modifiers, books with a lot of pages, containers with containers; or replaces items with air.
    static @NotNull org.bukkit.inventory.ItemStack
    fixItem(@NotNull org.bukkit.inventory.ItemStack item, int displayNameMaxLength, int loreLineMaxLength, int loreLinesLimit, int maxEnchantLevel, int bookPagesLimit, boolean removeClickableBooks, int containerBigItemsLimit, int entitiesLimit, boolean removeCustomEggs, boolean removeBossEggs, boolean removeAttributes, boolean clearCommandBlocksData)
    Removes bad things from item: enchants with big level, attribute modifiers, books with a lot of pages, containers with containers; or replaces items with air.
    static @NotNull org.bukkit.NamespacedKey
     
    static @NotNull org.bukkit.NamespacedKey
     
    static @NotNull org.bukkit.NamespacedKey
     
    static @NotNull org.bukkit.NamespacedKey
     
    static @NotNull org.bukkit.NamespacedKey
     
    static @NotNull org.bukkit.NamespacedKey
     
    static @NotNull org.bukkit.NamespacedKey
     
    static @NotNull org.bukkit.NamespacedKey
     
    static int
    getInsideBadItemsAmount(@NotNull org.bukkit.inventory.ItemStack item, int limit)
     
    static @NotNull org.bukkit.NamespacedKey
     
    static @NotNull org.bukkit.NamespacedKey
     
    static @NotNull String
    getItemType(@NotNull org.bukkit.inventory.ItemStack item)
     
    static @NotNull org.bukkit.NamespacedKey
     
    static @NotNull org.bukkit.inventory.ItemStack
    getItemWithIgnoreData(@NotNull org.bukkit.inventory.ItemStack item, boolean removeAmount, boolean removeName, boolean removeLore, boolean removeFlags, boolean removeEnchantments, boolean removeMaterial, boolean removeDurability)
     
    static @NotNull org.bukkit.inventory.meta.ItemMeta
    getOrCreateItemMeta(@NotNull org.bukkit.inventory.ItemStack item)
     
    static @NotNull String
    getPersistentData(@NotNull org.bukkit.inventory.ItemStack item, @NotNull org.bukkit.NamespacedKey key)
     
    static int
    getPersistentDataAmount(@NotNull org.bukkit.inventory.ItemStack item)
     
    static @NotNull ValueType
    getValueType(@NotNull org.bukkit.inventory.ItemStack item)
     
    static boolean
    itemEquals(org.bukkit.inventory.ItemStack itemStack, org.bukkit.inventory.ItemStack itemStack2)
     
    static @NotNull org.bukkit.inventory.ItemStack
    Loads item from byte array in text.
    static @NotNull org.bukkit.inventory.ItemStack
    replacePlaceholderInLore(@NotNull org.bukkit.inventory.ItemStack item, @NotNull String placeholder, @NotNull Object value)
     
    static @NotNull org.bukkit.inventory.ItemStack
    replacePlaceholderInName(@NotNull org.bukkit.inventory.ItemStack item, @NotNull String placeholder, @NotNull Object value)
     
    static @NotNull String
    saveItemAsByteArray(@Nullable org.bukkit.inventory.ItemStack item)
    Saves item as byte array in text.
    static @NotNull org.bukkit.inventory.ItemStack
    setDisplayName(@NotNull org.bukkit.inventory.ItemStack item, @Nullable String displayName)
     
    static @NotNull org.bukkit.inventory.ItemStack
    setLore(@NotNull org.bukkit.inventory.ItemStack item, @Nullable List<String> lore)
     
    static @NotNull org.bukkit.inventory.ItemStack
    setPersistentData(@NotNull org.bukkit.inventory.ItemStack item, @NotNull org.bukkit.NamespacedKey key, double value)
     
    static @NotNull org.bukkit.inventory.ItemStack
    setPersistentData(@NotNull org.bukkit.inventory.ItemStack item, @NotNull org.bukkit.NamespacedKey key, @NotNull String value)
     

    Methods inherited from class Object

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

    • ItemUtils

      public ItemUtils()
  • Method Details

    • getCodingValueKey

      @NotNull public static @NotNull org.bukkit.NamespacedKey getCodingValueKey()
    • getCodingVariableTypeKey

      @NotNull public static @NotNull org.bukkit.NamespacedKey getCodingVariableTypeKey()
    • getCodingDoNotDropMeKey

      @NotNull public static @NotNull org.bukkit.NamespacedKey getCodingDoNotDropMeKey()
    • getCodingLocationX

      @NotNull public static @NotNull org.bukkit.NamespacedKey getCodingLocationX()
    • getCodingLocationY

      @NotNull public static @NotNull org.bukkit.NamespacedKey getCodingLocationY()
    • getCodingLocationZ

      @NotNull public static @NotNull org.bukkit.NamespacedKey getCodingLocationZ()
    • getCodingParticleTypeKey

      @NotNull public static @NotNull org.bukkit.NamespacedKey getCodingParticleTypeKey()
    • getItemTypeKey

      @NotNull public static @NotNull org.bukkit.NamespacedKey getItemTypeKey()
    • getItemIdKey

      @NotNull public static @NotNull org.bukkit.NamespacedKey getItemIdKey()
    • getCodingTargetTypeKey

      @NotNull public static @NotNull org.bukkit.NamespacedKey getCodingTargetTypeKey()
    • getItemEntityInvisible

      @NotNull public static @NotNull org.bukkit.NamespacedKey getItemEntityInvisible()
    • setPersistentData

      @NotNull public static @NotNull org.bukkit.inventory.ItemStack setPersistentData(@NotNull @NotNull org.bukkit.inventory.ItemStack item, @NotNull @NotNull org.bukkit.NamespacedKey key, @NotNull @NotNull String value)
    • setPersistentData

      @NotNull public static @NotNull org.bukkit.inventory.ItemStack setPersistentData(@NotNull @NotNull org.bukkit.inventory.ItemStack item, @NotNull @NotNull org.bukkit.NamespacedKey key, double value)
    • createItem

      @NotNull public static @NotNull org.bukkit.inventory.ItemStack createItem(@NotNull @NotNull org.bukkit.inventory.ItemStack item, @NotNull @NotNull String localizationPath, @NotNull @NotNull String persistentData)
      Returns item stack with name, description found in localization file and persistent data.
    • createItem

      @NotNull public static @NotNull org.bukkit.inventory.ItemStack createItem(@NotNull @NotNull org.bukkit.Material material, int amount, @NotNull @NotNull String localizationPath, @NotNull @NotNull String persistentData)
      Returns item stack with name, description found in localization file and persistent data.
    • createItem

      @NotNull public static @NotNull org.bukkit.inventory.ItemStack createItem(@NotNull @NotNull org.bukkit.Material material, int amount, @NotNull @NotNull String localizationPath)
      Returns item stack with name and description found in localization file.
    • createItem

      @NotNull public static @NotNull org.bukkit.inventory.ItemStack createItem(@NotNull @NotNull org.bukkit.inventory.ItemStack item, @NotNull @NotNull String localizationPath)
      Returns item stack with name and description found in localization file.
    • createItem

      @NotNull public static @NotNull org.bukkit.inventory.ItemStack createItem(@NotNull @NotNull org.bukkit.Material material, int amount, @NotNull @NotNull String localizationPath, Object value)
      Returns item stack with name and description found in localization file.
    • createItem

      @NotNull public static @NotNull org.bukkit.inventory.ItemStack createItem(@NotNull @NotNull org.bukkit.Material material, int amount)
    • clearItemFlags

      @NotNull public static @NotNull org.bukkit.inventory.ItemStack clearItemFlags(@NotNull @NotNull org.bukkit.inventory.ItemStack itemStack)
    • clearItemMeta

      @NotNull public static @NotNull org.bukkit.inventory.ItemStack clearItemMeta(@NotNull @NotNull org.bukkit.inventory.ItemStack itemStack)
    • itemEquals

      public static boolean itemEquals(org.bukkit.inventory.ItemStack itemStack, org.bukkit.inventory.ItemStack itemStack2)
    • replacePlaceholderInName

      @NotNull public static @NotNull org.bukkit.inventory.ItemStack replacePlaceholderInName(@NotNull @NotNull org.bukkit.inventory.ItemStack item, @NotNull @NotNull String placeholder, @NotNull @NotNull Object value)
    • replacePlaceholderInLore

      @NotNull public static @NotNull org.bukkit.inventory.ItemStack replacePlaceholderInLore(@NotNull @NotNull org.bukkit.inventory.ItemStack item, @NotNull @NotNull String placeholder, @NotNull @NotNull Object value)
    • setDisplayName

      @NotNull public static @NotNull org.bukkit.inventory.ItemStack setDisplayName(@NotNull @NotNull org.bukkit.inventory.ItemStack item, @Nullable @Nullable String displayName)
    • setLore

      @NotNull public static @NotNull org.bukkit.inventory.ItemStack setLore(@NotNull @NotNull org.bukkit.inventory.ItemStack item, @Nullable @Nullable List<String> lore)
    • addLoreAtBegin

      @NotNull public static @NotNull org.bukkit.inventory.ItemStack addLoreAtBegin(@NotNull @NotNull org.bukkit.inventory.ItemStack item, @NotNull @NotNull String loreLine)
    • addLoreAtEnd

      @NotNull public static @NotNull org.bukkit.inventory.ItemStack addLoreAtEnd(@NotNull @NotNull org.bukkit.inventory.ItemStack item, @NotNull @NotNull String loreLine)
    • getValueType

      @NotNull public static @NotNull ValueType getValueType(@NotNull @NotNull org.bukkit.inventory.ItemStack item)
    • getItemType

      @NotNull public static @NotNull String getItemType(@NotNull @NotNull org.bukkit.inventory.ItemStack item)
    • getPersistentData

      @NotNull public static @NotNull String getPersistentData(@NotNull @NotNull org.bukkit.inventory.ItemStack item, @NotNull @NotNull org.bukkit.NamespacedKey key)
    • getItemWithIgnoreData

      @NotNull public static @NotNull org.bukkit.inventory.ItemStack getItemWithIgnoreData(@NotNull @NotNull org.bukkit.inventory.ItemStack item, boolean removeAmount, boolean removeName, boolean removeLore, boolean removeFlags, boolean removeEnchantments, boolean removeMaterial, boolean removeDurability)
    • getOrCreateItemMeta

      @NotNull public static @NotNull org.bukkit.inventory.meta.ItemMeta getOrCreateItemMeta(@NotNull @NotNull org.bukkit.inventory.ItemStack item)
    • fixItem

      public static org.bukkit.inventory.ItemStack fixItem(@NotNull @NotNull org.bukkit.inventory.ItemStack item)
      Removes bad things from item: enchants with big level, attribute modifiers, books with a lot of pages, containers with containers; or replaces items with air.
      Parameters:
      item - item to fix.
    • fixItem

      @NotNull public static @NotNull org.bukkit.inventory.ItemStack fixItem(@NotNull @NotNull org.bukkit.inventory.ItemStack item, int displayNameMaxLength, int loreLineMaxLength, int loreLinesLimit, int maxEnchantLevel, int bookPagesLimit, boolean removeClickableBooks, int containerBigItemsLimit, int entitiesLimit, boolean removeCustomEggs, boolean removeBossEggs, boolean removeAttributes, boolean clearCommandBlocksData)
      Removes bad things from item: enchants with big level, attribute modifiers, books with a lot of pages, containers with containers; or replaces items with air.
      Parameters:
      item - item to fix.
      displayNameMaxLength - maximum length of item's display name.
      loreLineMaxLength - maximum length of item's lore line.
      loreLinesLimit - maximum amount of item's lore lines.
      maxEnchantLevel - maximum enchant level.
      bookPagesLimit - limit of books pages.
      removeClickableBooks - remove clickable components in books or not.
      containerBigItemsLimit - limit of big items (books, containers) in container.
      entitiesLimit - limit of entities in entities blocks storage (beehives).
      removeCustomEggs - removes custom spawn eggs.
      removeBossEggs - removes boss spawn eggs.
      removeAttributes - removes attribute modifiers (scale).
      clearCommandBlocksData - removes commands from command blocks.
    • getInsideBadItemsAmount

      public static int getInsideBadItemsAmount(@NotNull @NotNull org.bukkit.inventory.ItemStack item, int limit)
    • getPersistentDataAmount

      public static int getPersistentDataAmount(@NotNull @NotNull org.bukkit.inventory.ItemStack item)
    • saveItemAsByteArray

      @NotNull public static @NotNull String saveItemAsByteArray(@Nullable @Nullable org.bukkit.inventory.ItemStack item)
      Saves item as byte array in text.
      Parameters:
      item - item to serialize.
      Returns:
      string of byte array, that can be used in configs, or empty text "".
    • loadItemFromByteArray

      @NotNull public static @NotNull org.bukkit.inventory.ItemStack loadItemFromByteArray(@NotNull @NotNull String text)
      Loads item from byte array in text.
      Parameters:
      text - text with item's byte array to deserialize.
      Returns:
      item from byte array, or empty (air x0) item.
    • doesItemRequireSpecialData

      public static boolean doesItemRequireSpecialData(@NotNull @NotNull org.bukkit.inventory.ItemStack item)
      Checks whether item should be saved as bytes array instead of just material.
      Parameters:
      item - item to check.
      Returns:
      true - item can have special data, so it should be saved as bytes array to contain all information, false - can be saved as material.