Event Integrations
Docs/dominion-api/Event Integrations

Event Integrations

Respond to state changes with Dominion events, or stop and adjust an operation before it is persisted.

Claim entry and exit

@EventHandler
public void onEnter(PlayerMoveInDominionEvent event) {
    DominionDTO dominion = event.getDominion();
    Player player = event.getPlayer();

    player.sendMessage("You entered " + dominion.getName());
}

@EventHandler
public void onLeave(PlayerMoveOutDominionEvent event) {
    DominionDTO dominion = event.getDominion();
    if (dominion == null) return;
    getLogger().info(event.getPlayer().getName() + " left " + dominion.getName());
}

If one handler should cover entry, exit, and movement between claims, listen for PlayerCrossDominionBorderEvent:

@EventHandler
public void onBorder(PlayerCrossDominionBorderEvent event) {
    DominionDTO from = event.getFrom();
    DominionDTO to = event.getTo();
    // from or to may be null.
}

Cancel claim creation

@EventHandler
public void onCreate(DominionCreateEvent event) {
    if (event.getName().startsWith("system-")) {
        event.setCancelled(true);
    }
}

After an event is cancelled, the corresponding provider Future completes with a failure result. Do not only display a message without cancelling, and do not try to roll back the database after the event has ended.

Modify operation parameters

Many data-operation events allow the new value to be changed, for example:

  • DominionRenameEvent#setNewName;
  • DominionSetGuestFlagEvent#setNewValue;
  • DominionSetEnvFlagEvent#setNewValue;
  • DominionSetTpLocationEvent#setNewTpLocation;
  • DominionTransferEvent#setNewOwner;
  • DominionReSizeEvent#setDirection, setSize.

Modified values still go through Dominion’s subsequent validity checks. A writable event does not mean that an addon can bypass permission, overlap, economy, or parent-child claim constraints.

Read the operation result

The data operation is performed only after the event is dispatched. When you need to grant a reward, synchronize an external system, or send a notification after success, use the callback exposed by the event:

@EventHandler
public void onMemberAdded(MemberAddedEvent event) {
    if (event.isCancelled()) return;

    event.afterAdded(member -> {
        if (member == null) return;
        // Process the added member here.
        getLogger().info("Member added: " + member.getPlayerUUID());
    });
}

Create/modify events usually provide afterCreated or afterModified, while member and group events provide afterAdded, afterRemoved, or afterSet. Check the target event’s JavaDoc for the exact name.

Event priority

EventPriority.NORMAL is sufficient by default. Change the priority only when you have a clear reason to coordinate with another addon:

  • use a lower priority when you need to reject an operation early while allowing other plugins to modify the event;
  • use a higher priority when you need to observe the final event parameters, but do not modify data during MONITOR;
  • do not perform blocking operations in high-frequency movement events.