Data Writes
Docs/dominion-api/Data Writes

Data Writes

Modify Dominion data with providers and correctly handle permissions, failure results, and asynchronous callbacks.

Rename a claim

api.getDominionProvider()
        .renameDominion(Bukkit.getConsoleSender(), dominion, newName)
        .thenAccept(updated -> {
            if (updated == null) {
                getLogger().warning("Rename rejected: " + newName);
                return;
            }
            getLogger().info("Dominion renamed to " + updated.getName());
        });

Background tasks that do not need to simulate player permissions can use the console as the operator. If the operation should be constrained by the claim owner’s or a member’s permissions, pass the real Player instead of replacing the permission check with the console.

Add a member and set a permission

PlayerDTO target = api.getPlayer(targetUuid);
if (target == null) {
    return;
}

api.getMemberProvider()
        .addMember(operator, dominion, target)
        .thenAccept(member -> {
            if (member == null) return;

            api.getMemberProvider()
                    .setMemberFlag(operator, dominion, member, Flags.CONTAINER, true)
                    .thenAccept(updated -> {
                        if (updated == null) {
                            getLogger().warning("Member flag update failed.");
                        }
                    });
        });

To give a group of players the same permission, create a GroupDTO, use GroupProvider.setGroupFlag, and then use GroupProvider.addMember to add members to the group. Do not copy a flag Map directly across multiple DTOs.

Create a claim

CuboidDTO cuboid = new CuboidDTO(
        minX, minY, minZ,
        maxX, maxY, maxZ
);

api.getDominionProvider()
        .createDominion(
                Bukkit.getConsoleSender(),
                "addon-created",
                ownerUuid,
                world,
                cuboid,
                null,       // null means a top-level claim
                true        // Skip the economy check in this example; configure production behavior explicitly.
        )
        .thenAccept(created -> {
            if (created == null) {
                getLogger().warning("Dominion creation failed.");
                return;
            }
            getLogger().info("Created dominion " + created.getName());
        });

Do not interpret skipEconomy as “skip all restrictions.” Dominion still checks the name, limits, boundaries, overlap, parent-child relationship, and other validity rules.

Resize a boundary

Use DominionReSizeEvent.TYPE.EXPAND/CONTRACT and DIRECTION to specify the direction:

api.getDominionProvider().resizeDominion(
        operator,
        dominion,
        DominionReSizeEvent.TYPE.EXPAND,
        DominionReSizeEvent.DIRECTION.EAST,
        8
).thenAccept(updated -> {
    if (updated == null) {
        getLogger().warning("Resize rejected.");
    }
});

Before exposing boundary changes on a production server, check the target claim’s parent, children, neighboring claims, and administrator permissions. The provider performs these checks, but the addon should still give users a clear failure message.

Notes for asynchronous calls

  • Do not repeatedly call future.get() or join() to wait for a result;
  • chain operations with thenCompose instead of nesting callbacks;
  • do not assume a callback still runs on the Bukkit main thread or in the same Folia region;
  • when you need to access an online entity, open a menu, or perform a thread-sensitive operation, use the appropriate server scheduler;
  • a deleted claim, an offline player, or a changed operator permission can still result in null or false.