Class ItemCache

java.lang.Object
valorless.rarespawns.builders.ItemCache

public class ItemCache extends Object
ItemCache is a utility class for creating and caching custom items in the RareSpawns plugin. It handles the creation, retrieval, and management of custom items, including loading item configurations from files. Primarily used for admins to get copies of items using '/rare item '.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected static Boolean
    Indicates whether the item cache has been fully loaded and is ready for use.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    addItem(String id, org.bukkit.inventory.ItemStack item)
    Adds a new item to the collection with the provided ID.
    static org.bukkit.inventory.ItemStack
    createItem(valorless.valorlessutils.config.Config config, String id)
    Creates an ItemStack object from a configuration file.
    static org.bukkit.inventory.ItemStack
    Retrieves an item by its unique ID.
    static ItemData
    Retrieves the ItemData for a given item ID from the loaded config files.
    static HashMap<String,org.bukkit.inventory.ItemStack>
    Returns a clone of the items map containing all custom items.
    static Boolean
    Returns whether the item cache is fully loaded and ready for use.
    static ItemData
    prepareData(valorless.valorlessutils.config.Config config, String id)
    Prepares all necessary item data from the configuration for a specific item ID.
    static void
    Reloads all items from the 'items' folder, creating or updating the collection of items.
    static boolean
    Removes an item from the collection by its ID.

    Methods inherited from class java.lang.Object

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

    • ready

      protected static Boolean ready
      Indicates whether the item cache has been fully loaded and is ready for use.
  • Constructor Details

    • ItemCache

      public ItemCache()
  • Method Details

    • isReady

      public static Boolean isReady()
      Returns whether the item cache is fully loaded and ready for use.
      Returns:
      true if items are loaded and cached; false otherwise
    • getItems

      public static HashMap<String,org.bukkit.inventory.ItemStack> getItems()
      Returns a clone of the items map containing all custom items.
      Returns:
      A cloned HashMap of item IDs to ItemStacks.
    • getItem

      public static org.bukkit.inventory.ItemStack getItem(String id)
      Retrieves an item by its unique ID.
      Parameters:
      id - The unique ID of the item.
      Returns:
      The ItemStack associated with the ID, or null if no item is found.
    • getItemData

      public static ItemData getItemData(String id)
      Retrieves the ItemData for a given item ID from the loaded config files.
      Parameters:
      id - The unique ID of the item.
      Returns:
      The ItemData object for the item.
    • addItem

      public static boolean addItem(String id, org.bukkit.inventory.ItemStack item) throws Exception
      Adds a new item to the collection with the provided ID. Validates the ID and item before adding.
      Parameters:
      id - The unique ID of the item to be added.
      item - The ItemStack that represents the item.
      Returns:
      True if the item was successfully added; false if the ID already exists or if an error occurs.
      Throws:
      Exception - If the ID is null or empty, or if the item is null or AIR.
    • removeItem

      public static boolean removeItem(String id)
      Removes an item from the collection by its ID.
      Parameters:
      id - The unique ID of the item to remove.
      Returns:
      True if the item was removed, false if not found.
    • reload

      public static void reload()
      Reloads all items from the 'items' folder, creating or updating the collection of items. It will either add new items or update existing ones.
    • createItem

      public static org.bukkit.inventory.ItemStack createItem(valorless.valorlessutils.config.Config config, String id)
      Creates an ItemStack object from a configuration file. This method constructs an ItemStack with attributes such as material, name, lore, enchantments, attributes, item flags, durability, NBT data, and custom tags based on the provided configuration. It ensures that the item has all the necessary properties defined.
      Parameters:
      config - The configuration object containing data for the item.
      id - The unique identifier for the item.
      Returns:
      The fully constructed ItemStack object.
    • prepareData

      public static ItemData prepareData(valorless.valorlessutils.config.Config config, String id)
      Prepares all necessary item data from the configuration for a specific item ID. This method gathers shared data as well as enchants and attributes if they exist in the config.
      Parameters:
      config - The configuration object containing the item properties.
      id - The unique identifier for the item in the configuration.
      Returns:
      An ItemData object populated with all relevant properties, including enchants and attributes at the highest applicable level.