Add a basic command handling framework inspired by Bukkit/BungeeCord.

This doesn't yet support tab complete, that will come later. Additionally,
a /server command (using your configuration) and /velocity (shows basic
copyright information about the proxy) have been added.
This commit is contained in:
Andrew Steinborn
2018-08-07 09:34:31 -04:00
parent 09eff5a2fb
commit 05693425bf
13 changed files with 309 additions and 22 deletions

View File

@@ -0,0 +1,29 @@
package com.velocitypowered.api.command;
import com.google.common.collect.ImmutableList;
import javax.annotation.Nonnull;
import java.util.List;
/**
* Represents a command that can be executed by a {@link CommandInvoker}, such as a {@link com.velocitypowered.api.proxy.Player}
* or the console.
*/
public interface CommandExecutor {
/**
* Executes the command for the specified {@link CommandInvoker}.
* @param invoker the invoker of this command
* @param args the arguments for this command
*/
void execute(@Nonnull CommandInvoker invoker, @Nonnull String[] args);
/**
* Provides tab complete suggestions for a command for a specified {@link CommandInvoker}.
* @param invoker the invoker to run the command for
* @param currentArgs the current, partial arguments for this command
* @return tab complete suggestions
*/
default List<String> suggest(@Nonnull CommandInvoker invoker, @Nonnull String[] currentArgs) {
return ImmutableList.of();
}
}

View File

@@ -0,0 +1,23 @@
package com.velocitypowered.api.command;
import net.kyori.text.Component;
import javax.annotation.Nonnull;
/**
* Represents something that can be used to run a {@link CommandExecutor}.
*/
public interface CommandInvoker {
/**
* Sends the specified {@code component} to the invoker.
* @param component the text component to send
*/
void sendMessage(@Nonnull Component component);
/**
* Determines whether or not the invoker has a particular permission.
* @param permission the permission to check for
* @return whether or not the invoker has permission to run this command
*/
boolean hasPermission(@Nonnull String permission);
}

View File

@@ -0,0 +1,26 @@
package com.velocitypowered.api.proxy;
import java.net.InetSocketAddress;
/**
* Represents a connection to the proxy. There is no guarantee that the connection has been fully initialized.
*/
public interface InboundConnection {
/**
* Returns the player's IP address.
* @return the player's IP
*/
InetSocketAddress getRemoteAddress();
/**
* Determine whether or not the player remains online.
* @return whether or not the player active
*/
boolean isActive();
/**
* Returns the current protocol version this connection uses.
* @return the protocol version the connection uses
*/
int getProtocolVersion();
}

View File

@@ -1,18 +1,18 @@
package com.velocitypowered.api.proxy;
import com.velocitypowered.api.command.CommandInvoker;
import com.velocitypowered.api.server.ServerInfo;
import com.velocitypowered.api.util.MessagePosition;
import net.kyori.text.Component;
import javax.annotation.Nonnull;
import java.net.InetSocketAddress;
import java.util.Optional;
import java.util.UUID;
/**
* Represents a player who is connected to the proxy.
*/
public interface Player {
public interface Player extends CommandInvoker, InboundConnection {
/**
* Returns the player's current username.
* @return the username
@@ -31,18 +31,6 @@ public interface Player {
*/
Optional<ServerInfo> getCurrentServer();
/**
* Returns the player's IP address.
* @return the player's IP
*/
InetSocketAddress getRemoteAddress();
/**
* Determine whether or not the player remains online.
* @return whether or not the player active
*/
boolean isActive();
/**
* Sends a chat message to the player's client.
* @param component the chat message to send

View File

@@ -1,5 +1,6 @@
package com.velocitypowered.api.proxy;
import com.velocitypowered.api.command.CommandInvoker;
import com.velocitypowered.api.server.ServerInfo;
import javax.annotation.Nonnull;
@@ -62,4 +63,12 @@ public interface ProxyServer {
* @param server the server to unregister
*/
void unregisterServer(@Nonnull ServerInfo server);
/**
* Returns an instance of {@link CommandInvoker} that can be used to determine if the command is being invoked by
* the console or a console-like executor. Plugins that execute commands are strongly urged to implement their own
* {@link CommandInvoker} instead of using the console invoker.
* @return the console command invoker
*/
CommandInvoker getConsoleCommandInvoker();
}