From 2d5a6018a2cfc4baafa419747bd87dcb427a4955 Mon Sep 17 00:00:00 2001 From: mcmonkey Date: Tue, 26 Feb 2019 19:35:40 -0800 Subject: [PATCH] fix exception output format --- .../denizen/nms/interfaces/EntityHelper.java | 2 +- .../denizen/utilities/debugging/dB.java | 54 +++++++++++-------- 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/nmshandler/src/main/java/net/aufdemrand/denizen/nms/interfaces/EntityHelper.java b/nmshandler/src/main/java/net/aufdemrand/denizen/nms/interfaces/EntityHelper.java index 08ea477e94..1187dd65e5 100644 --- a/nmshandler/src/main/java/net/aufdemrand/denizen/nms/interfaces/EntityHelper.java +++ b/nmshandler/src/main/java/net/aufdemrand/denizen/nms/interfaces/EntityHelper.java @@ -212,7 +212,7 @@ public void unhideEntity(Player player, Entity entity) { public static UUID DEFAULT_HIDE = new UUID(0, 0); - public boolean isHiddenByDefault(Entity ent) { // TODO: Backport? + public boolean isHiddenByDefault(Entity ent) { Set hiding = hiddenEntitiesEntPl.get(ent.getUniqueId()); return hiding != null && hiding.contains(DEFAULT_HIDE); } diff --git a/plugin/src/main/java/net/aufdemrand/denizen/utilities/debugging/dB.java b/plugin/src/main/java/net/aufdemrand/denizen/utilities/debugging/dB.java index e746fa50d5..3e0efcbb79 100644 --- a/plugin/src/main/java/net/aufdemrand/denizen/utilities/debugging/dB.java +++ b/plugin/src/main/java/net/aufdemrand/denizen/utilities/debugging/dB.java @@ -261,7 +261,7 @@ else if (source != null && source.getLastEntryExecuted() != null && source.getLa ConsoleSender.sendMessage(ChatColor.LIGHT_PURPLE + " " + ChatColor.RED + "ERROR" + (script != null ? " in script '" + script.getName() + "'" : "") + (source != null ? " in queue '" + source.id + "'" : "") + "! " - + ChatColor.WHITE + trimMessage(message)); + + ChatColor.WHITE + message); if (net.aufdemrand.denizencore.utilities.debugging.dB.verbose && depthCorrectError == 0) { depthCorrectError++; try { @@ -345,7 +345,14 @@ public static void echoError(ScriptQueue source, Throwable ex) { ex = ex.getCause(); first = false; } - dB.echoError(source, errorMesage.toString()); + dScript script = null; + if (source != null && source.getEntries().size() > 0 && source.getEntries().get(0).getScript() != null) { + script = source.getEntries().get(0).getScript(); + } + ConsoleSender.sendMessage(ChatColor.LIGHT_PURPLE + " " + ChatColor.RED + "ERROR" + + (script != null ? " in script '" + script.getName() + "'" : "") + + (source != null ? " in queue '" + source.id + "'" : "") + "! " + + ChatColor.WHITE + errorMesage.toString(), false); } throwErrorEvent = wasThrown; } @@ -521,6 +528,9 @@ private static class ConsoleSender { // Use this method for sending a message public static void sendMessage(String string) { + sendMessage(string, true); + } + public static void sendMessage(String string, boolean reformat) { if (commandSender == null) { commandSender = Bukkit.getServer().getConsoleSender(); } @@ -547,34 +557,36 @@ public static void sendMessage(String string) { skipFooter = false; } - // Create buffer for wrapping debug text nicely. This is mostly needed for Windows logging. - String[] words = string.split(" "); - StringBuilder buffer = new StringBuilder(); - int length = 0; - int width = Settings.consoleWidth(); - for (String word : words) { // # of total chars * # of lines - timestamp - int strippedLength = ChatColor.stripColor(word).length() + 1; - if (length + strippedLength < width) { - buffer.append(word).append(" "); - length = length + strippedLength; + if (reformat) { + // Create buffer for wrapping debug text nicely. This is mostly needed for Windows logging. + String[] words = string.split(" "); + StringBuilder buffer = new StringBuilder(); + int length = 0; + int width = Settings.consoleWidth(); + for (String word : words) { // # of total chars * # of lines - timestamp + int strippedLength = ChatColor.stripColor(word).length() + 1; + if (length + strippedLength < width) { + buffer.append(word).append(" "); + length = length + strippedLength; + } + else { + // Increase # of lines to account for + length = strippedLength; + // Leave spaces to account for timestamp and indent + buffer.append("\n ").append(word).append(" "); + } // [01:02:03 INFO]: } - else { - // Increase # of lines to account for - length = strippedLength; - // Leave spaces to account for timestamp and indent - buffer.append("\n ").append(word).append(" "); - } // [01:02:03 INFO]: + string = buffer.toString(); } - 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] " + result.replace(ChatColor.COLOR_CHAR, (char) 0x01) + "\n")); + + " [INFO] " + string.replace(ChatColor.COLOR_CHAR, (char) 0x01) + "\n")); } // Send buffer to the player - commandSender.sendMessage(showColor ? result : ChatColor.stripColor(result)); + commandSender.sendMessage(showColor ? string : ChatColor.stripColor(string)); } } }