Skip to content

Filters

Kaktushose edited this page Jun 14, 2022 · 2 revisions

Filters

You can create filters, that can cancel the command execution:

@Component(position = FilterPosition.BEFORE_ROUTING)
public class ExampleFilter implements Filter {

    @Override
    public void apply(@NotNull CommandContext context) {
        if (condition) {
            context.setCancelled(true);
            context.setErrorMessage(new MessageBuilder().append("Error Message").build());
            return;
        }
    }
}

The following positions are available:

  • BEFORE_ROUTING - Filter will be executed before command routing. The command will not be present in the CommandContext

  • BEFORE_ADAPTING - Filter will be executed before type adapting. The command will be present in the CommandContext but not the type adapted input.

  • BEFORE_EXECUTION - Filter will be executed just before the command execution.

Important

This wiki is the documentation for V3 (text commands)! If you're using V4 (interactions) please refer to the new documentation

Home

Getting Started

Writing Commands

Advanced Configuration

Util

Clone this wiki locally