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:
@@ -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();
|
||||
}
|
||||
}
|
@@ -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);
|
||||
}
|
@@ -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();
|
||||
}
|
@@ -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
|
||||
|
@@ -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();
|
||||
}
|
||||
|
Reference in New Issue
Block a user