Пример #1
1
  /**
   * Get all the commands available to this CommandManager. This is potentially expensive.
   *
   * @param startsWith Limit to commands that start with this string. "" or "?" will return all
   *     commands.
   * @param allowAdmin Allow admin-only commands?
   * @return Map of available commands.
   */
  public Map<String, Command> getAllCommands(final String startsWith, final boolean allowAdmin) {
    final String sw = startsWith.toLowerCase();
    final boolean allCommands = startsWith.isEmpty() || startsWith.equals("?");

    // First get our own commands
    final Map<String, Command> result =
        knownCommands
            .entrySet()
            .parallelStream()
            .filter(e -> allowAdmin || !e.getValue().isAdminOnly())
            .filter(
                e ->
                    allCommands
                        || e.getKey().startsWith(sw)
                        || e.getKey().startsWith(HIDDEN_PREFIX + sw))
            .collect(Collectors.toMap(Entry::getKey, Entry::getValue));

    // Now all our submanagers' commands
    for (CommandManager subManager : subManagers) {
      result.putAll(
          subManager
              .getAllCommands(startsWith, allowAdmin)
              .entrySet()
              .parallelStream()
              .filter(entry -> !result.containsKey(entry.getKey()))
              .collect(Collectors.toMap(Entry::getKey, Entry::getValue)));
    }

    return result;
  }
Пример #2
1
 /**
  * Add new Sub Command Manager.
  *
  * @param manager Sub CommandManager to add.
  * @return true if the CommandManager was added, else false.
  */
 public boolean addSubCommandManager(final CommandManager manager) {
   return !hasSubCommandManager(manager)
       && manager != this
       && !manager.hasSubCommandManager(this)
       && subManagers.parallelStream().noneMatch(manager::hasSubCommandManager)
       && subManagers.add(manager);
 }