From 8564ec9bbd80163644959fcd3e75819f3582052c Mon Sep 17 00:00:00 2001 From: Alex 'mcmonkey' Goodwin Date: Thu, 4 Nov 2021 01:07:32 -0700 Subject: [PATCH] cleanups and improvements to debug recording internal --- .../denizen/utilities/FormattedTextHelper.java | 2 +- .../denizen/utilities/debugging/Debug.java | 8 ++++++-- .../denizen/utilities/debugging/DebugSubmit.java | 10 +++++++--- .../implementation/DenizenCoreImplementation.java | 7 +------ 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/plugin/src/main/java/com/denizenscript/denizen/utilities/FormattedTextHelper.java b/plugin/src/main/java/com/denizenscript/denizen/utilities/FormattedTextHelper.java index f6651218b3..3d0407564e 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/utilities/FormattedTextHelper.java +++ b/plugin/src/main/java/com/denizenscript/denizen/utilities/FormattedTextHelper.java @@ -249,7 +249,7 @@ public static String cleanRedundantCodes(String str) { while (index != -1) { output.append(str, start, index); start = index; - if (index + 1 > str.length()) { + if (index + 1 >= str.length()) { break; } char symbol = str.charAt(index + 1); diff --git a/plugin/src/main/java/com/denizenscript/denizen/utilities/debugging/Debug.java b/plugin/src/main/java/com/denizenscript/denizen/utilities/debugging/Debug.java index efb91604ef..e1c5e1ca31 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/utilities/debugging/Debug.java +++ b/plugin/src/main/java/com/denizenscript/denizen/utilities/debugging/Debug.java @@ -556,8 +556,12 @@ public static void sendMessage(String string, boolean reformat) { // Record current buffer to the to-be-submitted buffer if (Debug.record) { - Debug.recording.append(URLEncoder.encode(dateFormat.format(new Date()) - + " [INFO] " + string.replace(ChatColor.COLOR_CHAR, (char) 0x01) + "\n")); + try { + Debug.recording.append(URLEncoder.encode(dateFormat.format(new Date()) + string + "\n", "UTF-8")); + } + catch (Throwable ex) { + Debug.echoError(ex); + } } string = Settings.debugPrefix() + string; if (DenizenCore.logInterceptor.redirected) { diff --git a/plugin/src/main/java/com/denizenscript/denizen/utilities/debugging/DebugSubmit.java b/plugin/src/main/java/com/denizenscript/denizen/utilities/debugging/DebugSubmit.java index 932e84d01c..52c51c0568 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/utilities/debugging/DebugSubmit.java +++ b/plugin/src/main/java/com/denizenscript/denizen/utilities/debugging/DebugSubmit.java @@ -32,6 +32,7 @@ public void run() { uc.setDoInput(true); uc.setDoOutput(true); uc.setConnectTimeout(10000); + uc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); uc.connect(); // Safely connected at this point // Build a list of plugins @@ -65,7 +66,7 @@ public void run() { newlineLength = 0; int playerCount = Bukkit.getOnlinePlayers().size(); for (Player pla : Bukkit.getOnlinePlayers()) { - String temp = pla.getDisplayName().replace(ChatColor.COLOR_CHAR, (char) 0x01) + ((char) 0x01) + "7(" + pla.getName() + "), "; + String temp = pla.getDisplayName() + ChatColor.GRAY + "(" + pla.getName() + "), "; playerlist.append(temp); newlineLength += temp.length(); if (newlineLength > 80) { @@ -96,7 +97,7 @@ public void run() { // Create the final message pack and upload it uc.getOutputStream().write(("pastetype=log" + "&response=micro&v=200&pastetitle=Denizen+Debug+Logs+From+" + URLEncoder.encode(ChatColor.stripColor(Bukkit.getServer().getMotd())) - + "&pastecontents=" + URLEncoder.encode(("Java Version: " + System.getProperty("java.version") + + "&pastecontents=" + URLEncoder.encode("Java Version: " + System.getProperty("java.version") + "\nUp-time: " + new DurationTag((System.currentTimeMillis() - DenizenCore.startTime) / 50).formatted(false) + "\nServer Version: " + Bukkit.getServer().getName() + " version " + Bukkit.getServer().getVersion() + "\nDenizen Version: Core: " + DenizenCore.VERSION + ", CraftBukkit: " + Denizen.getInstance().coreImplementation.getImplementationVersion() @@ -106,12 +107,15 @@ public void run() { + "\nTotal Players Ever: " + PlayerTag.getAllPlayers().size() + " (" + validPl + " valid, " + invalidPl + " invalid)" + "\nMode: " + (Bukkit.getServer().getOnlineMode() ? ChatColor.GREEN + "online" : (bungee ? ChatColor.YELLOW : ChatColor.RED) + "offline") + (bungee ? " (BungeeCord)" : "") + "\nLast reload: " + new DurationTag((System.currentTimeMillis() - DenizenCore.lastReloadTime) / 1000.0).formatted(false) + " ago" - + "\n\n").replace(ChatColor.COLOR_CHAR, (char) 0x01)) + recording) + + "\n\n", "UTF-8") + recording) .getBytes(StandardCharsets.UTF_8)); // Wait for a response from the server in = new BufferedReader(new InputStreamReader(uc.getInputStream())); // Record the response result = in.readLine(); + if (result != null && result.startsWith((" processResult) { public void run() { if (!submit.isAlive()) { this.cancel(); - if (submit.result == null) { - processResult.accept(null); - } - else { - processResult.accept(submit.result); - } + processResult.accept(submit.result); } } };