Package valorless.rarespawns.builders
Class ItemCache
java.lang.Object
valorless.rarespawns.builders.ItemCache
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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanAdds a new item to the collection with the provided ID.static org.bukkit.inventory.ItemStackcreateItem(valorless.valorlessutils.config.Config config, String id) Creates an ItemStack object from a configuration file.static org.bukkit.inventory.ItemStackRetrieves an item by its unique ID.static ItemDatagetItemData(String id) Retrieves the ItemData for a given item ID from the loaded config files.getItems()Returns a clone of the items map containing all custom items.static BooleanisReady()Returns whether the item cache is fully loaded and ready for use.static ItemDataprepareData(valorless.valorlessutils.config.Config config, String id) Prepares all necessary item data from the configuration for a specific item ID.static voidreload()Reloads all items from the 'items' folder, creating or updating the collection of items.static booleanremoveItem(String id) Removes an item from the collection by its ID.
-
Field Details
-
ready
Indicates whether the item cache has been fully loaded and is ready for use.
-
-
Constructor Details
-
ItemCache
public ItemCache()
-
-
Method Details
-
isReady
Returns whether the item cache is fully loaded and ready for use.- Returns:
- true if items are loaded and cached; false otherwise
-
getItems
Returns a clone of the items map containing all custom items.- Returns:
- A cloned HashMap of item IDs to ItemStacks.
-
getItem
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
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
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
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
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.
-