Developer API
AstralItems exposes its services through AstralItems.get() and persists item identity directly on the ItemStack via PDC. Other plugins can build items, resolve items back to their blueprint, register custom item data, listen to HandEquipEvent/AnvilResultEvent, or open the custom anvil for a player.
Maven coordinates
Repository: https://maven.astralrealms.fr/repository/maven-public/.
Accessing services
Getter | Type | Use |
|---|---|---|
|
| Look up rarities, list all loaded rarities. |
|
| Look up blueprints by |
|
| Look up the class behind a |
|
| Fire a virtual event through the dispatcher (advanced). |
|
| Open the custom anvil for a player. |
|
| Read / write item PDC, test for custom items, upgrade outdated stacks. |
|
| AstralCore menu container — opens the plugin's |
RarityService
Method | Returns | Use |
|---|---|---|
|
| Resolve a rarity by id. (Method name is a hold-over — |
|
| Iterate every loaded rarity (read-only). |
|
| Re-scan |
BlueprintService
Method | Returns | Use |
|---|---|---|
|
| Resolve a blueprint by its composite |
|
| Every blueprint registered under a given rarity id. |
|
| Every blueprint key currently registered. |
|
| Every loaded blueprint (read-only). |
|
| Re-scan |
PipelineService
Method | Returns | Use |
|---|---|---|
|
| Resolve a pipeline |
|
| Unregister every dummy listener and rewire all pipelines. Called automatically by |
ItemService
Method | Returns | Use |
|---|---|---|
|
| Read the |
|
| Re-write the PDC with a new instance and refresh the lore. Returns |
|
| Re-render the lore using the blueprint's lore template + current instance state (enchantments, unbreakable, repairable status). |
|
| Cheap PDC presence check. |
|
|
|
|
| Rebuild the stack from the current blueprint if its stored version is older. Preserves UUID, damage, unbreakable, amount, and whitelisted enchantments. |
|
| Calls |
The PDC key is exposed as ItemService.ITEM_KEY for callers that need to write the container directly (useful from PersistentDataType implementations):
AnvilService
Method | Returns | Use |
|---|---|---|
|
| Open the custom packet-level anvil window for the given player. |
See Anvil for the recompute pipeline and the AnvilResultEvent hook.
Item upgrade
ItemService.upgrade(ItemStack) is the centrepiece of the version-bump migration story: when a player handles a stack whose stored blueprint version is older than the current blueprint version, upgrade rebuilds the display ItemStack from the new blueprint and transfers:
The
ItemInstanceUUID and item data bag.Enchantments — clamped against
metadata.available-enchantments.Damage value.
Unbreakableflag.Stack amount.
The UpgradeListener invokes it on PlayerDataLoadedEvent (from AstralSync), InventoryOpenEvent, and ChunkLoadEvent (for item frames, containers, and shelves in newly loaded chunks).
Plugins that move items between worlds (e.g. cross-server transfer, bank withdraw) can call upgrade explicitly to ensure the item is refreshed before it lands in the destination inventory.
Creating an item
ItemFactory is a static utility that produces a ready-to-use ItemStack from a blueprint or an explicit ItemInstance. Use it to grant items from custom commands, loot tables, quests, etc.
ItemFactory.make(blueprint) generates a fresh UUID, copies the blueprint's version onto the instance, copies the blueprint's default-data into the instance, builds the display ItemStack via the blueprint's ItemStackWrapper, applies metadata.maxStackSize (when > 0), serialises the ItemInstance into the PDC, and refreshes the lore.
For more control — for example, restoring an item with an explicit UUID or pre-populated data — use the explicit form:
ItemFactory.makeInstance(blueprint) builds an ItemInstance without serialising it to an ItemStack — useful when the caller has its own ItemStack to attach the PDC to.
ItemStack PDC layout
Every AstralItems item carries one PDC entry:
Key | Type | Value |
|---|---|---|
|
|
|
ItemInstanceDataType serialises into a nested PersistentDataContainer with five sub-keys:
Sub-key | Type | Value |
|---|---|---|
|
| Per-item |
|
| Blueprint |
|
| Semver string |
| nested PDC | Typed item-data bag — each entry serialised by its registered |
|
| Rolled item stats, written only when the item has stats. |
CraftEngine stack supplier
The plugin registers itself as a CraftEngine stack supplier under the namespace astralitems:
That means any AstralCore call site that accepts a ce:/craftengine: key also accepts an astralitems: key. The key format is astralitems:<rarity-id>/<blueprint-id>. The supplier:
get(String key)— builds anItemStackfrom the blueprint behind the key.completions()— every blueprint key, for tab completion.keyOf(ItemStack)— extracts the blueprintKeyfrom a stack's PDC. Lets other plugins normalise an AstralItems stack back to a registry key.
Reacting to events
The plugin fires four custom events — see Events:
HandEquipEvent— main-hand change notification.ArmorEquipEvent/ArmorUnEquipEvent— armour-slot change notifications.AnvilResultEvent— fires each time the custom anvil recomputes its result; listeners can override the result and the level cost.
For most reactive behaviour, prefer authoring a pipeline on the blueprint rather than writing a Bukkit listener.
Firing a virtual event
EventService.fireVirtualEvent(Event) reroutes an event through the dispatcher without going through Bukkit's listener pipeline. It returns true if any hooked listener cancelled the event.
This is the mechanism the hammer, fell-tree, replant-crops, break-leaves, and build-wand links use to ask other plugins (claim, logging, protection) about every block they would break or place in their AoE. Only use it when you need that "ask before acting" semantics — calling Bukkit's normal dispatcher is the right choice everywhere else.
Registering custom item data
Custom item data adapters extend the typed bag stored alongside each instance. See Item Data for the ItemDataAdapter<T> contract and registration walkthrough.