Skip to content

Custom Handling System

Traqueur edited this page Jul 4, 2025 · 4 revisions

💬 CommandsAPI – Custom Message Handling (v4)

This guide shows how to fully customize the feedback messages sent to users when executing commands through CommandsAPI.


📘 Overview

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!


🧱 The MessageHandler Interface

Located in:

fr.traqueur.commands.api.lang.MessageHandler

Here 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.


🛠 Creating a Custom MessageHandler

✅ Step 1: Implement the Interface

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.


✅ Step 2: Register Your Handler

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.


📌 Notes

  • 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!

Clone this wiki locally