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. |
|
| Look up skins, build skin items, apply / remove a skin on a custom item. |
|
| 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):
SkinService
Method | Returns | Use |
|---|---|---|
|
| Resolve a skin by id. |
|
| Render the physical skin item, stamped with the PDC key |
|
| Reverse lookup from a skin item. Empty for air, meta-less stacks, stacks without the tag, and stacks whose stored id is no longer loaded. |
|
| Write the |
|
| Repaint the visuals of an already-skinned stack after a rebuild. Re-resolves the skin by id (falling back to the persisted model key when the id is gone) and no-ops on null / empty data. Called by |
|
| Restore the blueprint display's item model and equippable asset — clearing the asset id when the display declares none — and remove the skin item data. Same persistence caveat. |
|
| The loaded skin whose |
|
| The skin a stack visually wears but has no data for — see Orphan skins. Empty when the stack's model is the blueprint's own default. |
|
| Read-only view of every loaded skin id. |
|
| Read-only view of every loaded skin. |
|
| Re-scan |
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 six 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. |
|
| Current lore page, written only when greater than |
Item stack supplier
The plugin registers itself with AstralCore's shared item-stack supplier registry under the name astralitems:
That registers it alongside AstralCore's own suppliers (vanilla, ce, …). The key the supplier receives is the blueprint's composite Key — <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.
There are two ways to reference a supplied stack from YAML, and neither is <namespace>:<key>:
%stacksuppliers_<supplier>_<key>%— the placeholder form (ItemStackSupplierPlaceholder). This is what/core give's tab completion emits and the only form that works where anItemStackplaceholder is expected, such as the[give-item]action.<supplier>-<key>— the dashed form, accepted only by nodes deserialized as anItemStack(AstralCore'sItemStackTypeSerializersplits on the first-). AnItemStackWrapperblock'smaterial:key is not one of them: it only takes a BukkitMaterialname or a%placeholder%.
Skin stack supplier
AstralItems registers a second supplier, always (no plugin-hook gate), for skin items:
Supplier name | Provider | Registered | Key | Placeholder form |
|---|---|---|---|---|
|
| always |
|
|
|
| always |
|
|
Note that the supplier name itself contains a dot. get(String) builds the skin item for the id (or null), the (Player, Key, int) overload resolves key.value() and then sets the amount, completions() lists items.skins:<id> for every loaded skin, and keyOf(ItemStack) maps a skin item back to that same Key.
Reacting to events
The plugin fires six custom events — see Events:
HandEquipEvent— main-hand change notification.ItemHoldEvent/ItemUnholdEvent— an item entering / leaving the main hand, filtered so a meta update of the item already held does not re-fire the pair.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.