Listen for Events
Docs/dominion-api/Listen for Events

Listen for Events

Use entry/exit events and data-operation events for notifications, interception, and post-processing.

Send a message on claim entry

@EventHandler
public void onEnter(PlayerMoveInDominionEvent event) {
    Player player = event.getPlayer();
    DominionDTO dominion = event.getDominion();
    player.sendMessage("Welcome to " + dominion.getName());
}

Do not scan every online player every tick to implement this. Dominion already provides border events, which reduce repeated queries.

Block reserved names

@EventHandler
public void onCreate(DominionCreateEvent event) {
    if (event.getName().startsWith("server-")) {
        event.setCancelled(true);
        event.getOperator().sendMessage("This name prefix is reserved by the server.");
    }
}

This event runs before the data is processed. To modify the name, call event.setName(...); the changed value still goes through Dominion’s name rules and other validity checks.

Process a member after a successful addition

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

    event.afterAdded(member -> {
        if (member == null) return;

        Player player = Bukkit.getPlayer(member.getPlayerUUID());
        if (player == null) return;

        // Switch to the appropriate entity scheduler for the target server's threading model.
        player.sendMessage("You joined claim " + event.getDominion().getName());
    });
}

The afterAdded callback may run on an asynchronous thread. Code involving online players, menus, or worlds should use the appropriate Paper/Folia scheduler; do not assume that the callback runs on the Bukkit main thread.

Use the unified border event

@EventHandler
public void onBorder(PlayerCrossDominionBorderEvent event) {
    DominionDTO from = event.getFrom();
    DominionDTO to = event.getTo();

    if (to != null && from == null) {
        // Entered a claim from an unclaimed area.
    } else if (to == null && from != null) {
        // Left a claim for an unclaimed area.
    } else if (from != null && to != null) {
        // Moved from one claim to another.
    }
}