Example #1
0
  public ArrayList<HelpEntry> getSortedHelp(Player player, int start, int size, String plugin) {
    ArrayList<HelpEntry> ret = new ArrayList<HelpEntry>();
    if (!pluginHelpList.containsKey(plugin)) {
      return ret;
    } else {
      List<String> names = new ArrayList<String>(pluginHelpList.get(plugin).keySet());
      Collator collator = Collator.getInstance();
      collator.setStrength(Collator.SECONDARY);
      Collections.sort(names, collator);

      int index = 0;
      int currentCount = 0;
      int lineLength = 0;
      while (index < names.size() && lineLength < size) {
        String currName = names.get(index);
        HelpEntry entry = pluginHelpList.get(plugin).get(currName);
        if (entry.playerCanUse(player) && entry.visible) {
          if (currentCount >= start) {
            ret.add(entry);
            lineLength += entry.lineLength;
          } else {
            currentCount++;
          }
        }
        index++;
      }
      return ret;
    }
  }
Example #2
0
 public double getMaxEntries(Player player) {
   int count = 0;
   for (HelpEntry entry : mainHelpList.values()) {
     if (entry.playerCanUse(player) && entry.visible) {
       count++;
     }
   }
   return count;
 }
Example #3
0
 public double getMaxEntries(Player player, String plugin) {
   if (pluginHelpList.containsKey(plugin)) {
     int count = 0;
     for (HelpEntry entry : pluginHelpList.get(plugin).values()) {
       if (entry.playerCanUse(player) && entry.visible) {
         count++;
       }
     }
     return count;
   } else {
     return 0;
   }
 }
Example #4
0
 public boolean registerCommand(
     String command,
     String description,
     String plugin,
     boolean main,
     String[] permissions,
     File dataFolder) {
   HelpEntry entry = new HelpEntry(command, description, plugin, main, permissions, true);
   entry.save(dataFolder);
   if (main && !mainHelpList.containsKey(command)) {
     mainHelpList.put(command, entry);
   }
   savePluginEntry(plugin, entry);
   return true;
 }
Example #5
0
  public MatchList getMatches(String query, Player player) {
    ArrayList<HelpEntry> commandMatches = new ArrayList<HelpEntry>();
    ArrayList<HelpEntry> pluginExactMatches = new ArrayList<HelpEntry>();
    ArrayList<HelpEntry> pluginPartialMatches = new ArrayList<HelpEntry>();
    ArrayList<HelpEntry> descriptionMatches = new ArrayList<HelpEntry>();

    Collator collator = Collator.getInstance();
    collator.setStrength(Collator.SECONDARY);

    List<String> plugins = new ArrayList<String>(pluginHelpList.keySet());
    Collections.sort(plugins, collator);

    for (int i = 0; i < plugins.size(); i++) {
      String pluginName = plugins.get(i);
      HashMap<String, HelpEntry> pluginSet = pluginHelpList.get(pluginName);
      List<String> commands = new ArrayList<String>(pluginSet.keySet());
      Collections.sort(commands, collator);
      for (int j = 0; j < commands.size(); j++) {
        String command = commands.get(j);
        HelpEntry entry = pluginSet.get(command);
        if (entry.playerCanUse(player) && entry.visible) {
          // TODO Separate word matching
          if (pluginName.equalsIgnoreCase(query)) {
            pluginExactMatches.add(entry);
          } else if (pluginName.toLowerCase().contains(query.toLowerCase())) {
            pluginPartialMatches.add(entry);
          }
          if (entry.description.toLowerCase().contains(query.toLowerCase())) {
            descriptionMatches.add(entry);
          }
          if (entry.command.toLowerCase().contains(query.toLowerCase())) {
            commandMatches.add(entry);
          }
        }
      }
    }

    return new MatchList(
        commandMatches, pluginExactMatches, pluginPartialMatches, descriptionMatches);
  }