From 33871124a32cb73c470a205a6e86d356a44177a7 Mon Sep 17 00:00:00 2001 From: Illusion Date: Mon, 4 Sep 2023 16:04:15 +0100 Subject: [PATCH] javadoc go brr --- .../command/BungeeCommandSenderAudience.java | 3 + .../command/BungeeSkyblockCommandManager.java | 3 + .../command/BungeeSkyblockPlayerAudience.java | 3 + .../command/audience/SkyblockAudience.java | 17 ++++++ .../audience/SkyblockConsoleAudience.java | 3 + .../command/context/CommandArgument.java | 21 ++++++- .../command/context/CommandContext.java | 24 ++++++++ .../command/context/arg/LiteralArgument.java | 3 + .../context/arg/ProxiedDefaultArgument.java | 3 + .../context/impl/MutatingCommandContext.java | 4 ++ .../common/command/data/SkyblockCommand.java | 21 +++++++ .../command/data/SkyblockCommandBuilder.java | 30 ++++++++++ .../command/data/SkyblockCommandHandler.java | 5 ++ .../data/builder/SimpleSkyblockCommand.java | 5 ++ .../builder/SimpleSkyblockCommandBuilder.java | 5 ++ .../AbstractSkyblockCommandManager.java | 3 + .../manager/SkyblockCommandManager.java | 13 +++++ .../command/node/AbstractCommandNode.java | 3 + .../command/node/ArgumentCommandNode.java | 5 +- .../common/command/node/CommandNode.java | 42 ++++++++++++++ .../common/command/structure/CommandTree.java | 56 +++++++++++++++++-- .../common/config/SkyblockMessagesFile.java | 14 +++++ .../impl/AbstractDatabaseConfiguration.java | 6 ++ .../cache/redis/MemorySkyblockCache.java | 3 + .../sql/AbstractRemoteSQLDatabase.java | 3 + .../audience/SkyblockProxyPlayerAudience.java | 12 ++++ .../proxy/command/PlaySkyblockCommand.java | 4 ++ .../SkyblockBukkitConsoleAudience.java | 3 + 28 files changed, 311 insertions(+), 6 deletions(-) diff --git a/SkyblockCore-BungeeCord/src/main/java/me/illusion/skyblockcore/bungee/command/BungeeCommandSenderAudience.java b/SkyblockCore-BungeeCord/src/main/java/me/illusion/skyblockcore/bungee/command/BungeeCommandSenderAudience.java index deaf726..c44c94e 100644 --- a/SkyblockCore-BungeeCord/src/main/java/me/illusion/skyblockcore/bungee/command/BungeeCommandSenderAudience.java +++ b/SkyblockCore-BungeeCord/src/main/java/me/illusion/skyblockcore/bungee/command/BungeeCommandSenderAudience.java @@ -3,6 +3,9 @@ import me.illusion.skyblockcore.common.command.audience.SkyblockAudience; import net.md_5.bungee.api.CommandSender; +/** + * Represents a SkyblockAudience for any generic BungeeCord CommandSender + */ public class BungeeCommandSenderAudience implements SkyblockAudience { private final CommandSender sender; diff --git a/SkyblockCore-BungeeCord/src/main/java/me/illusion/skyblockcore/bungee/command/BungeeSkyblockCommandManager.java b/SkyblockCore-BungeeCord/src/main/java/me/illusion/skyblockcore/bungee/command/BungeeSkyblockCommandManager.java index 03dd890..d2d276a 100644 --- a/SkyblockCore-BungeeCord/src/main/java/me/illusion/skyblockcore/bungee/command/BungeeSkyblockCommandManager.java +++ b/SkyblockCore-BungeeCord/src/main/java/me/illusion/skyblockcore/bungee/command/BungeeSkyblockCommandManager.java @@ -9,6 +9,9 @@ import net.md_5.bungee.api.plugin.Command; import net.md_5.bungee.api.plugin.TabExecutor; +/** + * Represents a BungeeCord implementation of a SkyblockCommandManager. + */ public class BungeeSkyblockCommandManager extends AbstractSkyblockCommandManager { private final SkyblockBungeePlugin platform; diff --git a/SkyblockCore-BungeeCord/src/main/java/me/illusion/skyblockcore/bungee/command/BungeeSkyblockPlayerAudience.java b/SkyblockCore-BungeeCord/src/main/java/me/illusion/skyblockcore/bungee/command/BungeeSkyblockPlayerAudience.java index 3475c37..bd12711 100644 --- a/SkyblockCore-BungeeCord/src/main/java/me/illusion/skyblockcore/bungee/command/BungeeSkyblockPlayerAudience.java +++ b/SkyblockCore-BungeeCord/src/main/java/me/illusion/skyblockcore/bungee/command/BungeeSkyblockPlayerAudience.java @@ -5,6 +5,9 @@ import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.connection.ProxiedPlayer; +/** + * Represents a SkyblockAudience for any BungeeCord ProxiedPlayer + */ public class BungeeSkyblockPlayerAudience implements SkyblockProxyPlayerAudience { private final UUID playerId; diff --git a/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/audience/SkyblockAudience.java b/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/audience/SkyblockAudience.java index 335a4b2..afbc6be 100644 --- a/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/audience/SkyblockAudience.java +++ b/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/audience/SkyblockAudience.java @@ -1,11 +1,28 @@ package me.illusion.skyblockcore.common.command.audience; +/** + * Represents a generic Audience-like class, similar to Bukkit's CommandSender + */ public interface SkyblockAudience { + /** + * Sends a raw message to the audience. + * + * @param message The message to send. + */ void sendMessage(String message); + /** + * Checks if the audience has a permission. + * @param permission The permission to check. + * @return Whether or not the audience has the permission. + */ boolean hasPermission(String permission); + /** + * Checks if the audience is a console. + * @return Whether or not the audience is a console. + */ boolean isConsole(); } diff --git a/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/audience/SkyblockConsoleAudience.java b/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/audience/SkyblockConsoleAudience.java index 6e2d90b..8023f91 100644 --- a/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/audience/SkyblockConsoleAudience.java +++ b/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/audience/SkyblockConsoleAudience.java @@ -1,5 +1,8 @@ package me.illusion.skyblockcore.common.command.audience; +/** + * Represents a console audience. This allows us to filter console-only commands. + */ public abstract class SkyblockConsoleAudience implements SkyblockAudience { @Override diff --git a/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/context/CommandArgument.java b/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/context/CommandArgument.java index 1c0184d..783c362 100644 --- a/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/context/CommandArgument.java +++ b/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/context/CommandArgument.java @@ -1,16 +1,35 @@ package me.illusion.skyblockcore.common.command.context; +import java.util.Collections; import java.util.List; import me.illusion.skyblockcore.common.command.context.arg.ProxiedDefaultArgument; +/** + * Represents a command argument. This will then be parsed by the command context. + */ public interface CommandArgument { + /** + * Gets the name of this argument. This is used to retrieve the argument from the command context. + * + * @return The name of this argument. + */ String getName(); + /** + * Parses the argument from the command context into an object. + * @param context The command context. + * @return The parsed object. + */ Object parse(CommandContext context); + /** + * Gets the tab completion for this argument. + * @param context The command context. + * @return The tab completion. + */ default List tabComplete(CommandContext context) { - return null; + return Collections.emptyList(); } default CommandArgument orDefault(Object defaultValue) { diff --git a/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/context/CommandContext.java b/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/context/CommandContext.java index 09c3cbe..c46db35 100644 --- a/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/context/CommandContext.java +++ b/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/context/CommandContext.java @@ -1,12 +1,36 @@ package me.illusion.skyblockcore.common.command.context; +/** + * Represents a command context. This allows for the retrieval of arguments and is passed for tab completion and command execution. + */ public interface CommandContext { + /** + * Gets an argument by name + * + * @param name The name of the argument. + * @param The type of the argument. + * @return The parsed argument. + */ T getArgument(String name); // I know it's an unsafe cast, but Cloud commands do it too, so I'm not going to bother. + /** + * Gets an argument by index. Starts at 0. + * @param index The index of the argument. + * @return The parsed argument. + * @param The type of the argument. + */ T getArgument(int index); + /** + * Gets the full input of the command. This is the full command, not just the arguments, without a / + * @return The full input. + */ String getFullInput(); + /** + * Gets the last input of the command. This is the last word that was parsed by the last argument. + * @return The last input. + */ String getLastInput(); } diff --git a/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/context/arg/LiteralArgument.java b/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/context/arg/LiteralArgument.java index 4c7b1e6..ba7409c 100644 --- a/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/context/arg/LiteralArgument.java +++ b/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/context/arg/LiteralArgument.java @@ -5,6 +5,9 @@ import me.illusion.skyblockcore.common.command.context.CommandArgument; import me.illusion.skyblockcore.common.command.context.CommandContext; +/** + * Represents a "literal" argument, which matches the input exactly. + */ public class LiteralArgument implements CommandArgument { private final String name; diff --git a/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/context/arg/ProxiedDefaultArgument.java b/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/context/arg/ProxiedDefaultArgument.java index 5cc3f43..841faf0 100644 --- a/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/context/arg/ProxiedDefaultArgument.java +++ b/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/context/arg/ProxiedDefaultArgument.java @@ -3,6 +3,9 @@ import me.illusion.skyblockcore.common.command.context.CommandArgument; import me.illusion.skyblockcore.common.command.context.CommandContext; +/** + * Represents a command argument with a default value. + */ public class ProxiedDefaultArgument implements CommandArgument { private final CommandArgument argument; diff --git a/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/context/impl/MutatingCommandContext.java b/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/context/impl/MutatingCommandContext.java index 5261162..a4afe25 100644 --- a/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/context/impl/MutatingCommandContext.java +++ b/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/context/impl/MutatingCommandContext.java @@ -5,6 +5,10 @@ import me.illusion.skyblockcore.common.command.context.CommandArgument; import me.illusion.skyblockcore.common.command.context.CommandContext; +/** + * Represents a mutable command context. The mutable part is important when handling tab completion, as we slowly build up the arguments and can use the + * arguments for further completion. + */ public class MutatingCommandContext implements CommandContext { private final String fullInput; diff --git a/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/data/SkyblockCommand.java b/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/data/SkyblockCommand.java index cfc78a0..97ae4df 100644 --- a/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/data/SkyblockCommand.java +++ b/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/data/SkyblockCommand.java @@ -4,14 +4,35 @@ import me.illusion.skyblockcore.common.command.audience.SkyblockAudience; import me.illusion.skyblockcore.common.command.context.CommandArgument; +/** + * Represents an instance of a Skyblock command. + * + * @param The type of audience this command will be used for. SkyblockAudience is the default. + */ public interface SkyblockCommand { + /** + * Gets all the arguments for this command. + * @return The arguments. + */ List getArguments(); + /** + * Gets the handler for this command. + * @return The handler. + */ SkyblockCommandHandler getHandler(); + /** + * Gets the target audience for this command. + * @return The target audience. + */ Class getAudience(); + /** + * Gets the permission for this command. + * @return The permission. + */ String getPermission(); } diff --git a/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/data/SkyblockCommandBuilder.java b/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/data/SkyblockCommandBuilder.java index 6c3e1a6..af3bc13 100644 --- a/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/data/SkyblockCommandBuilder.java +++ b/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/data/SkyblockCommandBuilder.java @@ -3,16 +3,46 @@ import me.illusion.skyblockcore.common.command.audience.SkyblockAudience; import me.illusion.skyblockcore.common.command.context.CommandArgument; +/** + * Represents a command builder. This is used to build commands. + * + * @param The type of audience this command will be used for. SkyblockAudience is the default. + */ public interface SkyblockCommandBuilder { + /** + * Registers an argument to the command. + * @param argument The argument to register. + * @return The command builder. + */ SkyblockCommandBuilder registerArgument(CommandArgument argument); + /** + * Sets the handler for the command. + * @param handler The handler to set. + * @return The command builder. + */ SkyblockCommandBuilder handler(SkyblockCommandHandler handler); + /** + * Sets the permission for the command. + * @param permission The permission to set. + * @return The command builder. + */ SkyblockCommandBuilder permission(String permission); + /** + * Sets the new target audience for the command. + * @param audience The audience to set. + * @return A new command builder of the new audience type. + * @param The type of audience this command will be used for. + */ SkyblockCommandBuilder audience(Class audience); + /** + * Builds and registers the command. + * @return The built command. + */ SkyblockCommand build(); } diff --git a/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/data/SkyblockCommandHandler.java b/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/data/SkyblockCommandHandler.java index 2f1638c..6f2e5c2 100644 --- a/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/data/SkyblockCommandHandler.java +++ b/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/data/SkyblockCommandHandler.java @@ -3,6 +3,11 @@ import me.illusion.skyblockcore.common.command.audience.SkyblockAudience; import me.illusion.skyblockcore.common.command.context.CommandContext; +/** + * Represents a command handler. This is the lambda that is called when a command is executed. + * + * @param The type of audience this command handler will be used for. SkyblockAudience is the default. + */ public interface SkyblockCommandHandler { void handle(T audience, CommandContext context); diff --git a/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/data/builder/SimpleSkyblockCommand.java b/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/data/builder/SimpleSkyblockCommand.java index 0bc093e..4c8bc98 100644 --- a/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/data/builder/SimpleSkyblockCommand.java +++ b/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/data/builder/SimpleSkyblockCommand.java @@ -6,6 +6,11 @@ import me.illusion.skyblockcore.common.command.data.SkyblockCommand; import me.illusion.skyblockcore.common.command.data.SkyblockCommandHandler; +/** + * Represents a simple implementation of a SkyblockCommand. + * + * @param The audience type. + */ public class SimpleSkyblockCommand implements SkyblockCommand { private final List arguments; diff --git a/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/data/builder/SimpleSkyblockCommandBuilder.java b/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/data/builder/SimpleSkyblockCommandBuilder.java index 2496032..e145773 100644 --- a/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/data/builder/SimpleSkyblockCommandBuilder.java +++ b/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/data/builder/SimpleSkyblockCommandBuilder.java @@ -10,6 +10,11 @@ import me.illusion.skyblockcore.common.command.data.SkyblockCommandHandler; import me.illusion.skyblockcore.common.command.manager.AbstractSkyblockCommandManager; +/** + * Represents a simple implementation of a SkyblockCommandBuilder. + * + * @param The audience type. + */ public class SimpleSkyblockCommandBuilder implements SkyblockCommandBuilder { private final List arguments; diff --git a/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/manager/AbstractSkyblockCommandManager.java b/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/manager/AbstractSkyblockCommandManager.java index 4964a45..3a3a091 100644 --- a/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/manager/AbstractSkyblockCommandManager.java +++ b/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/manager/AbstractSkyblockCommandManager.java @@ -12,6 +12,9 @@ import me.illusion.skyblockcore.common.command.structure.CommandTree.TargetResult; import me.illusion.skyblockcore.common.platform.SkyblockPlatform; +/** + * Represents an abstract implementation of a SkyblockCommandManager. This implementation provides the command tree logic, and the command handling logic. + */ public abstract class AbstractSkyblockCommandManager implements SkyblockCommandManager { private final CommandTree commandTree = new CommandTree(this); diff --git a/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/manager/SkyblockCommandManager.java b/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/manager/SkyblockCommandManager.java index 6c88aa3..7045d7b 100644 --- a/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/manager/SkyblockCommandManager.java +++ b/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/manager/SkyblockCommandManager.java @@ -3,10 +3,23 @@ import me.illusion.skyblockcore.common.command.audience.SkyblockAudience; import me.illusion.skyblockcore.common.command.data.SkyblockCommandBuilder; +/** + * Represents the proprietary command manager for SkyblockCore. This is used to register commands across all platforms. + * + * @param The type of audience this command manager will be used for. SkyblockAudience is the default. + */ public interface SkyblockCommandManager { + /** + * Creates a new command builder. + * @param name The name of the command. This is the first word after the slash. + * @return The command builder. + */ SkyblockCommandBuilder newCommand(String name); + /** + * Syncs all commands to the platform. Some platforms need this in order for commands to work after the server is running. + */ void syncCommands(); diff --git a/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/node/AbstractCommandNode.java b/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/node/AbstractCommandNode.java index 063f1ff..62431af 100644 --- a/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/node/AbstractCommandNode.java +++ b/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/node/AbstractCommandNode.java @@ -3,6 +3,9 @@ import java.util.ArrayList; import java.util.List; +/** + * Represents a command node. This is used to build the command tree. This abstract implementation provides the parent-child logic. + */ public abstract class AbstractCommandNode implements CommandNode { private final List children = new ArrayList<>(); diff --git a/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/node/ArgumentCommandNode.java b/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/node/ArgumentCommandNode.java index 6a4083f..959937f 100644 --- a/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/node/ArgumentCommandNode.java +++ b/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/node/ArgumentCommandNode.java @@ -5,9 +5,12 @@ import me.illusion.skyblockcore.common.command.context.CommandArgument; import me.illusion.skyblockcore.common.command.data.SkyblockCommand; +/** + * Represents a command node version of a CommandArgument. + */ +@Getter public class ArgumentCommandNode extends AbstractCommandNode { - @Getter private final SkyblockCommand command; private final CommandArgument argument; diff --git a/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/node/CommandNode.java b/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/node/CommandNode.java index bceaf6f..604e9a4 100644 --- a/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/node/CommandNode.java +++ b/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/node/CommandNode.java @@ -6,26 +6,68 @@ import me.illusion.skyblockcore.common.command.context.CommandArgument; import me.illusion.skyblockcore.common.command.context.arg.LiteralArgument; +/** + * Represents a command node. This is used to build the command tree. + */ public interface CommandNode { + /** + * Gets the name of this node. + * + * @return The name. + */ String getName(); + /** + * Gets the permission for this node. + * + * @return The permission. + */ String getPermission(); + /** + * Gets the children of this node. + * + * @return The children. + */ List getChildren(); + /** + * Gets the parent of this node. Null if this is a root node. + * @return The parent. + */ CommandNode getParent(); + /** + * Sets the parent of this node. + * @param node The parent. + */ void setParent(@Nullable CommandNode node); + /** + * Registers children to this node. + * @param nodes The children. + */ void registerChildren(CommandNode... nodes); + /** + * Removes children from this node. + * @param nodes The children. + */ void removeChildren(CommandNode... nodes); + /** + * Gets the argument for this node. + * @return The argument. + */ default CommandArgument getArgument() { return new LiteralArgument(getName()); } + /** + * Gets the target audience for this node. + * @return The target audience. + */ Class getTargetAudience(); } diff --git a/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/structure/CommandTree.java b/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/structure/CommandTree.java index c9ac616..f1a9519 100644 --- a/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/structure/CommandTree.java +++ b/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/command/structure/CommandTree.java @@ -16,6 +16,9 @@ import me.illusion.skyblockcore.common.command.node.ArgumentCommandNode; import me.illusion.skyblockcore.common.command.node.CommandNode; +/** + * Represents a parsed command tree. + */ public class CommandTree { private final Map roots = new ConcurrentHashMap<>(); @@ -26,10 +29,21 @@ public CommandTree(AbstractSkyblockCommandManager manager) { this.manager = manager; } + /** + * Gets the root node for a command. + * + * @param name The name of the command. + * @return The root node. + */ public CommandNode getRoot(String name) { return roots.get(name); } + /** + * Gets the target node and context for a command. + * @param fullInput The full input of the command. + * @return The target node and context. + */ public TargetResult getTargetNode(String fullInput) { String[] split = fullInput.split(" "); CommandNode node = getRoot(split[0]); @@ -70,6 +84,12 @@ public TargetResult getTargetNode(String fullInput) { return new TargetResult(target, context); } + /** + * Tab completes a command. + * @param audience The audience to tab complete for. + * @param fullInput The full input of the command. + * @return The tab completions. + */ public List tabComplete(SkyblockAudience audience, String fullInput) { String[] split = fullInput.split(" "); CommandNode node = getRoot(split[0]); @@ -90,7 +110,7 @@ public List tabComplete(SkyblockAudience audience, String fullInput) { boolean isLast = index == split.length - 1; if (children == null) { - return Collections.emptyList(); + break; } CommandNode targetChild = null; @@ -111,6 +131,12 @@ public List tabComplete(SkyblockAudience audience, String fullInput) { continue; } + Class targetAudience = child.getTargetAudience(); + + if (targetAudience != null && !targetAudience.isAssignableFrom(audience.getClass())) { + continue; + } + List tabComplete = argument.tabComplete(context); if (tabComplete == null) { @@ -121,16 +147,34 @@ public List tabComplete(SkyblockAudience audience, String fullInput) { } if (targetChild == null) { - return Collections.emptyList(); + break; } target = targetChild; } - return completions; - } + String lastWord = split[split.length - 1]; + + // filter + if (lastWord.isEmpty()) { + return completions; + } + + List filtered = new ArrayList<>(); + + for (String completion : completions) { + if (completion.startsWith(lastWord)) { + filtered.add(completion); + } + } + return filtered; + } + /** + * Registers a root node to the tree. + * @param node The node to register. + */ public void registerNode(CommandNode node) { String name = node.getName(); @@ -142,6 +186,10 @@ public void registerNode(CommandNode node) { manager.registerRoot(name); } + /** + * Registers a command to the tree. + * @param command The command to register. + */ public void registerCommand(SkyblockCommand command) { List nodes = new LinkedList<>(); diff --git a/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/config/SkyblockMessagesFile.java b/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/config/SkyblockMessagesFile.java index f0b4fe3..5d0a9fa 100644 --- a/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/config/SkyblockMessagesFile.java +++ b/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/config/SkyblockMessagesFile.java @@ -3,12 +3,26 @@ import me.illusion.skyblockcore.common.command.audience.SkyblockAudience; import me.illusion.skyblockcore.common.platform.SkyblockPlatform; +/** + * Represents a generic messages file. + */ public class SkyblockMessagesFile extends AbstractConfiguration { + /** + * Creates a new messages file. + * + * @param platform The platform this messages file is for. + * @param name The name of this messages file, without the extension. + */ public SkyblockMessagesFile(SkyblockPlatform platform, String name) { super(platform, name + ".yml"); } + /** + * Sends a message to a SkyblockAudience. + * @param audience The audience to send the message to. + * @param message The message id to send. + */ public void sendMessage(SkyblockAudience audience, String message) { audience.sendMessage(configuration.getString(message)); } diff --git a/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/config/impl/AbstractDatabaseConfiguration.java b/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/config/impl/AbstractDatabaseConfiguration.java index f907b28..8debf10 100644 --- a/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/config/impl/AbstractDatabaseConfiguration.java +++ b/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/config/impl/AbstractDatabaseConfiguration.java @@ -6,6 +6,12 @@ import me.illusion.skyblockcore.common.database.SkyblockDatabaseSetup; import me.illusion.skyblockcore.common.platform.SkyblockPlatform; +/** + * Represents an abstract version of a database configuration. This provides the ability to get the properties of a database, as well as the ability to get the + * preferred database type and filter out unsupported databases. + * + * @param The database type. + */ public abstract class AbstractDatabaseConfiguration extends AbstractConfiguration implements SkyblockDatabaseSetup { private boolean supportsFileBased = true; diff --git a/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/database/cache/redis/MemorySkyblockCache.java b/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/database/cache/redis/MemorySkyblockCache.java index 9785381..9df1fc7 100644 --- a/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/database/cache/redis/MemorySkyblockCache.java +++ b/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/database/cache/redis/MemorySkyblockCache.java @@ -9,6 +9,9 @@ import me.illusion.skyblockcore.common.config.ReadOnlyConfigurationSection; import me.illusion.skyblockcore.common.database.cache.SkyblockCacheDatabase; +/** + * Represents an in-memory implementation of a SkyblockCacheDatabase. This should not be used for anything other than a "simple" network structure. + */ public class MemorySkyblockCache implements SkyblockCacheDatabase { private final Map islandServers = new ConcurrentHashMap<>(); diff --git a/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/database/fetching/sql/AbstractRemoteSQLDatabase.java b/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/database/fetching/sql/AbstractRemoteSQLDatabase.java index f2f575b..1ee5c01 100644 --- a/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/database/fetching/sql/AbstractRemoteSQLDatabase.java +++ b/SkyblockCore-Common/src/main/java/me/illusion/skyblockcore/common/database/fetching/sql/AbstractRemoteSQLDatabase.java @@ -4,6 +4,9 @@ import java.sql.SQLException; import me.illusion.skyblockcore.common.config.ReadOnlyConfigurationSection; +/** + * Represents a remote SQL database. + */ public abstract class AbstractRemoteSQLDatabase extends AbstractSQLSkyblockDatabase { protected String host; diff --git a/SkyblockCore-Proxy/src/main/java/me/illusion/skyblockcore/proxy/audience/SkyblockProxyPlayerAudience.java b/SkyblockCore-Proxy/src/main/java/me/illusion/skyblockcore/proxy/audience/SkyblockProxyPlayerAudience.java index 3a9e588..4a293d3 100644 --- a/SkyblockCore-Proxy/src/main/java/me/illusion/skyblockcore/proxy/audience/SkyblockProxyPlayerAudience.java +++ b/SkyblockCore-Proxy/src/main/java/me/illusion/skyblockcore/proxy/audience/SkyblockProxyPlayerAudience.java @@ -3,10 +3,22 @@ import java.util.UUID; import me.illusion.skyblockcore.common.command.audience.SkyblockAudience; +/** + * Represents a Proxy's player audience. + */ public interface SkyblockProxyPlayerAudience extends SkyblockAudience { + /** + * Gets the player's UUID. + * + * @return The player's UUID. + */ UUID getUniqueId(); + /** + * Connects the player to a server. + * @param server The server id to connect to. + */ void connect(String server); } diff --git a/SkyblockCore-Proxy/src/main/java/me/illusion/skyblockcore/proxy/command/PlaySkyblockCommand.java b/SkyblockCore-Proxy/src/main/java/me/illusion/skyblockcore/proxy/command/PlaySkyblockCommand.java index 32a6e7e..edb50d5 100644 --- a/SkyblockCore-Proxy/src/main/java/me/illusion/skyblockcore/proxy/command/PlaySkyblockCommand.java +++ b/SkyblockCore-Proxy/src/main/java/me/illusion/skyblockcore/proxy/command/PlaySkyblockCommand.java @@ -9,6 +9,10 @@ import me.illusion.skyblockcore.proxy.SkyblockProxyPlatform; import me.illusion.skyblockcore.proxy.audience.SkyblockProxyPlayerAudience; +/** + * Represents a simple play-skyblock command. This will attempt to matchmake the player and connect them to the server. If no server is found, the player will + * be notified. + */ public class PlaySkyblockCommand { private final SkyblockProxyPlatform platform; diff --git a/SkyblockCore-Spigot/src/main/java/me/illusion/skyblockcore/spigot/player/audience/SkyblockBukkitConsoleAudience.java b/SkyblockCore-Spigot/src/main/java/me/illusion/skyblockcore/spigot/player/audience/SkyblockBukkitConsoleAudience.java index f29dc67..0b48770 100644 --- a/SkyblockCore-Spigot/src/main/java/me/illusion/skyblockcore/spigot/player/audience/SkyblockBukkitConsoleAudience.java +++ b/SkyblockCore-Spigot/src/main/java/me/illusion/skyblockcore/spigot/player/audience/SkyblockBukkitConsoleAudience.java @@ -3,6 +3,9 @@ import me.illusion.skyblockcore.common.command.audience.SkyblockConsoleAudience; import org.bukkit.Bukkit; +/** + * Represents a Bukkit console audience. + */ public class SkyblockBukkitConsoleAudience extends SkyblockConsoleAudience { @Override