Skip to content

Commit

Permalink
javadoc go brr
Browse files Browse the repository at this point in the history
  • Loading branch information
IllusionTheDev committed Sep 4, 2023
1 parent f313fa2 commit 3387112
Show file tree
Hide file tree
Showing 28 changed files with 311 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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();

}
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> tabComplete(CommandContext context) {
return null;
return Collections.emptyList();
}

default CommandArgument orDefault(Object defaultValue) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <T> The type of the argument.
* @return The parsed argument.
*/
<T> 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 <T> The type of the argument.
*/
<T> 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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <T> The type of audience this command will be used for. SkyblockAudience is the default.
*/
public interface SkyblockCommand<T extends SkyblockAudience> {

/**
* Gets all the arguments for this command.
* @return The arguments.
*/
List<CommandArgument> getArguments();

/**
* Gets the handler for this command.
* @return The handler.
*/
SkyblockCommandHandler<T> getHandler();

/**
* Gets the target audience for this command.
* @return The target audience.
*/
Class<T> getAudience();

/**
* Gets the permission for this command.
* @return The permission.
*/
String getPermission();

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 <T> The type of audience this command will be used for. SkyblockAudience is the default.
*/
public interface SkyblockCommandBuilder<T extends SkyblockAudience> {

/**
* Registers an argument to the command.
* @param argument The argument to register.
* @return The command builder.
*/
SkyblockCommandBuilder<T> registerArgument(CommandArgument argument);

/**
* Sets the handler for the command.
* @param handler The handler to set.
* @return The command builder.
*/
SkyblockCommandBuilder<T> handler(SkyblockCommandHandler<T> handler);

/**
* Sets the permission for the command.
* @param permission The permission to set.
* @return The command builder.
*/
SkyblockCommandBuilder<T> 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 <V> The type of audience this command will be used for.
*/
<V extends SkyblockAudience> SkyblockCommandBuilder<V> audience(Class<V> audience);

/**
* Builds and registers the command.
* @return The built command.
*/
SkyblockCommand<T> build();

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 <T> The type of audience this command handler will be used for. SkyblockAudience is the default.
*/
public interface SkyblockCommandHandler<T extends SkyblockAudience> {

void handle(T audience, CommandContext context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <T> The audience type.
*/
public class SimpleSkyblockCommand<T extends SkyblockAudience> implements SkyblockCommand<T> {

private final List<CommandArgument> arguments;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <T> The audience type.
*/
public class SimpleSkyblockCommandBuilder<T extends SkyblockAudience> implements SkyblockCommandBuilder<T> {

private final List<CommandArgument> arguments;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<SkyblockAudience> {

private final CommandTree commandTree = new CommandTree(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <T> The type of audience this command manager will be used for. SkyblockAudience is the default.
*/
public interface SkyblockCommandManager<T extends SkyblockAudience> {

/**
* 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<T> 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();


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CommandNode> children = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Loading

0 comments on commit 3387112

Please sign in to comment.