From 631609af74c0c9adb84c19536a50091dd5fc8742 Mon Sep 17 00:00:00 2001 From: Andre601 <11576465+Andre601@users.noreply.github.com> Date: Sat, 5 Feb 2022 14:08:43 +0100 Subject: [PATCH 1/3] Improve expansion sorting in /papi dump --- .../commands/impl/local/CommandDump.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandDump.java b/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandDump.java index c647e71..2b0d6f7 100644 --- a/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandDump.java +++ b/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandDump.java @@ -106,7 +106,6 @@ public final class CommandDump extends PlaceholderCommand { } try (final InputStream stream = connection.getInputStream()) { - //noinspection UnstableApiUsage final String json = CharStreams.toString(new InputStreamReader(stream, StandardCharsets.UTF_8)); return gson.fromJson(json, JsonObject.class).get("key").getAsString(); } @@ -134,8 +133,10 @@ public final class CommandDump extends PlaceholderCommand { final List expansions = plugin.getLocalExpansionManager() .getExpansions() .stream() - .sorted(Comparator.comparing(PlaceholderExpansion::getIdentifier)) - .sorted(Comparator.comparing(PlaceholderExpansion::getAuthor)) + .sorted( + Comparator.comparing(PlaceholderExpansion::getIdentifier) + .thenComparing(PlaceholderExpansion::getAuthor) + ) .collect(Collectors.toList()); int size = 0; @@ -167,10 +168,15 @@ public final class CommandDump extends PlaceholderCommand { .getExpansionsFolder() .list((dir, name) -> name.toLowerCase().endsWith(".jar")); - for (final String jar : jars) { - builder.append(" ") - .append(jar) - .append('\n'); + + if (jars == null) { + builder.append(" WARN: Jars array was empty!"); + } else { + for (final String jar : jars) { + builder.append(" ") + .append(jar) + .append('\n'); + } } builder.append('\n'); From 0e0e36476a067b6a127457611b5f34d92dc29591 Mon Sep 17 00:00:00 2001 From: Andre601 <11576465+Andre601@users.noreply.github.com> Date: Fri, 29 Apr 2022 23:13:19 +0200 Subject: [PATCH 2/3] Change appended message for null jar array --- .../me/clip/placeholderapi/commands/impl/local/CommandDump.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandDump.java b/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandDump.java index 2b0d6f7..3f633b2 100644 --- a/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandDump.java +++ b/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandDump.java @@ -170,7 +170,7 @@ public final class CommandDump extends PlaceholderCommand { if (jars == null) { - builder.append(" WARN: Jars array was empty!"); + builder.append(" ยจ[Warning]: Could not load jar files from expansions folder."); } else { for (final String jar : jars) { builder.append(" ") From 0be6b721cf688f7a1f46089fdc7f070dcf1ac85a Mon Sep 17 00:00:00 2001 From: Andre601 <11576465+Andre601@users.noreply.github.com> Date: Wed, 4 May 2022 18:36:46 +0200 Subject: [PATCH 3/3] Use stream to get size padding --- .../commands/impl/local/CommandDump.java | 22 ++++++------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandDump.java b/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandDump.java index 3f633b2..7976943 100644 --- a/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandDump.java +++ b/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandDump.java @@ -139,14 +139,9 @@ public final class CommandDump extends PlaceholderCommand { ) .collect(Collectors.toList()); - int size = 0; - - for (final String name : expansions.stream().map(PlaceholderExpansion::getIdentifier) - .collect(Collectors.toList())) { - if (name.length() > size) { - size = name.length(); - } - } + int size = expansions.stream().map(e -> e.getIdentifier().length()) + .max(Integer::compareTo) + .orElse(0); for (final PlaceholderExpansion expansion : expansions) { builder.append(" ") @@ -197,13 +192,10 @@ public final class CommandDump extends PlaceholderCommand { List plugins = Arrays.stream(plugin.getServer().getPluginManager().getPlugins()) .sorted(Comparator.comparing(Plugin::getName)) .collect(Collectors.toList()); - - for (final String pluginName : plugins.stream().map(Plugin::getName) - .collect(Collectors.toList())) { - if (pluginName.length() > size) { - size = pluginName.length(); - } - } + + size = plugins.stream().map(pl -> pl.getName().length()) + .max(Integer::compareTo) + .orElse(0); for (final Plugin other : plugins) { builder.append(" ")