Skip to content

Commit

Permalink
fix exception output format
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Feb 27, 2019
1 parent 7317e2c commit 2d5a601
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 22 deletions.
Expand Up @@ -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<UUID> hiding = hiddenEntitiesEntPl.get(ent.getUniqueId());
return hiding != null && hiding.contains(DEFAULT_HIDE);
}
Expand Down
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
}
Expand All @@ -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));
}
}
}

0 comments on commit 2d5a601

Please sign in to comment.