### Full UniItem Plugin Integration Example Source: https://context7.com/projectunified/uniitem/llms.txt A comprehensive example of integrating UniItem into a Bukkit plugin. It demonstrates initializing the AllItemProvider, logging available types, and handling player interactions with custom items. ```java import io.github.projectunified.uniitem.all.AllItemProvider; import io.github.projectunified.uniitem.api.Item; import io.github.projectunified.uniitem.api.ItemKey; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; public class MyPlugin extends JavaPlugin implements Listener { private AllItemProvider itemProvider; @Override public void onEnable() { // Initialize the provider once itemProvider = new AllItemProvider(); // Log available item types getLogger().info("Available item types: " + itemProvider.availableTypes()); getServer().getPluginManager().registerEvents(this, this); } @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { Player player = event.getPlayer(); ItemStack heldItem = event.getItem(); if (heldItem == null) return; // Identify the custom item regardless of which plugin it's from ItemKey key = itemProvider.key(heldItem); if (key != null) { player.sendMessage("You're holding: " + key.type() + ":" + key.id()); } } // Give a custom item to a player by key string public void giveItem(Player player, String keyString) { try { ItemKey key = ItemKey.fromString(keyString); Item item = itemProvider.wrap(key); if (item.isValid()) { // Use player context for player-specific items (MMOItems, etc.) ItemStack itemStack = item.tryBukkitItem(player); if (itemStack != null) { player.getInventory().addItem(itemStack); player.sendMessage("Received: " + key.toString()); } } else { player.sendMessage("Item not found: " + keyString); } } catch (IllegalArgumentException e) { player.sendMessage("Invalid key format. Use type:id"); } } // Check if player has a specific custom item public boolean hasCustomItem(Player player, String keyString) { ItemKey targetKey = ItemKey.fromString(keyString); for (ItemStack item : player.getInventory().getContents()) { if (item != null && itemProvider.isSimilar(item, targetKey)) { return true; } } return false; } } ``` -------------------------------- ### Slimefun Provider Integration Source: https://context7.com/projectunified/uniitem/llms.txt Demonstrates how to use the SlimefunProvider to get Slimefun items. It checks for Slimefun availability and shows how to obtain items using both full and shorthand type aliases. ```java import io.github.projectunified.uniitem.api.ItemKey; import io.github.projectunified.uniitem.bukkit.provider.SlimefunProvider; import org.bukkit.inventory.ItemStack; // Check if Slimefun is available if (SlimefunProvider.isAvailable()) { SlimefunProvider provider = new SlimefunProvider(); // Get Slimefun item ItemKey key = new ItemKey("slimefun", "ELECTRIC_MOTOR"); ItemStack item = provider.item(key); // Using shorthand ItemKey shortKey = new ItemKey("sf", "GOLD_DUST"); ItemStack goldDust = provider.item(shortKey); } ``` -------------------------------- ### Basic UniItem Usage with AllItemProvider Source: https://github.com/projectunified/uniitem/wiki/Usage This Java code demonstrates the fundamental usage of the `AllItemProvider` from the UniItem library. It shows how to instantiate the provider and retrieve an `ItemStack` using an `ItemKey`, and conversely, how to get an `ItemKey` from an `ItemStack`. Note that methods can return null if the item or key is not found. ```java AllItemProvider provider = new AllItemProvider(); ItemStack item = provider.item(new ItemKey("ia", "my_item")); // Get item from key, can be null ItemKey key = provider.key(item); // Get key from item, can be null ``` -------------------------------- ### Unified Item Retrieval and Identification with AllItemProvider Source: https://context7.com/projectunified/uniitem/llms.txt Demonstrates how to use the AllItemProvider to fetch items from various plugins using their unique keys, identify items from player inventories, retrieve all available item types, and check for item similarity. This provider automatically detects and integrates with installed plugins. ```java AllItemProvider provider = new AllItemProvider(); // Get item from any supported plugin using type:id key format ItemKey iaKey = new ItemKey("ia", "my_custom_item"); ItemStack iaItem = provider.item(iaKey); // From ItemsAdder ItemKey oraxenKey = new ItemKey("oraxen", "emerald_sword"); ItemStack oraxenItem = provider.item(oraxenKey); // From Oraxen ItemKey mmoKey = new ItemKey("mmoitems", "SWORD:FIRE_BLADE"); ItemStack mmoItem = provider.item(mmoKey); // From MMOItems ItemKey sfKey = new ItemKey("sf", "ELECTRIC_MOTOR"); ItemStack sfItem = provider.item(sfKey); // From Slimefun // Identify any custom item from any plugin ItemStack unknownItem = /* item from player inventory */; ItemKey foundKey = provider.key(unknownItem); // Returns key or null if (foundKey != null) { String pluginType = foundKey.type(); // "itemsadder", "oraxen", etc. String itemId = foundKey.id(); // The item's ID } // Get all available item types across all plugins List allTypes = provider.availableTypes(); // ["itemsadder", "ia", "oraxen", "orx", "mmoitems", "mythicmobs", "mm", ...] // Check if items match boolean matches = provider.isSimilar(unknownItem, iaKey); ``` -------------------------------- ### Maven Dependency Setup for UniItem Source: https://context7.com/projectunified/uniitem/llms.txt Instructions for adding the UniItem library to a Maven project. It includes the necessary dependency declaration and configuration for the Maven Shade Plugin to relocate UniItem's package. ```xml io.github.projectunified uni-item-all 2.5.0 org.apache.maven.plugins maven-shade-plugin 3.6.0 io.github.projectunified.uniitem your.package.uniitem package shade ``` -------------------------------- ### Oraxen Item Retrieval and Identification Source: https://context7.com/projectunified/uniitem/llms.txt Illustrates how to use the OraxenProvider to get Oraxen custom items via their keys or aliases ('oraxen', 'orx'). It includes functionality to wrap an ItemStack and check if it's a valid Oraxen item, retrieving its key if so. ```java // Check if Oraxen is available if (OraxenProvider.isAvailable()) { OraxenProvider provider = new OraxenProvider(); // Get Oraxen item ItemKey key = new ItemKey("oraxen", "emerald_sword"); ItemStack item = provider.item(key); // Using alias ItemKey aliasKey = new ItemKey("orx", "emerald_sword"); ItemStack sameItem = provider.item(aliasKey); // Check if item is from Oraxen Item wrapped = provider.wrap(someItemStack); if (wrapped.isValid()) { ItemKey oraxenKey = wrapped.key(); } } ``` -------------------------------- ### ItemProvider Interface Methods in Java Source: https://context7.com/projectunified/uniitem/llms.txt The `ItemProvider` interface defines the contract for plugin-specific item handlers in UniItem. Implementations allow wrapping `ItemStack`s or `ItemKey`s, checking key validity, retrieving `ItemStack`s, and normalizing type aliases. It provides shorthand methods for common operations like getting an item's key or creating an item from a key. ```java import org.bukkit.inventory.ItemStack; import org.bukkit.entity.Player; import java.util.List; // Assuming ItemProvider, Item, ItemKey classes/interfaces are available // Assuming ItemsAdderProvider is a concrete implementation // Example: Using a specific provider like ItemsAdderProvider // ItemProvider provider = new ItemsAdderProvider(); // Placeholder for an ItemProvider instance ItemProvider provider = /* ... get an ItemProvider instance ... */; // Get available type aliases for this provider List types = provider.availableTypes(); // e.g., ["itemsadder", "ia"] // Wrap an ItemStack to get its Item representation ItemStack someStack = /* an ItemStack from inventory */; Item wrappedItem = provider.wrap(someStack); if (wrappedItem.isValid()) { ItemKey key = wrappedItem.key(); // Get the custom item key } // Wrap an ItemKey to get the Item ItemKey key = new ItemKey("itemsadder", "namespace:custom_item"); Item item = provider.wrap(key); // Check if a key is valid without getting the full item boolean valid = provider.isValidKey(key); // Shorthand methods for common operations ItemKey foundKey = provider.key(someStack); // Get key from ItemStack ItemStack newItem = provider.item(key); // Get ItemStack from key // Get ItemStack with player context Player player = /* your player object */; ItemStack playerItem = provider.item(key, player); // With player context // Check similarity between an ItemStack and a key boolean similar = provider.isSimilar(someStack, key); // Normalize type aliases to canonical form String normalizedType = provider.normalize("ia"); // Returns "itemsadder" ItemKey normalizedKey = provider.normalize(new ItemKey("ia", "my_item")); // Returns ItemKey("itemsadder", "my_item") ``` -------------------------------- ### Configure Maven Shade Plugin for Relocation Source: https://github.com/projectunified/uniitem/wiki/Usage This XML configuration snippet demonstrates how to use the Maven Shade Plugin to relocate packages. It's crucial for avoiding dependency conflicts by renaming the 'io.github.projectunified.uniitem' package to a custom 'YOUR_PACKAGE.uniitem'. Ensure the plugin version is up-to-date. ```xml org.apache.maven.plugins maven-shade-plugin 3.6.0 io.github.projectunified.uniitem YOUR_PACKAGE.uniitem package shade ``` -------------------------------- ### MythicMobs Item Retrieval Source: https://context7.com/projectunified/uniitem/llms.txt Explains how to use the MythicItemProvider to fetch MythicMobs custom items using their keys or aliases ('mythicmobs', 'mm'). This allows for easy integration and retrieval of items defined within MythicMobs configurations. ```java // Check if MythicMobs is available if (MythicItemProvider.isAvailable()) { MythicItemProvider provider = new MythicItemProvider(); // Get MythicMobs item ItemKey key = new ItemKey("mythicmobs", "SkeletonKingSword"); ItemStack item = provider.item(key); // Using shorthand alias ItemKey aliasKey = new ItemKey("mm", "SkeletonKingSword"); ItemStack sameItem = provider.item(aliasKey); } ``` -------------------------------- ### ItemsAdder Item Retrieval and Identification Source: https://context7.com/projectunified/uniitem/llms.txt Shows how to interact with the ItemsAdderProvider to retrieve custom items using their namespaced IDs or aliases ('itemsadder', 'ia'). It also demonstrates how to identify if an item from a player's inventory is an ItemsAdder item and extract its namespaced ID. ```java // Check if ItemsAdder is available on the server if (ItemsAdderProvider.isAvailable()) { ItemsAdderProvider provider = new ItemsAdderProvider(); // Get item by namespaced ID ItemKey key = new ItemKey("itemsadder", "mypack:custom_sword"); ItemStack item = provider.item(key); // Alternative using alias ItemKey aliasKey = new ItemKey("ia", "mypack:custom_sword"); ItemStack sameItem = provider.item(aliasKey); // Identify ItemsAdder item ItemStack playerItem = player.getInventory().getItemInMainHand(); ItemKey foundKey = provider.key(playerItem); if (foundKey != null) { String namespacedId = foundKey.id(); // "mypack:custom_sword" } } ``` -------------------------------- ### HeadDatabase Provider Integration Source: https://context7.com/projectunified/uniitem/llms.txt Shows how to use the HeadDatabaseProvider to retrieve heads. It includes checks for HeadDatabase availability and demonstrates fetching heads using different alias types. ```java import io.github.projectunified.uniitem.api.ItemKey; import io.github.projectunified.uniitem.bukkit.provider.HeadDatabaseProvider; import org.bukkit.inventory.ItemStack; // Check if HeadDatabase is available if (HeadDatabaseProvider.isAvailable()) { HeadDatabaseProvider provider = new HeadDatabaseProvider(); // Get head by ID ItemKey key = new ItemKey("headdatabase", "12345"); ItemStack head = provider.item(key); // Using shorthand aliases ItemKey hdbKey = new ItemKey("hdb", "12345"); ItemStack sameHead = provider.item(hdbKey); } ``` -------------------------------- ### MMOItems Item Retrieval and Identification Source: https://context7.com/projectunified/uniitem/llms.txt Details the usage of the MMOItemsProvider for retrieving MMOItems, emphasizing the 'TYPE:ID' format for item IDs and the 'mmoitems' type. It also covers fetching player-specific items and identifying MMOItems from inventory, extracting their type and ID. ```java // Check if MMOItems is available if (MMOItemsProvider.isAvailable()) { MMOItemsProvider provider = new MMOItemsProvider(); // MMOItems uses TYPE:ID format within the item id // Full key format: mmoitems:SWORD:FIRE_BLADE ItemKey key = new ItemKey("mmoitems", "SWORD:FIRE_BLADE"); ItemStack item = provider.item(key); // Get player-specific item (applies player stats/level) Player player = /* your player */; ItemStack playerItem = provider.item(key, player); // Identify MMOItems item ItemStack unknown = player.getInventory().getItemInMainHand(); ItemKey found = provider.key(unknown); if (found != null) { // found.id() returns "SWORD:FIRE_BLADE" ItemKey innerKey = ItemKey.fromString(found.id()); String itemType = innerKey.type(); // "SWORD" String itemId = innerKey.id(); // "FIRE_BLADE" } } ``` -------------------------------- ### Item Interface Operations in Java Source: https://context7.com/projectunified/uniitem/llms.txt The `Item` interface in UniItem acts as a wrapper for custom items, providing methods to verify existence, retrieve the associated `ItemKey`, obtain Bukkit `ItemStack` representations (with and without player context), and check for item similarity. `Item.INVALID` is a static constant representing a non-existent item. ```java import org.bukkit.inventory.ItemStack; import org.bukkit.entity.Player; // Assuming Item, ItemKey, and ItemProvider interfaces/classes are available // Example usage with a provider (assuming 'provider' is an instance of ItemProvider) // Item item = provider.wrap(new ItemKey("oraxen", "emerald_sword")); // Placeholder for a valid item wrapper Item validItem = /* ... get a valid Item instance ... */; // Check if the item is valid (exists in the plugin) if (validItem.isValid()) { // Get the ItemKey for this item ItemKey key = validItem.key(); // Returns "oraxen:emerald_sword" // Get the Bukkit ItemStack ItemStack bukkitItem = validItem.bukkitItem(); // Get ItemStack with player context (for player-specific items) Player player = /* your player object */; ItemStack playerItem = validItem.bukkitItem(player); // Try to get ItemStack, using player context if available ItemStack tryItem = validItem.tryBukkitItem(player); // Uses player if not null // Check if another ItemStack is similar to this item ItemStack someItem = /* an ItemStack from inventory or elsewhere */; boolean isSame = validItem.isSimilar(someItem); } // Item.INVALID is returned when item doesn't exist Item invalid = Item.INVALID; boolean isInvalidValid = invalid.isValid(); // false ItemKey invalidKey = invalid.key(); // null ItemStack invalidItemStack = invalid.bukkitItem(); // null ``` -------------------------------- ### ItemKey Management in Java Source: https://context7.com/projectunified/uniitem/llms.txt The `ItemKey` class in UniItem represents unique item identifiers using a 'type:id' format. It supports creation from components, parsing from strings, accessing type and id, checking against types (including aliases), and conversion back to string. This class is fundamental for referencing custom items across different plugins. ```java import java.util.Arrays; import java.util.List; // Assuming ItemKey class is available // Create an ItemKey from type and id ItemKey key = new ItemKey("itemsadder", "namespace:custom_sword"); // Parse an ItemKey from string format "type:id" ItemKey parsedKey = ItemKey.fromString("oraxen:emerald_sword"); // Get type and id components String type = key.type(); // "itemsadder" String id = key.id(); // "namespace:custom_sword" // Check if key matches a type (case-insensitive) boolean isItemsAdder = key.isType("itemsadder"); // true boolean isIA = key.isType("ia"); // true (alias) // Check against multiple types List types = Arrays.asList("itemsadder", "ia"); boolean matches = key.isType(types); // true // Convert back to string String keyString = key.toString(); // "itemsadder:namespace:custom_sword" ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.