From 7e58d6abeef450e8dd15d72b4a3363a2d59f2cbf Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 27 May 2024 16:38:22 -0500 Subject: [PATCH] Only capture printed text up to specified length and remove new line at end of string (new line is inserted by the script's logger) --- .../magicmq/pyspigot/util/logging/PrintStreamWrapper.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/dev/magicmq/pyspigot/util/logging/PrintStreamWrapper.java b/src/main/java/dev/magicmq/pyspigot/util/logging/PrintStreamWrapper.java index e0abe95..8b322d8 100644 --- a/src/main/java/dev/magicmq/pyspigot/util/logging/PrintStreamWrapper.java +++ b/src/main/java/dev/magicmq/pyspigot/util/logging/PrintStreamWrapper.java @@ -21,6 +21,7 @@ import java.io.OutputStream; import java.io.PrintStream; import java.nio.charset.StandardCharsets; +import java.util.Arrays; import java.util.logging.Level; /** @@ -54,7 +55,9 @@ public PrintStreamWrapper(OutputStream out, Script script, Level level, String p */ @Override public void write(byte[] buf, int off, int len) { - String string = new String(buf, StandardCharsets.UTF_8); + byte[] toLog = Arrays.copyOfRange(buf, 0, len); + String string = new String(toLog, StandardCharsets.UTF_8); + string = string.replaceAll("\\R$", ""); script.getLogger().log(level, prefix + " " + string); }