9
0
mirror of https://github.com/WiIIiam278/HuskSync.git synced 2025-12-25 17:49:20 +00:00

Use Commodore for rich command completion registering

This commit is contained in:
William
2022-08-08 19:32:09 +01:00
parent d1c95030f0
commit 2f700b2d93
18 changed files with 125 additions and 31 deletions

View File

@@ -10,6 +10,7 @@ import net.william278.husksync.migrator.Migrator;
import net.william278.husksync.player.OnlineUser;
import net.william278.husksync.redis.RedisManager;
import net.william278.husksync.util.Logger;
import net.william278.husksync.util.ResourceReader;
import net.william278.husksync.util.Version;
import org.jetbrains.annotations.NotNull;
@@ -114,6 +115,14 @@ public interface HuskSync {
@NotNull
Logger getLoggingAdapter();
/**
* Returns the plugin resource file reader
*
* @return the {@link ResourceReader}
*/
@NotNull
ResourceReader getResourceReader();
/**
* Returns the plugin version
*

View File

@@ -9,6 +9,7 @@ import net.william278.husksync.util.UpdateChecker;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.logging.Level;
@@ -126,9 +127,12 @@ public class HuskSyncCommand extends CommandBase implements TabCompletable, Cons
@Override
public List<String> onTabComplete(@NotNull String[] args) {
return Arrays.stream(COMMAND_ARGUMENTS)
.filter(argument -> argument.startsWith(args.length >= 1 ? args[0] : ""))
.sorted().collect(Collectors.toList());
if (args.length <= 1) {
return Arrays.stream(COMMAND_ARGUMENTS)
.filter(argument -> argument.startsWith(args.length >= 1 ? args[0] : ""))
.sorted().collect(Collectors.toList());
}
return Collections.emptyList();
}
private void displayPluginInformation(@NotNull OnlineUser player) {

View File

@@ -225,7 +225,7 @@ public class UserDataCommand extends CommandBase implements TabCompletable {
switch (args.length) {
case 0, 1 -> {
return Arrays.stream(COMMAND_ARGUMENTS)
.filter(argument -> argument.startsWith(args.length >= 1 ? args[0] : ""))
.filter(argument -> argument.startsWith(args.length == 1 ? args[0] : ""))
.sorted().collect(Collectors.toList());
}
case 2 -> {

View File

@@ -14,6 +14,7 @@ import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@@ -108,7 +109,7 @@ public abstract class Database {
*/
@SuppressWarnings("SameParameterValue")
protected final String[] getSchemaStatements(@NotNull String schemaFileName) throws IOException {
return formatStatementTables(new String(resourceReader.getResource(schemaFileName)
return formatStatementTables(new String(Objects.requireNonNull(resourceReader.getResource(schemaFileName))
.readAllBytes(), StandardCharsets.UTF_8)).split(";");
}

View File

@@ -1,8 +1,7 @@
package net.william278.husksync.util;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.io.InputStream;
/**
@@ -14,15 +13,8 @@ public interface ResourceReader {
* Gets the resource with given filename and reads it as an {@link InputStream}
*
* @param fileName Name of the resource file to read
* @return The resource, read as an {@link InputStream}
* @return The resource, read as an {@link InputStream}; or {@code null} if the resource was not found
*/
@NotNull InputStream getResource(String fileName);
/**
* Gets the plugin data folder where plugin configuration and data are kept
*
* @return the plugin data directory
*/
@NotNull File getDataFolder();
@Nullable InputStream getResource(String fileName);
}