Exemple #1
0
  /**
   * This is my favorite debug routine :) I use it everywhere to print out variable values
   *
   * @param s - array of any object that you need to print out. Example: Message.BC ("variable
   *     1:",var1,"variable 2:",var2)
   */
  public static void BC(Object... s) {
    if (!debugMode) return;
    if (s.length == 0) return;

    StringBuilder sb =
        new StringBuilder("&3[").append(plugin.getDescription().getName()).append("]&f ");
    for (Object str : s) sb.append(str.toString()).append(" ");
    plugin.getServer().broadcastMessage(TextFormat.colorize(sb.toString().trim()));
  }
Exemple #2
0
 public static boolean debugMessage(Object... s) {
   if (debugMode) plugin.getLogger().info(TextFormat.clean(join(s)));
   return true;
 }
Exemple #3
0
  /**
   * Get formated text.
   *
   * @param keys
   * @return
   */
  public String getText(Object... keys) {
    if (keys.length == 0) return TextFormat.colorize("&" + c1 + this.message);
    String str = this.message;
    boolean noColors = false;
    boolean skipDefaultColors = false;
    boolean fullFloat = false;
    String prefix = "";
    int count = 1;
    char[] colors = new char[] {c1, c2};
    int c = 0;
    DecimalFormat fmt = new DecimalFormat("####0.##");
    for (int i = 0; i < keys.length; i++) {
      String s = keys[i].toString();
      if (c < 2 && keys[i] instanceof Character) {
        colors[c] = (Character) keys[i];
        c++;
        continue;
      } else if (s.startsWith("prefix:")) {
        prefix = s.replace("prefix:", "");
        continue;
      } else if (s.equals("SKIPCOLOR")) {
        skipDefaultColors = true;
        continue;
      } else if (s.equals("NOCOLORS") || s.equals("NOCOLOR")) {
        noColors = true;
        continue;
      } else if (s.equals("FULLFLOAT")) {
        fullFloat = true;
        continue;
      } else if (keys[i] instanceof Location) {
        Location loc = (Location) keys[i];
        if (fullFloat)
          s =
              loc.getLevel().getName()
                  + "["
                  + loc.getX()
                  + ", "
                  + loc.getY()
                  + ", "
                  + loc.getZ()
                  + "]";
        else
          s =
              loc.getLevel().getName()
                  + "["
                  + fmt.format(loc.getX())
                  + ", "
                  + fmt.format(loc.getY())
                  + ", "
                  + fmt.format(loc.getZ())
                  + "]";
      } else if (keys[i] instanceof Double || keys[i] instanceof Float) {
        if (!fullFloat) s = fmt.format((Double) keys[i]);
      }

      String from = (new StringBuilder("%").append(count).append("%")).toString();
      String to =
          skipDefaultColors
              ? s
              : (new StringBuilder("&").append(colors[1]).append(s).append("&").append(colors[0]))
                  .toString();
      str = str.replace(from, to);
      count++;
    }
    str =
        TextFormat.colorize(
            prefix.isEmpty() ? "&" + colors[0] + str : prefix + " " + "&" + colors[0] + str);
    if (noColors) str = TextFormat.clean(str);
    return str;
  }
Exemple #4
0
 /**
  * Same as log, but will printout nothing if debug mode is disabled
  *
  * @param s
  * @return
  */
 public boolean debug(Object... s) {
   if (debugMode) plugin.getLogger().info(TextFormat.clean(getText(s)));
   return true;
 }