mirror of
https://github.com/PlaceholderAPI/PlaceholderAPI
synced 2024-11-18 00:46:55 +01:00
Improve dump command (#412)
This commit is contained in:
parent
9412fed9ad
commit
e43b7bf205
@ -42,9 +42,10 @@ import java.time.Instant;
|
|||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.time.format.FormatStyle;
|
import java.time.format.FormatStyle;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.CompletionException;
|
import java.util.concurrent.CompletionException;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@ -58,8 +59,8 @@ public final class CommandDump extends PlaceholderCommand
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG)
|
private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG)
|
||||||
.withLocale(Locale.US)
|
.withLocale(Locale.US)
|
||||||
.withZone(ZoneId.of("UTC"));
|
.withZone(ZoneId.of("UTC"));
|
||||||
|
|
||||||
|
|
||||||
public CommandDump()
|
public CommandDump()
|
||||||
@ -123,77 +124,90 @@ public final class CommandDump extends PlaceholderCommand
|
|||||||
final StringBuilder builder = new StringBuilder();
|
final StringBuilder builder = new StringBuilder();
|
||||||
|
|
||||||
builder.append("Generated: ")
|
builder.append("Generated: ")
|
||||||
.append(DATE_FORMAT.format(Instant.now()))
|
.append(DATE_FORMAT.format(Instant.now()))
|
||||||
.append("\n\n");
|
.append("\n\n");
|
||||||
|
|
||||||
builder.append("PlaceholderAPI: ")
|
builder.append("PlaceholderAPI: ")
|
||||||
.append(plugin.getDescription().getVersion())
|
.append(plugin.getDescription().getVersion())
|
||||||
.append("\n\n");
|
.append("\n\n");
|
||||||
|
|
||||||
builder.append("Expansions Registered:")
|
builder.append("Expansions Registered:")
|
||||||
.append('\n');
|
.append('\n');
|
||||||
|
|
||||||
|
final List<PlaceholderExpansion> expansions = plugin.getLocalExpansionManager()
|
||||||
|
.getExpansions()
|
||||||
|
.stream()
|
||||||
|
.sorted(Comparator.comparing(PlaceholderExpansion::getIdentifier))
|
||||||
|
.sorted(Comparator.comparing(PlaceholderExpansion::getAuthor))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
final Map<String, List<PlaceholderExpansion>> expansions = plugin.getLocalExpansionManager()
|
int size = 0;
|
||||||
.getExpansions()
|
|
||||||
.stream()
|
|
||||||
.collect(Collectors.groupingBy(PlaceholderExpansion::getAuthor));
|
|
||||||
|
|
||||||
for (final Map.Entry<String, List<PlaceholderExpansion>> expansionsByAuthor : expansions.entrySet())
|
for(final String name : expansions.stream().map(PlaceholderExpansion::getIdentifier).collect(Collectors.toList())){
|
||||||
{
|
if (name.length() > size) {
|
||||||
builder.append(" ")
|
size = name.length();
|
||||||
.append(expansionsByAuthor.getKey())
|
|
||||||
.append(": ")
|
|
||||||
.append('\n');
|
|
||||||
|
|
||||||
for (final PlaceholderExpansion expansion : expansionsByAuthor.getValue())
|
|
||||||
{
|
|
||||||
builder.append(" ")
|
|
||||||
.append(expansion.getName())
|
|
||||||
.append(':')
|
|
||||||
.append(expansion.getVersion())
|
|
||||||
.append('\n');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (final PlaceholderExpansion expansion : expansions) {
|
||||||
|
builder.append(" ")
|
||||||
|
.append(String.format("%-" + size + "s", expansion.getIdentifier()))
|
||||||
|
.append(" [Author: ")
|
||||||
|
.append(expansion.getAuthor())
|
||||||
|
.append(", Version: ")
|
||||||
|
.append(expansion.getVersion())
|
||||||
|
.append("]\n");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
builder.append('\n');
|
builder.append('\n');
|
||||||
|
|
||||||
builder.append("Expansions Directory:")
|
builder.append("Expansions Directory:")
|
||||||
.append('\n');
|
.append('\n');
|
||||||
|
|
||||||
final String[] jars = plugin.getLocalExpansionManager()
|
final String[] jars = plugin.getLocalExpansionManager()
|
||||||
.getExpansionsFolder()
|
.getExpansionsFolder()
|
||||||
.list((dir, name) -> name.toLowerCase().endsWith(".jar"));
|
.list((dir, name) -> name.toLowerCase().endsWith(".jar"));
|
||||||
|
|
||||||
for (final String jar : jars)
|
for (final String jar : jars)
|
||||||
{
|
{
|
||||||
builder.append(" ")
|
builder.append(" ")
|
||||||
.append(jar)
|
.append(jar)
|
||||||
.append('\n');
|
.append('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.append('\n');
|
builder.append('\n');
|
||||||
|
|
||||||
|
|
||||||
builder.append("Server Info: ")
|
builder.append("Server Info: ")
|
||||||
.append(plugin.getServer().getBukkitVersion())
|
.append(plugin.getServer().getBukkitVersion())
|
||||||
.append('/')
|
.append('/')
|
||||||
.append(plugin.getServer().getVersion())
|
.append(plugin.getServer().getVersion())
|
||||||
.append("\n\n");
|
.append("\n\n");
|
||||||
|
|
||||||
builder.append("Plugin Info:")
|
builder.append("Plugin Info:")
|
||||||
.append('\n');
|
.append('\n');
|
||||||
|
|
||||||
for (final Plugin other : plugin.getServer().getPluginManager().getPlugins())
|
List<Plugin> 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (final Plugin other : plugins)
|
||||||
{
|
{
|
||||||
builder.append(" ")
|
builder.append(" ")
|
||||||
.append(other.getName())
|
.append(String.format("%-" + size + "s", other.getName()))
|
||||||
.append(": ")
|
.append(" [Version: ")
|
||||||
.append(other.getDescription().getVersion())
|
.append(other.getDescription().getVersion())
|
||||||
.append('\n');
|
.append("]")
|
||||||
|
.append("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user