Skip to main content

Simple Commands

BaseIO simplifies command creation with the class SimpleCommand. Instead of implementing ICommand you extend SimpleCommand.

If you don't like the simplifications made by this feature just override the original method from ICommand.

This is what SimpleCommand can do for you:

  • Simple command names - getCommandName() and getCommandAliases() are combined in commandNames() where the first command name is the actual command name and the others are aliases. Example:
  • public List<String> commandNames() {
    //return Collections.singletonList("name1");
    return Arrays.asList("name1", "name2", "name3");
    }
  • localized/default command usage - provide a localization key in commandUsage() and it will be localized as described in Localization. Provide an invalid or no (null) localization key and SimpleCommand creates a default command usage for you based on the arguments.
  • redundancy removal - isUsernameIndex and compareTo are removed.
  • Options - you can define command options in getOptions(). Options are arguments starting with a hyphen that can be used at any position of the arguments. Additionally options might have arguments attached to themselves. When implemented, getOptions() must return a map with the option string as the key and a string array of potential option arguments, the elements describing the option argument at its index. If found, the options will be cut out of the argument array and added to the option set that will be passed to the run method you have to implement in your command. Example:
  • @Override
    public void run(MinecraftServer server, ICommandSender sender, String[] args, Map<String, String[]> options) {

    }

    @NotNull
    @Override
    protected Map<String, String[]> getOptions() {
    //return Utils.map("opt1", new String[]{"oa1", "oa2"}, "opt2", new String[0], "opt3", new String[0]);
    }