Skip to content

Event API

EmakiLevel exposes Bukkit events that external plugins can listen to in order to intercept, modify, or record level and experience flows. Event classes live in the emaki.jiuwu.craft.level.api.event package and use the standard HandlerList boilerplate.

EventWhen it firesCancellableMutable
PlayerExpGainEventBefore experience is writtenYessetAmount
PlayerLevelUpEventAfter an experience-driven level upNoRead-only
PlayerLevelChangeEventAfter any level changeNoRead-only
PlayerMaxLevelReachedEventWhen the max level is reached for the first timeNoRead-only

PlayerExpGainEvent

Fires before experience is written to the player. amount is the value after multipliers and daily caps are applied, before it is added to the player.

Event behavior

  • It is cancellable. If cancelled, no experience is gained.
  • The amount can be changed with setAmount. A value of 0 or less suppresses the gain.
  • Fired on the main thread; asynchronous paths skip the event.

Main methods

MethodReturnDescription
getPlayer()PlayerPlayer gaining experience, may be null.
getTypeId()StringLevel type id.
getCurrentLevel()intLevel before this gain.
getCurrentExp()doubleExperience before this gain.
getReason()StringSource reason marker.
getAmount()doubleExperience to add unless changed or cancelled.
setAmount(double)voidChange the experience amount; a value of 0 or less suppresses the gain.
isCancelled()booleanWhether the event is cancelled.
setCancelled(boolean)voidCancel or restore the event.

Example

java
@EventHandler
public void onExpGain(PlayerExpGainEvent event) {
    // Double experience event
    event.setAmount(event.getAmount() * 2);
}

PlayerLevelUpEvent

Fires after an experience-driven level up completes. The level has been applied, and rewards and success actions have run.

Event behavior

  • Not cancellable; purely informational.
  • Covers only experience-driven level ups (direct level changes via command or API use PlayerLevelChangeEvent).

Main methods

MethodReturnDescription
getPlayer()PlayerPlayer who leveled up, may be null.
getTypeId()StringLevel type id.
getOldLevel()intLevel before the level up.
getNewLevel()intLevel after the level up.
getCause()LevelUpCauseCause of the level up (emaki.jiuwu.craft.level.api.LevelUpCause), may be null.

PlayerLevelChangeEvent

Fires after any level change, covering direct level changes via command or API (as opposed to the experience-only PlayerLevelUpEvent). The change has already been applied and cannot be reverted.

Event behavior

  • Not cancellable; purely informational.
  • Covers add, set, level up, reset, and other level operations.

Main methods

MethodReturnDescription
getPlayer()PlayerAffected player, may be null when offline.
getTypeId()StringLevel type id.
getOldLevel()intLevel before the change.
getNewLevel()intLevel after the change.
getOperationType()LevelOperationTypeOperation that caused the change (emaki.jiuwu.craft.level.api.LevelOperationType).
isIncrease()booleanWhether the level increased (new level greater than old level).

PlayerMaxLevelReachedEvent

A milestone event fired once when a player reaches the configured max level for the first time via experience.

Event behavior

  • Not cancellable; purely informational.
  • Fires once per level type the first time max level is reached.

Main methods

MethodReturnDescription
getPlayer()PlayerPlayer who reached max level, may be null.
getTypeId()StringLevel type id.
getMaxLevel()intConfigured max level.
getCause()LevelUpCauseCause of the level up (LevelUpCause), may be null.

Example

java
@EventHandler
public void onMaxLevel(PlayerMaxLevelReachedEvent event) {
    Player player = event.getPlayer();
    if (player != null) {
        Bukkit.broadcastMessage(player.getName()
            + " has maxed out " + event.getTypeId() + "!");
    }
}

Notes

  • getPlayer() may return null when offline; check for null before use.
  • PlayerLevelUpEvent only fires for experience-driven level ups; listen to PlayerLevelChangeEvent for direct level changes via command or API.
  • LevelUpCause and LevelOperationType are enums exposed by the EmakiLevel API, located in the emaki.jiuwu.craft.level.api package.