-
-
Notifications
You must be signed in to change notification settings - Fork 45
Operations API
github-actions[bot] edited this page Feb 2, 2025
·
1 revision
HuskTowns exposes API to let you register OperationType
s to call custom operations and check if they should be allowed with the Handler
.
- 1. Getting the OperationTypeRegistry
- 2. Operations and OperationTypes
- 3. Registering a custom OperationType
- 4. Using Handler to cancel Operations with your custom OperationType
- The
OperationTypeRegistry
is the registry containing registeredOperationType
s. - It also lets you access the
Handler
class. - Get the
OperationTypeRegistry
withHuskTownsAPI#getOperationTypeRegistry
Example — Getting the OperationTypeRegistry
void getRegistry() {
final OperationTypeRegistry reg = HuskTowns.getOperationTypeRegistry();
}
-
Operation
s represent actions in a world that can be prevented from occuring entity based on:- Which game entity, if any, performed the action
- If the game entity is a player, their trust level (see Trust API)
- The location the action affects or occurred
- The game entity, if any, affected by the action
- The type of action that occurred is represented by an
OperationType
. - Your plugin can create
Operation
s with custom registeredOperationType
s and callHandler#isOperationAllowed
to allow to determine whether your custom plugin/mod's actions should be permitted - Users can then add these
OperationType
s to their trust levels config.
- Start by registering a custom
OperationType
. We recommend doing thisonEnable
(notonLoad
before HuskTowns has loaded). - Use
OperationTypeRegistry#registerOperationType(@NotNull Key key, boolean silent)
to create anOperationType
-
key
- the key identifier of the OperationType (e.g.Key.of("my_plugin", "operation_name")
->my_plugin:operation_name
). -
silent
- whether players should be informed when this operation is cancelled (usually you want this on, unless your operation doesn't affect players or is particularly spammy such as pressure plate triggering operations)
-
- This method will create, then register an
OperationType
. You should save this Operation Type somewhere for later use.
Example — Registering a custom OperationType
private OperationType releaseMonOpType;
void getRegistry() {
final OperationTypeRegistry reg = HuskTowns.getOperationTypeRegistry();
releaseMonOpType = reg.createOperationType(Key.of("mons_mod", "release_mon"));
reg.registerOperationType(releaseMonOpType);
}
- Get the
Handler
withOperationTypeRegistry#getHandler
- Create an
Operation
with your newly madeOperationType
usingOperation#of()
- There are different static
Operation#of
variants letting you specify the performing user, operation type, operation position, silent state of this operation (overriding the default value of the operation type), and victim user in various combinations.
- There are different static
- Call
Handler#cancelOperation
to get a booleantrue
orfalse
value of whether the Operation should be allowed - Decide whether to perform logic based on that return value
Example — Checking if Operations are allowed
private OperationType releaseMonOpType;
void onMonReleased(Player bukkitPlayer, Location releasedAt) {
final OperationTypeRegistry reg = HuskTowns.getOperationTypeRegistry();
final boolean cancelled = reg.getHandler().cancelOperation(Operation.of(
HuskTowns.getPlayer(bukkitPlayer), // OnlineUser implements OperationUser
releaseMonOpType,
HuskTowns.getPosition(releasedAt) // Position implements OperationPosition
));
if (cancelled) {
// Don't continue with the action
return;
}
// Logic would continue if the operation wasn't cancelled...
}
This documentation is available via william278.net |
---|
- 📚 Setup
- 📦 Legacy Migration
- 📁 Database
- ⛅ Redis Support
- 📄 Config Files
- 📝 Translations
- 🔌 Hooks
- 🖥️ Commands
- 🏙️ Towns
- 🏠 Claims
- 🔨 Roles
- 🌟 Advancements
- ☯️ Relations
- ⚔️ Wars
- 🚫 Inactive Town Pruning
- 📦 API v3
- 🧡 Towns API
- ⚙️ Claims API
- 🎬 Operations API
- ❗ API Events
- 🕸️ API v1 (Legacy)