Skip to content

Event API

EmakiGem exposes Bukkit events that external plugins can listen to in order to intercept or modify gem operations. Event classes live in the emaki.jiuwu.craft.gem.api.event package and use the standard HandlerList boilerplate. Every event fires before any cost is charged or the outcome is rolled.

EventWhen it firesCancellableMutable
GemInlayEventBefore the inlay success rollYessetSuccessChance
GemUpgradeEventBefore the upgrade cost and rollYessetSuccessChance
GemExtractEventBefore extraction cost and removalYesCancel only
GemSocketOpenEventBefore opening a slot and consuming the openerYesCancel only

Actor accessor difference

GemInlayEvent, GemExtractEvent, and GemSocketOpenEvent use getActor() for the acting player, while GemUpgradeEvent uses getPlayer().

GemInlayEvent

Fires before the inlay success roll. Use it to intercept the inlay or change the success chance.

Event behavior

  • It is cancellable. If cancelled, the inlay does not happen.
  • The success chance can be changed with setSuccessChance, expressed as a percentage from 0 to 100.
  • Fired only when the acting player is owned by the current thread; otherwise the event is skipped and the operation continues.

Main methods

MethodReturnDescription
getActor()PlayerPlayer performing the inlay.
getEquipment()ItemStackEquipment receiving the gem.
getGemItem()ItemStackGem item being inlaid.
getSlotIndex()intTarget slot index.
getGemId()StringGem definition id.
getGemLevel()intGem level.
getSuccessChance()doubleSuccess chance used for the roll (0-100).
setSuccessChance(double)voidChange the success chance.
isCancelled()booleanWhether the event is cancelled.
setCancelled(boolean)voidCancel or restore the event.

Example

java
@EventHandler
public void onGemInlay(GemInlayEvent event) {
    // VIP players always succeed
    if (event.getActor().hasPermission("server.vip")) {
        event.setSuccessChance(100.0);
    }
}

GemUpgradeEvent

Fires before the gem upgrade cost is charged and the success roll is decided.

Event behavior

  • It is cancellable. If cancelled, no cost is charged and no upgrade happens.
  • The success chance can be changed with setSuccessChance, expressed as a percentage from 0 to 100.
  • Fired only when the acting player is owned by the current thread; otherwise the event is skipped and the operation continues.

Main methods

MethodReturnDescription
getPlayer()PlayerPlayer performing the upgrade.
getGemItem()ItemStackGem item being upgraded; the equipment when upgrading an inlaid gem.
getGemId()StringGem definition id.
getCurrentLevel()intLevel before the upgrade.
getTargetLevel()intLevel after success.
getSlotIndex()intSlot index for an inlaid upgrade; -1 when upgrading a gem item directly.
getSuccessChance()doubleSuccess chance used for the roll (0-100).
setSuccessChance(double)voidChange the success chance.
isCancelled()booleanWhether the event is cancelled.
setCancelled(boolean)voidCancel or restore the event.

Example

java
@EventHandler
public void onGemUpgrade(GemUpgradeEvent event) {
    // Disallow upgrading already-inlaid gems
    if (event.getSlotIndex() >= 0) {
        event.setCancelled(true);
    }
}

GemExtractEvent

Fires before extraction cost is charged and the gem is removed from its socket.

Event behavior

  • It is cancellable. If cancelled, extraction does not happen.
  • Fired only when the acting player is owned by the current thread; otherwise the event is skipped and the operation continues.

Main methods

MethodReturnDescription
getActor()PlayerPlayer performing the extraction.
getEquipment()ItemStackEquipment the gem is removed from.
getSlotIndex()intSlot index being cleared.
getGemId()StringGem definition id.
getGemLevel()intGem level.
getReturnMode()StringConfigured return mode (such as destroy, downgrade, return).
isCancelled()booleanWhether the event is cancelled.
setCancelled(boolean)voidCancel or restore the event.

GemSocketOpenEvent

Fires before the slot is opened and the opener item is consumed.

Event behavior

  • It is cancellable. If cancelled, no slot is opened and the opener is not consumed.
  • Fired only when the acting player is owned by the current thread; otherwise the event is skipped and the operation continues.

Main methods

MethodReturnDescription
getActor()PlayerPlayer opening the slot.
getEquipment()ItemStackEquipment receiving the new slot.
getOpenerItem()ItemStackOpener item used, may be null.
getOpenerId()StringOpener item configuration id.
getSlotIndex()intResolved slot index.
getItemDefinitionId()StringGem item definition id of the equipment.
isCancelled()booleanWhether the event is cancelled.
setCancelled(boolean)voidCancel or restore the event.

Notes

  • Changing the success chance applies only to GemInlayEvent and GemUpgradeEvent; extraction and socket-open events can only be cancelled.
  • Success chance is always a percentage from 0 to 100.