Beispiel #1
0
  @SuppressWarnings("CallToThreadDumpStack")
  private List<String> getHelpLines(User user, String match) throws Exception {
    List<String> retval = new ArrayList<String>();
    File helpFile =
        new File(ess.getDataFolder(), "help_" + Util.sanitizeFileName(user.getName()) + ".txt");
    if (!helpFile.exists()) {
      helpFile =
          new File(ess.getDataFolder(), "help_" + Util.sanitizeFileName(user.getGroup()) + ".txt");
    }
    if (!helpFile.exists()) {
      helpFile = new File(ess.getDataFolder(), "help.txt");
    }
    if (helpFile.exists()) {
      final BufferedReader bufferedReader = new BufferedReader(new FileReader(helpFile));
      try {

        while (bufferedReader.ready()) {
          final String line = bufferedReader.readLine();
          retval.add(line.replace('&', '§'));
        }
      } finally {
        bufferedReader.close();
      }
      return retval;
    }

    boolean reported = false;
    String pluginName = "";
    for (Plugin p : ess.getServer().getPluginManager().getPlugins()) {
      try {
        final PluginDescriptionFile desc = p.getDescription();
        final HashMap<String, HashMap<String, String>> cmds =
            (HashMap<String, HashMap<String, String>>) desc.getCommands();
        for (Entry<String, HashMap<String, String>> k : cmds.entrySet()) {
          if ((!match.equalsIgnoreCase(""))
              && (!p.getDescription().getName().toLowerCase().contains(match))
              && (!p.getDescription().getDescription().toLowerCase().contains(match))) {
            continue;
          }

          if (p.getDescription().getName().toLowerCase().contains("essentials")) {
            final String node = "essentials." + k.getKey();
            if (!ess.getSettings().isCommandDisabled(k.getKey()) && user.isAuthorized(node)) {
              retval.add("§c" + k.getKey() + "§7: " + k.getValue().get("description"));
            }
          } else {
            if (ess.getSettings().showNonEssCommandsInHelp()) {
              pluginName = p.getDescription().getName();
              final HashMap<String, String> value = k.getValue();
              if (value.containsKey("permission")
                  && value.get("permission") != null
                  && !(value.get("permission").equals(""))) {
                if (user.isAuthorized(value.get("permission"))) {
                  retval.add("§c" + k.getKey() + "§7: " + value.get("description"));
                }
              } else {
                if (!ess.getSettings().hidePermissionlessHelp()) {
                  retval.add("§c" + k.getKey() + "§7: " + value.get("description"));
                }
              }
            }
          }
        }
      } catch (NullPointerException ex) {
        continue;
      } catch (Exception ex) {
        if (!reported) {
          logger.log(Level.WARNING, "Error getting help for:" + pluginName, ex);
        }
        reported = true;
        continue;
      }
    }
    return retval;
  }