Last active
January 2, 2016 12:41
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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