From 65e85eb8534fe169989465e554be794ba7abc368 Mon Sep 17 00:00:00 2001 From: rtm516 Date: Wed, 25 Aug 2021 11:31:12 +0100 Subject: [PATCH] Fix bungeecord dump logs after 9fb5090 --- .../bungeecord/GeyserBungeePlugin.java | 9 +-------- .../org/geysermc/connector/dump/DumpInfo.java | 3 ++- .../geysermc/connector/utils/FileUtils.java | 18 +++++++++++++++++- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePlugin.java b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePlugin.java index 7c7be5b90..548ec7210 100644 --- a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePlugin.java +++ b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePlugin.java @@ -174,14 +174,7 @@ public class GeyserBungeePlugin extends Plugin implements GeyserBootstrap { @Override public Path getLogsPath() { - boolean isBungeeCord = getProxy().getName().equals("BungeeCord"); - Path getFork; - if (isBungeeCord) { - getFork = Paths.get("proxy.log.0"); - } else { - getFork = Paths.get("logs/latest.log"); - } - return getFork; + return Paths.get(getProxy().getName().equals("BungeeCord") ? "proxy.log.0" : "logs/latest.log"); } @Nullable diff --git a/connector/src/main/java/org/geysermc/connector/dump/DumpInfo.java b/connector/src/main/java/org/geysermc/connector/dump/DumpInfo.java index c006c28b2..d6a5f0725 100644 --- a/connector/src/main/java/org/geysermc/connector/dump/DumpInfo.java +++ b/connector/src/main/java/org/geysermc/connector/dump/DumpInfo.java @@ -52,6 +52,7 @@ import java.net.*; import java.util.HashMap; import java.util.Map; import java.util.Properties; +import java.util.stream.Collectors; @Getter public class DumpInfo { @@ -201,7 +202,7 @@ public class DumpInfo { public LogsInfo() { try { Map fields = new HashMap<>(); - fields.put("content", String.join("\n", java.nio.file.Files.readAllLines(GeyserConnector.getInstance().getBootstrap().getLogsPath()))); + fields.put("content", FileUtils.readAllLines(GeyserConnector.getInstance().getBootstrap().getLogsPath()).collect(Collectors.joining("\n"))); JsonNode logData = GeyserConnector.JSON_MAPPER.readTree(WebUtils.postForm("https://api.mclo.gs/1/log", fields)); diff --git a/connector/src/main/java/org/geysermc/connector/utils/FileUtils.java b/connector/src/main/java/org/geysermc/connector/utils/FileUtils.java index 3369f16a5..091c90a90 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/FileUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/FileUtils.java @@ -35,10 +35,12 @@ import java.io.*; import java.lang.annotation.Annotation; import java.nio.charset.StandardCharsets; import java.nio.file.Files; +import java.nio.file.Path; import java.security.MessageDigest; import java.util.Set; import java.util.function.Function; import java.util.stream.Collectors; +import java.util.stream.Stream; public class FileUtils { @@ -220,7 +222,21 @@ public class FileUtils { } return bytes; } catch (IOException e) { - throw new RuntimeException("Error while trying to read input stream!"); + throw new RuntimeException("Error while trying to read input stream!", e); + } + } + + /** + * Read the lines of a file and return it as a stream + * + * @param path File path to read + * @return The lines as a stream + */ + public static Stream readAllLines(Path path) { + try { + return new BufferedReader(new InputStreamReader(java.nio.file.Files.newInputStream(path))).lines(); + } catch (IOException e) { + throw new RuntimeException("Error while trying to read file!", e); } }