From 2cfa3f743f87a02b2a238931d8822f561dc96623 Mon Sep 17 00:00:00 2001 From: A248 Date: Mon, 24 May 2021 12:02:35 -0400 Subject: [PATCH 1/5] Remove Add-Opens from manifest --- proxy/build.gradle | 1 - 1 file changed, 1 deletion(-) diff --git a/proxy/build.gradle b/proxy/build.gradle index a206dcf39..27431da34 100644 --- a/proxy/build.gradle +++ b/proxy/build.gradle @@ -28,7 +28,6 @@ jar { attributes 'Implementation-Version': version attributes 'Implementation-Vendor': "Velocity Contributors" attributes 'Multi-Release': 'true' - attributes 'Add-Opens': 'java.base/java.lang' } } From 150808b4b0772e4d41cd30c9abb69f54d98bf1bb Mon Sep 17 00:00:00 2001 From: CoreyShupe Date: Tue, 1 Jun 2021 02:07:06 -0400 Subject: [PATCH 2/5] Initial implementation of raw registered server creation. --- .../com/velocitypowered/api/proxy/ProxyServer.java | 8 ++++++++ .../com/velocitypowered/proxy/VelocityServer.java | 5 +++++ .../com/velocitypowered/proxy/server/ServerMap.java | 13 ++++++++++++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/api/src/main/java/com/velocitypowered/api/proxy/ProxyServer.java b/api/src/main/java/com/velocitypowered/api/proxy/ProxyServer.java index ed0593de2..2a0927ecf 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/ProxyServer.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/ProxyServer.java @@ -105,6 +105,14 @@ public interface ProxyServer extends Audience { */ Collection matchServer(String partialName); + /** + * Creates a raw {@link RegisteredServer} without tying it into the internal server map. + * + * @param server the server to register + * @return the {@link RegisteredServer} implementation created by the provided {@link ServerInfo}. + */ + RegisteredServer createRawRegisteredServer(ServerInfo server); + /** * Registers a server with this proxy. A server with this name should not already exist. * diff --git a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java index ed3bbf801..a060183e8 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java @@ -600,6 +600,11 @@ public class VelocityServer implements ProxyServer, ForwardingAudience { return servers.getAllServers(); } + @Override + public RegisteredServer createRawRegisteredServer(ServerInfo server) { + return servers.createRawRegisteredServer(server); + } + @Override public RegisteredServer registerServer(ServerInfo server) { return servers.register(server); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/server/ServerMap.java b/proxy/src/main/java/com/velocitypowered/proxy/server/ServerMap.java index 41d337be0..00fc2edd6 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/server/ServerMap.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/server/ServerMap.java @@ -54,6 +54,17 @@ public class ServerMap { return ImmutableList.copyOf(servers.values()); } + /** + * Creates a raw implementation of a {@link RegisteredServer} without + * tying it to the internal server map. + * + * @param serverInfo the server to create a registered server with + * @return the {@link RegisteredServer} built from the {@link ServerInfo} + */ + public RegisteredServer createRawRegisteredServer(ServerInfo serverInfo) { + return new VelocityRegisteredServer(server, serverInfo); + } + /** * Registers a server with the proxy. * @@ -63,7 +74,7 @@ public class ServerMap { public RegisteredServer register(ServerInfo serverInfo) { Preconditions.checkNotNull(serverInfo, "serverInfo"); String lowerName = serverInfo.getName().toLowerCase(Locale.US); - VelocityRegisteredServer rs = new VelocityRegisteredServer(server, serverInfo); + RegisteredServer rs = createRawRegisteredServer(serverInfo); RegisteredServer existing = servers.putIfAbsent(lowerName, rs); if (existing != null && !existing.getServerInfo().equals(serverInfo)) { From 61c0c0d083c7ba9214681d52e34bc427d3cd58c1 Mon Sep 17 00:00:00 2001 From: CoreyShupe Date: Tue, 1 Jun 2021 02:17:35 -0400 Subject: [PATCH 3/5] Initial change to allow for server info equality. --- .../proxy/connection/client/ConnectedPlayer.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java index b3f14adea..0d83111a3 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java @@ -870,7 +870,8 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { && !connectedServer.hasCompletedJoin())) { return Optional.of(ConnectionRequestBuilder.Status.CONNECTION_IN_PROGRESS); } - if (connectedServer != null && connectedServer.getServer().equals(server)) { + if (connectedServer != null + && connectedServer.getServer().getServerInfo().equals(server.getServerInfo())) { return Optional.of(ALREADY_CONNECTED); } return Optional.empty(); From e6eecd806a02aadc1189ba10c4082d45b1dc3dbf Mon Sep 17 00:00:00 2001 From: Hugo Manrique Date: Sun, 16 May 2021 13:46:38 +0200 Subject: [PATCH 4/5] Document some restrictions in the command API --- .../com/velocitypowered/api/command/BrigadierCommand.java | 2 +- .../java/com/velocitypowered/api/command/Command.java | 4 ++-- .../com/velocitypowered/api/command/CommandManager.java | 8 ++++++-- .../java/com/velocitypowered/api/command/CommandMeta.java | 6 ++++-- .../com/velocitypowered/api/command/InvocableCommand.java | 5 +++++ .../velocitypowered/api/proxy/ConsoleCommandSource.java | 2 -- 6 files changed, 18 insertions(+), 9 deletions(-) diff --git a/api/src/main/java/com/velocitypowered/api/command/BrigadierCommand.java b/api/src/main/java/com/velocitypowered/api/command/BrigadierCommand.java index da40f48a5..67af56634 100644 --- a/api/src/main/java/com/velocitypowered/api/command/BrigadierCommand.java +++ b/api/src/main/java/com/velocitypowered/api/command/BrigadierCommand.java @@ -18,7 +18,7 @@ import com.mojang.brigadier.tree.LiteralCommandNode; public final class BrigadierCommand implements Command { /** - * Return code used by a {@link com.mojang.brigadier.Command} to indicate + * The return code used by a {@link com.mojang.brigadier.Command} to indicate * the command execution should be forwarded to the backend server. */ public static final int FORWARD = 0xF6287429; diff --git a/api/src/main/java/com/velocitypowered/api/command/Command.java b/api/src/main/java/com/velocitypowered/api/command/Command.java index 684589578..7eb68b40c 100644 --- a/api/src/main/java/com/velocitypowered/api/command/Command.java +++ b/api/src/main/java/com/velocitypowered/api/command/Command.java @@ -17,8 +17,8 @@ import org.checkerframework.checker.nullness.qual.NonNull; * Represents a command that can be executed by a {@link CommandSource} * such as a {@link Player} or the console. * - *

Velocity 1.1.0 introduces specialized command subinterfaces to separate - * command parsing concerns. These include, in order of preference: + *

You must not subclass Command. Use one of the following + * registrable subinterfaces:

* *
    *
  • {@link BrigadierCommand}, which supports parameterized arguments and diff --git a/api/src/main/java/com/velocitypowered/api/command/CommandManager.java b/api/src/main/java/com/velocitypowered/api/command/CommandManager.java index dd0932677..00a2ae2a1 100644 --- a/api/src/main/java/com/velocitypowered/api/command/CommandManager.java +++ b/api/src/main/java/com/velocitypowered/api/command/CommandManager.java @@ -39,7 +39,9 @@ public interface CommandManager { * @param alias the first command alias * @param command the command to register * @param otherAliases additional aliases - * @throws IllegalArgumentException if one of the given aliases is already registered + * @throws IllegalArgumentException if one of the given aliases is already registered, or + * the given command does not implement a registrable {@link Command} subinterface + * @see Command for a list of registrable {@link Command} subinterfaces */ default void register(String alias, Command command, String... otherAliases) { register(metaBuilder(alias).aliases(otherAliases).build(), command); @@ -58,7 +60,9 @@ public interface CommandManager { * * @param meta the command metadata * @param command the command to register - * @throws IllegalArgumentException if one of the given aliases is already registered + * @throws IllegalArgumentException if one of the given aliases is already registered, or + * the given command does not implement a registrable {@link Command} subinterface + * @see Command for a list of registrable {@link Command} subinterfaces */ void register(CommandMeta meta, Command command); diff --git a/api/src/main/java/com/velocitypowered/api/command/CommandMeta.java b/api/src/main/java/com/velocitypowered/api/command/CommandMeta.java index d731e6ec4..45c0a5fe5 100644 --- a/api/src/main/java/com/velocitypowered/api/command/CommandMeta.java +++ b/api/src/main/java/com/velocitypowered/api/command/CommandMeta.java @@ -24,8 +24,8 @@ public interface CommandMeta { Collection getAliases(); /** - * Returns a collection containing command nodes that provide additional - * argument metadata and tab-complete suggestions. + * Returns an immutable collection containing command nodes that provide + * additional argument metadata and tab-complete suggestions. * Note some {@link Command} implementations may not support hinting. * * @return the hinting command nodes @@ -51,6 +51,8 @@ public interface CommandMeta { * * @param node the command node * @return this builder, for chaining + * @throws IllegalArgumentException if the node is executable, i.e. has a non-null + * {@link com.mojang.brigadier.Command}, or has a redirect. */ Builder hint(CommandNode node); diff --git a/api/src/main/java/com/velocitypowered/api/command/InvocableCommand.java b/api/src/main/java/com/velocitypowered/api/command/InvocableCommand.java index e6183e52d..b5301ae3b 100644 --- a/api/src/main/java/com/velocitypowered/api/command/InvocableCommand.java +++ b/api/src/main/java/com/velocitypowered/api/command/InvocableCommand.java @@ -14,6 +14,11 @@ import java.util.concurrent.CompletableFuture; /** * A command that can be executed with arbitrary arguments. * + *

    Modifying the command tree (e.g. registering a command via + * {@link CommandManager#register(CommandMeta, Command)}) during + * permission checking and suggestions provision results in + * undefined behavior, which may include deadlocks. + * * @param the type of the command invocation object */ public interface InvocableCommand> extends Command { diff --git a/api/src/main/java/com/velocitypowered/api/proxy/ConsoleCommandSource.java b/api/src/main/java/com/velocitypowered/api/proxy/ConsoleCommandSource.java index 191b56de7..018ea097c 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/ConsoleCommandSource.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/ConsoleCommandSource.java @@ -7,8 +7,6 @@ package com.velocitypowered.api.proxy; -import com.velocitypowered.api.command.CommandSource; - /** * Indicates that the executor of the command is the console. */ From f103662dc4eec0d6aeb6d4a630f78fca69f7481e Mon Sep 17 00:00:00 2001 From: Hugo Manrique Date: Sat, 5 Jun 2021 18:33:22 +0200 Subject: [PATCH 5/5] Fix incorrect import removal --- .../com/velocitypowered/api/proxy/ConsoleCommandSource.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/api/src/main/java/com/velocitypowered/api/proxy/ConsoleCommandSource.java b/api/src/main/java/com/velocitypowered/api/proxy/ConsoleCommandSource.java index 018ea097c..191b56de7 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/ConsoleCommandSource.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/ConsoleCommandSource.java @@ -7,6 +7,8 @@ package com.velocitypowered.api.proxy; +import com.velocitypowered.api.command.CommandSource; + /** * Indicates that the executor of the command is the console. */