From 197fbb661778dd746889b267c3f05712f983c356 Mon Sep 17 00:00:00 2001 From: xaver106 Date: Wed, 1 Jun 2022 23:48:22 +0200 Subject: [PATCH 1/7] feature: Add language files to debugpaste --- .../plotsquared/core/command/DebugPaste.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Core/src/main/java/com/plotsquared/core/command/DebugPaste.java b/Core/src/main/java/com/plotsquared/core/command/DebugPaste.java index dd643f6c5..f88c05914 100644 --- a/Core/src/main/java/com/plotsquared/core/command/DebugPaste.java +++ b/Core/src/main/java/com/plotsquared/core/command/DebugPaste.java @@ -32,6 +32,7 @@ import com.intellectualsites.paster.IncendoPaster; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.configuration.Storage; +import com.plotsquared.core.configuration.caption.StaticCaption; import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.inject.annotations.ConfigFile; import com.plotsquared.core.inject.annotations.WorldFile; @@ -46,6 +47,7 @@ import java.io.IOException; import java.lang.management.ManagementFactory; import java.lang.management.RuntimeMXBean; import java.nio.file.Files; +import java.util.Collection; import java.util.concurrent.TimeUnit; @CommandDeclaration(command = "debugpaste", @@ -173,6 +175,24 @@ public class DebugPaste extends SubCommand { ); } + final File langDir = new File( + PlotSquared.platform().getDirectory(), + "lang" + ); + + try { + for (File current : langDir.listFiles()) { + try { + if (current.getName().startsWith("messages_") && current.getName().endsWith(".json")) { + incendoPaster.addFile(current); + } + } catch (NullPointerException ignored) { + } + } + } catch (NullPointerException ignored) { + //No lang files found + } + try { final String rawResponse = incendoPaster.upload(); final JsonObject jsonObject = From 724c8a6148ccacf2cf4b3a836e364b3f7b0a3490 Mon Sep 17 00:00:00 2001 From: xaver106 Date: Wed, 1 Jun 2022 23:54:32 +0200 Subject: [PATCH 2/7] refactor: cleanup imports --- Core/src/main/java/com/plotsquared/core/command/DebugPaste.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/Core/src/main/java/com/plotsquared/core/command/DebugPaste.java b/Core/src/main/java/com/plotsquared/core/command/DebugPaste.java index f88c05914..c3d345465 100644 --- a/Core/src/main/java/com/plotsquared/core/command/DebugPaste.java +++ b/Core/src/main/java/com/plotsquared/core/command/DebugPaste.java @@ -32,7 +32,6 @@ import com.intellectualsites.paster.IncendoPaster; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.configuration.Storage; -import com.plotsquared.core.configuration.caption.StaticCaption; import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.inject.annotations.ConfigFile; import com.plotsquared.core.inject.annotations.WorldFile; @@ -47,7 +46,6 @@ import java.io.IOException; import java.lang.management.ManagementFactory; import java.lang.management.RuntimeMXBean; import java.nio.file.Files; -import java.util.Collection; import java.util.concurrent.TimeUnit; @CommandDeclaration(command = "debugpaste", From 58378dd90046335df1014b81108b3104a74b065f Mon Sep 17 00:00:00 2001 From: xaver106 Date: Thu, 2 Jun 2022 12:32:17 +0200 Subject: [PATCH 3/7] refactor: replace try with if statements --- .../com/plotsquared/core/command/DebugPaste.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Core/src/main/java/com/plotsquared/core/command/DebugPaste.java b/Core/src/main/java/com/plotsquared/core/command/DebugPaste.java index c3d345465..60b78042a 100644 --- a/Core/src/main/java/com/plotsquared/core/command/DebugPaste.java +++ b/Core/src/main/java/com/plotsquared/core/command/DebugPaste.java @@ -178,6 +178,20 @@ public class DebugPaste extends SubCommand { "lang" ); + if (langDir.exists()) { + File[] fileList = langDir.listFiles(); + if (fileList != null) { + for (File current : fileList) { + if (current == null || current.exists()) { + continue; + } + if (current.getName().startsWith("messages_") && current.getName().endsWith(".json")) { + incendoPaster.addFile(current); + } + } + } + } + try { for (File current : langDir.listFiles()) { try { From fe37fe3c10a65944e4d3d07066634053ae88faac Mon Sep 17 00:00:00 2001 From: xaver106 Date: Thu, 2 Jun 2022 12:33:24 +0200 Subject: [PATCH 4/7] refactor: remove old code --- .../com/plotsquared/core/command/DebugPaste.java | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/Core/src/main/java/com/plotsquared/core/command/DebugPaste.java b/Core/src/main/java/com/plotsquared/core/command/DebugPaste.java index 60b78042a..a9df4c5cf 100644 --- a/Core/src/main/java/com/plotsquared/core/command/DebugPaste.java +++ b/Core/src/main/java/com/plotsquared/core/command/DebugPaste.java @@ -192,19 +192,6 @@ public class DebugPaste extends SubCommand { } } - try { - for (File current : langDir.listFiles()) { - try { - if (current.getName().startsWith("messages_") && current.getName().endsWith(".json")) { - incendoPaster.addFile(current); - } - } catch (NullPointerException ignored) { - } - } - } catch (NullPointerException ignored) { - //No lang files found - } - try { final String rawResponse = incendoPaster.upload(); final JsonObject jsonObject = From 0eef7220a6394d5259c2b60fb6c7df762ed76560 Mon Sep 17 00:00:00 2001 From: xaver106 Date: Thu, 2 Jun 2022 23:58:37 +0200 Subject: [PATCH 5/7] refactor: implement `Path` and `Files` --- .../plotsquared/core/command/DebugPaste.java | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/Core/src/main/java/com/plotsquared/core/command/DebugPaste.java b/Core/src/main/java/com/plotsquared/core/command/DebugPaste.java index a9df4c5cf..65a20a5fa 100644 --- a/Core/src/main/java/com/plotsquared/core/command/DebugPaste.java +++ b/Core/src/main/java/com/plotsquared/core/command/DebugPaste.java @@ -32,6 +32,7 @@ import com.intellectualsites.paster.IncendoPaster; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.configuration.Storage; +import com.plotsquared.core.configuration.caption.StaticCaption; import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.inject.annotations.ConfigFile; import com.plotsquared.core.inject.annotations.WorldFile; @@ -46,7 +47,10 @@ import java.io.IOException; import java.lang.management.ManagementFactory; import java.lang.management.RuntimeMXBean; import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; import java.util.concurrent.TimeUnit; +import java.util.stream.Stream; @CommandDeclaration(command = "debugpaste", aliases = "dp", @@ -76,9 +80,9 @@ public class DebugPaste extends SubCommand { StringBuilder b = new StringBuilder(); b.append( """ - # Welcome to this paste - # It is meant to provide us at IntellectualSites with better information about your problem - """ + # Welcome to this paste + # It is meant to provide us at IntellectualSites with better information about your problem + """ ); b.append("# PlotSquared Information\n"); b.append("PlotSquared Version: ").append(PlotSquared.get().getVersion()) @@ -173,22 +177,18 @@ public class DebugPaste extends SubCommand { ); } - final File langDir = new File( - PlotSquared.platform().getDirectory(), - "lang" - ); - - if (langDir.exists()) { - File[] fileList = langDir.listFiles(); - if (fileList != null) { - for (File current : fileList) { - if (current == null || current.exists()) { - continue; - } - if (current.getName().startsWith("messages_") && current.getName().endsWith(".json")) { - incendoPaster.addFile(current); - } - } + final Path langDir = PlotSquared.platform().getDirectory().toPath().resolve("lang"); + if (Files.isDirectory(langDir)) { + try (Stream files = Files.list(langDir)) { + files.filter(Files::isRegularFile) + .filter(path -> path.getFileName().toString().startsWith("messages_") && + path.getFileName().toString().endsWith(".json") + ).forEach(path -> { + try { + incendoPaster.addFile(path.toFile()); + } catch (IOException ignored) { + } + }); } } From 3fed8ba970cea2e2a4524fdcd121246ac74f5e35 Mon Sep 17 00:00:00 2001 From: xaver106 Date: Fri, 3 Jun 2022 00:01:20 +0200 Subject: [PATCH 6/7] refactor: import cleanup --- Core/src/main/java/com/plotsquared/core/command/DebugPaste.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/Core/src/main/java/com/plotsquared/core/command/DebugPaste.java b/Core/src/main/java/com/plotsquared/core/command/DebugPaste.java index 65a20a5fa..77ba73772 100644 --- a/Core/src/main/java/com/plotsquared/core/command/DebugPaste.java +++ b/Core/src/main/java/com/plotsquared/core/command/DebugPaste.java @@ -32,7 +32,6 @@ import com.intellectualsites.paster.IncendoPaster; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.configuration.Storage; -import com.plotsquared.core.configuration.caption.StaticCaption; import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.inject.annotations.ConfigFile; import com.plotsquared.core.inject.annotations.WorldFile; @@ -48,7 +47,6 @@ import java.lang.management.ManagementFactory; import java.lang.management.RuntimeMXBean; import java.nio.file.Files; import java.nio.file.Path; -import java.util.ArrayList; import java.util.concurrent.TimeUnit; import java.util.stream.Stream; From 6f857c917ad24dfe66aaf71f3d9cf3429bcbce9f Mon Sep 17 00:00:00 2001 From: xaver106 Date: Fri, 3 Jun 2022 15:48:33 +0200 Subject: [PATCH 7/7] refactor: undo unnecessary changes --- .../main/java/com/plotsquared/core/command/DebugPaste.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Core/src/main/java/com/plotsquared/core/command/DebugPaste.java b/Core/src/main/java/com/plotsquared/core/command/DebugPaste.java index 77ba73772..338b02e32 100644 --- a/Core/src/main/java/com/plotsquared/core/command/DebugPaste.java +++ b/Core/src/main/java/com/plotsquared/core/command/DebugPaste.java @@ -78,9 +78,9 @@ public class DebugPaste extends SubCommand { StringBuilder b = new StringBuilder(); b.append( """ - # Welcome to this paste - # It is meant to provide us at IntellectualSites with better information about your problem - """ + # Welcome to this paste + # It is meant to provide us at IntellectualSites with better information about your problem + """ ); b.append("# PlotSquared Information\n"); b.append("PlotSquared Version: ").append(PlotSquared.get().getVersion())