Exemplo n.º 1
0
  public void registerCommands(Class<?> clazz, CommandContainer base) {
    Validate.notNull(clazz);

    Set<CommandContainer> commands =
        CommandContainer.create(clazz, base, instantiator, execution, logger);
    Iterator<CommandContainer> iterator = commands.iterator();

    while (iterator.hasNext()) {
      CommandContainer command = iterator.next();

      if (base == null) {
        if (commandMap.containsKey(command.getName())) {
          logger.warning("duplicate command " + command.getName() + "!");
          continue;
        }

        commandMap.put(command.getName(), command);

        PluginCommand bukkitCommand = plugin.getCommand(command.getName());
        if (bukkitCommand != null) {
          bukkitCommand.setExecutor(this);
        } else {
          logger.warning(
              "Command "
                  + command.getName()
                  + " registered but could not find a matching command for plugin "
                  + plugin.getName()
                  + ". Did you forget to add the command to your plugin.yml?");
        }
      } else {
        // Just add it as a child
        base.addChild(command);
      }
    }
  }
Exemplo n.º 2
0
  public SearchResult searchCommand(String name, String[] args) {
    CommandContainer command = commandMap.get(name);

    // Try to find the deepest available sub-command
    int index = 0;
    boolean subFound;

    if (args.length > 0) {
      do {
        subFound = false;

        Set<CommandContainer> childs = command.getChildCommands();

        if (childs != null) {
          for (CommandContainer child : childs) {
            if (child.getName().equals(args[index])) {
              command = child;
              index++;
              subFound = true;
              break;
            }
          }
        }
      } while (index < args.length && subFound);
    }

    SearchResult result = new SearchResult();
    result.container = command;
    result.deepness = index;

    return result;
  }