Added auto suggestion in the reload command

This commit is contained in:
themode 2020-11-06 23:35:31 +01:00
parent 69f424eb6a
commit 8c8ba37947
2 changed files with 50 additions and 29 deletions

View File

@ -8,14 +8,29 @@ import net.minestom.server.command.builder.arguments.Argument;
import net.minestom.server.command.builder.arguments.ArgumentType;
import net.minestom.server.extensions.Extension;
import net.minestom.server.extensions.ExtensionManager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.stream.Collectors;
public class ReloadExtensionCommand extends Command {
// the extensions name as an array
private static String[] extensionsName;
static {
List<String> extensionsName = MinecraftServer.getExtensionManager().getExtensions()
.stream()
.map(extension -> extension.getDescription().getName())
.collect(Collectors.toList());
ReloadExtensionCommand.extensionsName = extensionsName.toArray(new String[0]);
}
public ReloadExtensionCommand() {
super("reload");
@ -63,6 +78,12 @@ public class ReloadExtensionCommand extends Command {
sender.sendMessage("'" + extension + "' is not a valid extension name!");
}
@Nullable
@Override
public String[] onDynamicWrite(@NotNull String text) {
return extensionsName;
}
private String join(String[] extensionNameParts) {
StringBuilder b = new StringBuilder();
for (int i = 0; i < extensionNameParts.length; i++) {