Skip to content

Creating subcommand fail listener

Leonardo Luiz Gava edited this page Jan 6, 2023 · 6 revisions

You can create events to be triggered when a subcommand is not executed correctly, for example if the player dont have the permission to use a specific subcommand.

Player Without Permission listener

listener class

public class MyCustomListener implements Listener {

  @EventHandler
  public void playerWithoutPermission(SubcommandFailEvent event) {
    if(event.getFailType() != NeelixSubcommandFailType.WITHOUT_PERMISSION_FOR_SUBCOMMAND) return;

    Player player = event.getPlayerWithoutPermission();
    NeelixSubcommand subcommand = event.getSubcommand();

    player.sendMessage("You don't have permission to use the subcommand " + subcommand.getName());
    player.sendMessage("Needed permission: " + subcommand.getPermission());
  }
}

Subcommand not found listener

listener class

public class MyCustomListener implements Listener {

  @EventHandler
  public void subcommandNotFound(SubcommandFailEvent event) {
    if(event.getFailType() != NeelixSubcommandFailType.SUBCOMMAND_NOT_FOUND) return;

    Player player = event.getPlayerWithoutPermission();

    player.sendMessage("Subcommand not found. Use /help command for more info.");
  }
}