Skip to content

Instantly share code, notes, and snippets.

@molenzwiebel
Last active January 2, 2016 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save molenzwiebel/7072087 to your computer and use it in GitHub Desktop.
Save molenzwiebel/7072087 to your computer and use it in GitHub Desktop.
Nested commands. This example allows for /hello if you register Commands.class and allows for /myplugin hello if you register ParentCommand.class
public class Commands {
public static class ParentCommand {
@Command(aliases = { "myplugin"}, desc = "All MyPlugin commands", min = 0, max = -1)
@NestedCommand(Command.class) //All commands will get passed on to Commands.class
public static void myplugin(final CommandContext args, CommandSender sender) throws CommandException {
}
}
@Command(aliases = { "hello", "hey" }, desc = "Says hello", usage = "[player] - The player to say hello to", min = 1, max = 1)
public static void hello(final CommandContext args, CommandSender sender) throws CommandException {
Player target = Bukkit.getPlayer(args.getString(0)); //0 is the index
if (target == null) throw new CommandException("Player "+args.getString(0)+" not found!");
target.sendMessage("Hello!");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment