Item resolution
The Item and ItemKey abstractions, and implementing an ItemProvider.
Conduit resolves custom items the same way regardless of which plugin made them. This is the API that predates event normalisation and is unchanged by it.
ItemKey
The type:id pair every provider agrees on. A record, so equality and hashing
are already correct — do not wrap it.
ItemKey key = new ItemKey("oraxen", "ruby_sword");
key.type(); // "oraxen"
key.id(); // "ruby_sword"
key.serialized(); // "oraxen:ruby_sword"The compact constructor rejects a null or blank type or id with
IllegalArgumentException. There is a type-only factory for providers that
expose a single id per type.
Item
What a provider says about one item.
public interface Item {
Item INVALID = InvalidItem.INSTANCE;
boolean isValid();
Optional<ItemKey> key();
Optional<ItemStack> bukkitItem();
Optional<ItemStack> bukkitItem(@Nullable Player player);
boolean matches(ItemStack stack);
}INVALID is the "no provider claimed this" answer. It is not an exception and
it is not null — check isValid() when you care.
The player-aware overload exists because several providers build a different
ItemStack per player (CustomFishing and ItemsAdder both do). Pass the player
when there is one, or you may get the generic variant.
The Conduit surface
Conduit conduit = ConduitLoader.load(this);
conduit.resolve(stack); // ItemStack -> Item
conduit.resolve(ItemKey); // key -> Item
conduit.resolve("oraxen", "ruby_sword"); // type, id -> Item
conduit.keyOf(stack); // Optional<ItemKey>
conduit.itemOf(key); // Optional<ItemStack>
conduit.itemOf(key, player); // per-player variant
conduit.matches(stack, key); // boolean, no Item allocated
conduit.isValidKey(key); // boolean
conduit.normalizeType("oraxen"); // canonical type name
conduit.normalize(key); // canonical ItemKey
conduit.types(); // Set<String> of known types
conduit.providers(); // List<ItemProvider>
conduit.provider(String type); // Optional<ItemProvider>matches(...) is the cheap path: it answers the question without building an
Item. Prefer it in a hot loop or an inventory scan.
normalizeType(...) is how you map a user-typed string onto a known type. It is
what a command's item argument should go through.
Implementing an ItemProvider
Only needed if you are adding a plugin Conduit does not know about. Discovery is otherwise automatic.
public final class MyItemProvider implements ItemProvider {
@Override public @NotNull String pluginName() { return "MyPlugin"; }
@Override public @NotNull Set<String> types() { return Set.of("myplugin"); }
@Override public boolean isAvailable() { return Bukkit.getPluginManager().isPluginEnabled("MyPlugin"); }
@Override public @NotNull Item wrap(@NotNull ItemStack stack) { /* ... */ }
@Override public @NotNull Item wrap(@NotNull ItemKey key) { /* ... */ }
}order() decides precedence when two providers claim the same type:
| Constant | Value | Use |
|---|---|---|
ORDER_WRAPPER |
0 | Wraps another provider's items; resolved last. |
ORDER_PRIMARY |
100 | The default. Claims a type outright. |
ORDER_FALLBACK |
200 | Only consulted when nothing else matched. |
A wrap implementation should return Item.INVALID rather than throw or return
null when it does not recognise the input.