Esempio n. 1
0
  public void generateICDocs(Player player, String id) {

    RegisteredICFactory ric = ICManager.registered.get(id.toLowerCase());
    if (ric == null) {
      try {
        ric = ICManager.registered.get(getSearchID(player, id));
        if (ric == null) {
          player.sendMessage(ChatColor.RED + "Invalid IC!");
          return;
        }
      } catch (Exception e) {
        player.sendMessage(ChatColor.RED + "Invalid IC!");
        return;
      }
    }
    try {
      IC ic = ric.getFactory().create(null);
      player.sendMessage(" "); // To space the area
      player.sendMessage(ChatColor.BLUE + ic.getTitle() + " (" + ric.getId() + ") Documentation");
      if (plugin.getConfiguration().ICShortHandEnabled && ric.getShorthand() != null) {
        player.sendMessage(ChatColor.YELLOW + "Shorthand: =" + ric.getShorthand());
      }
      player.sendMessage(ChatColor.YELLOW + "Desc: " + ric.getFactory().getShortDescription());
      if (ric.getFactory().getLineHelp()[0] != null) {
        player.sendMessage(ChatColor.YELLOW + "Line 3: " + ric.getFactory().getLineHelp()[0]);
      } else {
        player.sendMessage(ChatColor.YELLOW + "Line 3: Blank.");
      }
      if (ric.getFactory().getLineHelp()[1] != null) {
        player.sendMessage(ChatColor.YELLOW + "Line 4: " + ric.getFactory().getLineHelp()[1]);
      } else {
        player.sendMessage(ChatColor.YELLOW + "Line 4: Blank.");
      }
      player.sendMessage(
          ChatColor.AQUA
              + "Wiki: "
              + "http://wiki.sk89q.com/wiki/CraftBook/"
              + ric.getId().toUpperCase());
    } catch (Exception ignored) {
    }
  }
Esempio n. 2
0
  public String getSearchID(Player p, String search) {

    ArrayList<String> icNameList = new ArrayList<String>();
    icNameList.addAll(ICManager.registered.keySet());

    Collections.sort(icNameList);

    for (String ic : icNameList) {
      try {
        RegisteredICFactory ric = ICManager.registered.get(ic);
        IC tic = ric.getFactory().create(null);
        if (search != null
            && !tic.getTitle().toLowerCase().contains(search.toLowerCase())
            && !ric.getId().toLowerCase().contains(search.toLowerCase())) continue;

        return ic;
      } catch (Exception ignored) {
      }
    }

    return "";
  }
Esempio n. 3
0
  /**
   * Used for the /ic list command.
   *
   * @param p
   * @return
   */
  public String[] generateICText(Player p, String search, char[] parameters) {

    ArrayList<String> icNameList = new ArrayList<String>();
    icNameList.addAll(ICManager.registered.keySet());

    Collections.sort(icNameList);

    ArrayList<String> strings = new ArrayList<String>();
    boolean col = true;
    for (String ic : icNameList) {
      try {
        thisIC:
        {
          RegisteredICFactory ric = ICManager.registered.get(ic);
          IC tic = ric.getFactory().create(null);
          if (search != null
              && !tic.getTitle().toLowerCase().contains(search.toLowerCase())
              && !ric.getId().toLowerCase().contains(search.toLowerCase())) continue;
          if (parameters != null) {
            for (char c : parameters) {
              if (c == 'r' && !(ric.getFactory() instanceof RestrictedIC)) break thisIC;
              else if (c == 's' && ric.getFactory() instanceof RestrictedIC) break thisIC;
              else if (c == 'b'
                  && !ric.getFactory().getClass().getPackage().getName().endsWith("blocks"))
                break thisIC;
              else if (c == 'i'
                  && !ric.getFactory().getClass().getPackage().getName().endsWith("items"))
                break thisIC;
              else if (c == 'e'
                  && !ric.getFactory().getClass().getPackage().getName().endsWith("entity"))
                break thisIC;
              else if (c == 'w'
                  && !ric.getFactory().getClass().getPackage().getName().endsWith("weather"))
                break thisIC;
              else if (c == 'l'
                  && !ric.getFactory().getClass().getPackage().getName().endsWith("logic"))
                break thisIC;
              else if (c == 'm'
                  && !ric.getFactory().getClass().getPackage().getName().endsWith("miscellaneous"))
                break thisIC;
              else if (c == 'c'
                  && !ric.getFactory().getClass().getPackage().getName().endsWith("sensors"))
                break thisIC;
            }
          }
          col = !col;
          ChatColor colour = col ? ChatColor.YELLOW : ChatColor.GOLD;

          if (!ICMechanicFactory.checkPermissionsBoolean(
              CraftBookPlugin.inst().wrapPlayer(p), ric.getFactory(), ic.toLowerCase())) {
            colour = col ? ChatColor.RED : ChatColor.DARK_RED;
          }
          strings.add(
              colour
                  + tic.getTitle()
                  + " ("
                  + ric.getId()
                  + ")"
                  + ": "
                  + (tic instanceof SelfTriggeredIC ? "ST " : "T ")
                  + (ric.getFactory() instanceof RestrictedIC ? ChatColor.DARK_RED + "R " : ""));
        }
      } catch (Throwable e) {
        plugin.getLogger().warning("An error occurred generating the docs for IC: " + ic + ".");
        plugin.getLogger().warning("Please report this error on: http://youtrack.sk89q.com/.");
      }
    }

    return strings.toArray(new String[strings.size()]);
  }