diff --git a/src/main/java/net/aufdemrand/denizen/utilities/debugging/dB.java b/src/main/java/net/aufdemrand/denizen/utilities/debugging/dB.java index 6bcf926fa2..737ae27887 100644 --- a/src/main/java/net/aufdemrand/denizen/utilities/debugging/dB.java +++ b/src/main/java/net/aufdemrand/denizen/utilities/debugging/dB.java @@ -5,6 +5,8 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Map; +import java.util.WeakHashMap; import net.aufdemrand.denizen.Settings; @@ -198,13 +200,16 @@ public static void echoError(Throwable ex) { } } + private static final Map, String> classNameCache = new WeakHashMap, String>(); public static void log(String message) { if (!showDebug) return; + Class caller = sun.reflect.Reflection.getCallerClass(2); + String callerName = classNameCache.get(caller); + if (callerName == null) + classNameCache.put(caller, callerName = sun.reflect.Reflection.getCallerClass(2).getSimpleName()); ConsoleSender.sendMessage(ChatColor.YELLOW + "+> [" - + (sun.reflect.Reflection.getCallerClass(2).getSimpleName().length() > 16 ? - sun.reflect.Reflection.getCallerClass(2).getSimpleName().substring(0, 12) + "..." - : sun.reflect.Reflection.getCallerClass(2).getSimpleName()) + "] " + + (callerName.length() > 16 ? callerName.substring(0, 12) + "..." : callerName) + "] " + ChatColor.WHITE + trimMessage(message)); } @@ -221,6 +226,9 @@ public static void log(DebugElement element, String string) { case Header: sb.append(ChatColor.LIGHT_PURPLE).append("+- ").append(string).append(" ---------+"); break; + + default: + break; } ConsoleSender.sendMessage(sb.toString()); @@ -290,9 +298,9 @@ public static void sendMessage(String string) { // These colors are used a lot in the debugging of commands/etc, so having a few shortcuts is nicer // than having a bunch of ChatColor.XXXX string = string - .replace("", ChatColor.YELLOW + "") - .replace("", ChatColor.DARK_GRAY + "") - .replace("", ChatColor.AQUA + ""); + .replace("", ChatColor.YELLOW.toString()) + .replace("", ChatColor.DARK_GRAY.toString()) + .replace("", ChatColor.AQUA.toString()); // 'Hack-fix' for disallowing multiple 'footers' to print in a row if (string.equals(ChatColor.LIGHT_PURPLE + "+---------------------+")) { @@ -302,26 +310,28 @@ public static void sendMessage(String string) { // Create buffer for wrapping debug text nicely. This is mostly needed for Windows logging. String[] words = string.split(" "); - String buffer = ""; + StringBuilder buffer = new StringBuilder(); int length = 0; for (String word : words) { // # of total chars * # of lines - timestamp - if (length + ChatColor.stripColor(word).length() + 1 < Settings.ConsoleWidth()) { - buffer = buffer + word + " "; - length = length + ChatColor.stripColor(word).length() + 1; + int strippedLength = ChatColor.stripColor(word).length() + 1; + if (length + strippedLength < Settings.ConsoleWidth()) { + buffer.append(word).append(" "); + length = length + strippedLength; } else { // Increase # of lines to account for - length = ChatColor.stripColor(word).length() + 1; + length = strippedLength; // Leave spaces to account for timestamp and indent - buffer = buffer + "\n" + " " + word + " "; + buffer.append("\n ").append(word).append(" "); } // 16:05:06 [INFO] } + String result = buffer.toString(); // Record current buffer to the to-be-submitted buffer if (dB.record) dB.Recording.append(URLEncoder.encode(dateFormat.format(new Date()) - + " [INFO] " + buffer.replace(ChatColor.COLOR_CHAR, (char)0x01) + "\n")); + + " [INFO] " + result.replace(ChatColor.COLOR_CHAR, (char)0x01) + "\n")); // Send buffer to the player - commandSender.sendMessage(showColor ? buffer : ChatColor.stripColor(buffer)); + commandSender.sendMessage(showColor ? result : ChatColor.stripColor(result)); } }