Permission Messages
To customize a message about missing permissions, you can choose from two ways:
- Use the message system
- Implement a missing permissions handler
Message System
To change the default message, register a custom message in the builder:
java
.commands(
new SomeCommand()
)
.message(LiteMessages.MISSING_PERMISSIONS, permissions -> "Required permissions: (" + permissions.asJoinedText() + ")")
.build();
1
2
3
4
5
2
3
4
5
The permissions
parameter is a MissingPermissions
object that contains the missing permissions.
Missing Permissions Handler
To implement a missing permissions handler, create a class that implements the MissingPermissionsHandler
interface:
java
// PermissionsHandler.java
public class PermissionsHandler implements MissingPermissionsHandler<SENDER> {
@Override
public void handle(
Invocation<SENDER> invocation,
MissingPermissions missingPermissions,
ResultHandlerChain<SENDER> chain
) {
String permissions = missingPermissions.asJoinedText();
SENDER sender = invocation.sender();
sender.sendMessage("Required permissions: (" + permissions + ")");
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Then, register the handler in the builder:
java
.commands(
new SomeCommand()
)
.missingPermission(new PermissionsHandler())
.build();
1
2
3
4
5
2
3
4
5
And that's it! Now, when a player without the required permissions tries to execute a command, the handler will send a custom message.