コード例 #1
0
ファイル: RPGItem.java プロジェクト: OsipXD/RPG-Items
  public List<String> getTooltipLines(String locale) {
    ArrayList<String> output = new ArrayList<String>();
    int width = 150;
    output.add(encodedID + quality.colour + ChatColor.BOLD + displayName);
    int dWidth = getStringWidthBold(ChatColor.stripColor(displayName));
    if (dWidth > width) width = dWidth;

    dWidth = getStringWidth(ChatColor.stripColor(hand + "     " + type));
    if (dWidth > width) width = dWidth;
    String damageStr;
    if (damageMin == 0 && damageMax == 0 && armour != 0) {
      damageStr = armour + "% " + Plugin.plugin.getConfig().getString("defaults.armour", "Armour");
    } else if (armour == 0 && damageMin == 0 && damageMax == 0) {
      damageStr = null;
    } else if (damageMin == damageMax) {
      damageStr =
          damageMin + " " + Plugin.plugin.getConfig().getString("defaults.damage", "Damage");
    } else {
      damageStr =
          damageMin
              + "-"
              + damageMax
              + " "
              + Plugin.plugin.getConfig().getString("defaults.damage", "Damage");
    }
    if (damageMin != 0 || damageMax != 0 || armour != 0) {
      dWidth = getStringWidth(damageStr);
      if (dWidth > width) width = dWidth;
    }

    for (Power p : powers) {
      dWidth = getStringWidth(ChatColor.stripColor(p.displayText(locale)));
      if (dWidth > width) width = dWidth;
    }

    for (String s : description) {
      dWidth = getStringWidth(ChatColor.stripColor(s));
      if (dWidth > width) width = dWidth;
    }

    tooltipWidth = width;

    output.add(
        ChatColor.WHITE
            + hand
            + StringUtils.repeat(
                " ", (width - getStringWidth(ChatColor.stripColor(hand + type))) / 4)
            + type);
    if (damageStr != null) {
      output.add(ChatColor.WHITE + damageStr);
    }

    for (Power p : powers) {
      output.add(p.displayText(locale));
    }
    if (loreText.length() != 0) {
      int cWidth = 0;
      int tWidth = 0;
      StringBuilder out = new StringBuilder();
      StringBuilder temp = new StringBuilder();
      out.append(ChatColor.YELLOW);
      out.append(ChatColor.ITALIC);
      String currentColour = ChatColor.YELLOW.toString();
      String dMsg = "\"" + loreText + "\"";
      for (int i = 0; i < dMsg.length(); i++) {
        char c = dMsg.charAt(i);
        temp.append(c);
        if (c == ChatColor.COLOR_CHAR || c == '&') {
          i += 1;
          temp.append(dMsg.charAt(i));
          currentColour = ChatColor.COLOR_CHAR + "" + dMsg.charAt(i);
          continue;
        }
        if (c == ' ') tWidth += 4;
        else tWidth += Font.widths[c] + 1;
        if (c == ' ' || i == dMsg.length() - 1) {
          if (cWidth + tWidth > width) {
            cWidth = 0;
            cWidth += tWidth;
            tWidth = 0;
            output.add(out.toString());
            out = new StringBuilder();
            out.append(currentColour);
            out.append(ChatColor.ITALIC);
            out.append(temp);
            temp = new StringBuilder();
          } else {
            out.append(temp);
            temp = new StringBuilder();
            cWidth += tWidth;
            tWidth = 0;
          }
        }
      }
      out.append(temp);
      output.add(out.toString());
    }

    for (String s : description) {
      output.add(s);
    }
    return output;
  }