ItemProvider

Implement it to make your plugin's items available via Items. Register it in onLoad via Mimic.registerItemProvider. To create or identify items, use Items instead.

IDs

Mimic adds your provider id as the namespace, so receive and return IDs without it: ruby_sword becomes myplugin:ruby_sword. Don't change id later, it breaks consumers' configs.

If your plugin has its own namespaced IDs, convert them to paths:

  • Drop your plugin's own namespace: myplugin:ruby_sword ->ruby_sword.

  • Keep other namespaces as the first path part: default:palm_log ->default/palm_log.

Other rules:

  • Allowed characters: a-z, 0-9, ., _, - and /. Items with other characters are ignored.

  • To convert other IDs, lowercase them and replace other characters with _. Keep a map back to the original IDs.

  • If two IDs become the same (Ruby_Sword and ruby_sword), log a warning and keep one of them.

Ownership

An item belongs to the provider with the highest priority that returns an ID for it. So return an ID only for your items, and null for the rest, including the vanilla items your items are built on. Vanilla items belong to Mimic's own minecraft provider, which is always asked last.

Rules

  • Never throw. Return null instead.

  • Item IDs may be unknown until your plugin loads its data. Return null for them until then.

  • allItems, hasItem and getItemId may be called from any thread, createItem is called on the main thread.

  • Document the format of the payload your provider takes, or that it takes none.

Mimic does the rest: selects the provider by the item ID namespace, finds the owner of an item, compares items by ID, limits the amount of the created stack, and catches errors thrown by the provider.

Since

0.11.0

Properties

Link copied to clipboard
abstract val allItems: Collection<String>

IDs of all items this provider knows. The list may change while the plugin loads or reloads its data, so it is read on every request.

Inherited properties

Link copied to clipboard
open val id: String
Link copied to clipboard
open val isEnabled: Boolean

Functions

Link copied to clipboard
abstract fun createItem(@KeyPattern.Value itemId: String, amount: Int, player: Player?, payload: String?): ItemStack?

Creates a new stack of the item with itemId. The caller owns the returned stack, so never return a shared one.

Link copied to clipboard
abstract fun getItemId(item: ItemStack): String?

Returns ID of the item, or null if it isn't an item of this provider. Amount, stats, durability and lore of the stack don't affect the ID.

Link copied to clipboard
open fun hasItem(@KeyPattern.Value itemId: String): Boolean

Returns true if the item with itemId exists. By default, looks for the ID in allItems. Override it if your plugin can check an item faster, or can't list all its items. It should return true at least for every ID from allItems.