-
Couldn't load subscription status.
- Fork 2
Custom Handling System
This guide shows how to fully customize the feedback messages sent to users when executing commands through CommandsAPI.
The MessageHandler interface in CommandsAPI allows you to define custom messages for core system behaviors such as:
- No permission
- Console-only restriction
- Argument parsing failure
- Requirement failure (e.g., world or sender check)
By default, CommandsAPI provides standard messages, but you can override them to suit your plugin’s style or language.
💡 This feature was inspired by Robotv2. Thanks!
Located in:
fr.traqueur.commands.api.lang.MessageHandlerHere are the methods you can override:
public interface MessageHandler {
String getNoPermissionMessage();
String getOnlyInGameMessage();
String getArgNotRecognized();
String getRequirementMessage();
}Each method returns a message (as a String) that will be sent to the sender when the corresponding event occurs.
public class CustomMessageHandler implements MessageHandler {
@Override
public String getNoPermissionMessage() {
return "§cYou do not have permission to execute this command.";
}
@Override
public String getOnlyInGameMessage() {
return "§cThis command can only be run by players.";
}
@Override
public String getArgNotRecognized() {
return "§cInvalid argument type. Please check your input.";
}
@Override
public String getRequirementMessage() {
return "§cYou don't meet the requirements to run this command.";
}
}🎨 You can use color codes (e.g.,
§c,§a, etc.) or component APIs depending on your platform.
Inside your plugin’s onEnable method:
public class MyPlugin extends JavaPlugin {
private CommandManager<MyPlugin> commandManager;
@Override
public void onEnable() {
commandManager = new CommandManager<>(this);
commandManager.setMessageHandler(new CustomMessageHandler());
}
}This will replace all default messages with your customized versions.
- All message methods return raw strings.
- These messages are used across all commands managed by the
CommandManager. - You can localize messages per locale by injecting your own translation system.
Customize the experience, match your plugin's tone, and enhance feedback with your own message handler!