diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml
index ab1dc2fcd4..aafe7ad3ad 100644
--- a/.github/workflows/gradle.yml
+++ b/.github/workflows/gradle.yml
@@ -3,20 +3,20 @@
name: Java CI with Gradle
-on: [push, pull_request]
+on: [ push, pull_request ]
jobs:
build-17:
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v3
- - uses: gradle/wrapper-validation-action@v1
- - name: Set up JDK 17
- uses: actions/setup-java@v3
- with:
- java-version: 17
- distribution: 'temurin'
- - name: Grant execute permission for gradlew
- run: chmod +x gradlew
- - name: Build with Gradle
- run: ./gradlew build
+ - uses: actions/checkout@v3
+ - uses: gradle/wrapper-validation-action@v1
+ - name: Set up JDK 17
+ uses: actions/setup-java@v3
+ with:
+ java-version: 17
+ distribution: 'temurin'
+ - name: Grant execute permission for gradlew
+ run: chmod +x gradlew
+ - name: Build with Gradle
+ run: ./gradlew build
diff --git a/README.md b/README.md
index 5de7436fda..1d303d16d2 100644
--- a/README.md
+++ b/README.md
@@ -18,7 +18,7 @@ Velocity is licensed under the GPLv3 license.
* First-class support for Paper, Sponge, Fabric and Forge. (Other implementations
may work, but we make every endeavor to support these server implementations
specifically.)
-
+
## Building
Velocity is built with [Gradle](https://gradle.org). We recommend using the
diff --git a/api/build.gradle.kts b/api/build.gradle.kts
index 32fdc70717..f3644c97ec 100644
--- a/api/build.gradle.kts
+++ b/api/build.gradle.kts
@@ -52,12 +52,12 @@ tasks {
o.source = "8"
o.links(
- "https://www.slf4j.org/apidocs/",
- "https://guava.dev/releases/${libs.guava.get().version}/api/docs/",
- "https://google.github.io/guice/api-docs/${libs.guice.get().version}/javadoc/",
- "https://docs.oracle.com/en/java/javase/11/docs/api/",
- "https://jd.advntr.dev/api/${libs.adventure.bom.get().version}/",
- "https://javadoc.io/doc/com.github.ben-manes.caffeine/caffeine"
+ "https://www.slf4j.org/apidocs/",
+ "https://guava.dev/releases/${libs.guava.get().version}/api/docs/",
+ "https://google.github.io/guice/api-docs/${libs.guice.get().version}/javadoc/",
+ "https://docs.oracle.com/en/java/javase/11/docs/api/",
+ "https://jd.advntr.dev/api/${libs.adventure.bom.get().version}/",
+ "https://javadoc.io/doc/com.github.ben-manes.caffeine/caffeine"
)
// Disable the crazy super-strict doclint tool in Java 8
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 094e4ddf9c..a0dea5a0c4 100644
--- a/api/src/main/java/com/velocitypowered/api/command/BrigadierCommand.java
+++ b/api/src/main/java/com/velocitypowered/api/command/BrigadierCommand.java
@@ -12,22 +12,20 @@
import com.mojang.brigadier.tree.LiteralCommandNode;
/**
- * A command that uses Brigadier for parsing the command and
- * providing suggestions to the client.
+ * A command that uses Brigadier for parsing the command and providing suggestions to the client.
*/
public final class BrigadierCommand implements Command {
/**
- * The return code used by a {@link com.mojang.brigadier.Command} to indicate
- * the command execution should be forwarded to the backend server.
+ * 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;
private final LiteralCommandNode You must not subclass 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.
+ * {@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
*/
diff --git a/api/src/main/java/com/velocitypowered/api/command/RawCommand.java b/api/src/main/java/com/velocitypowered/api/command/RawCommand.java
index 05da7c6e4e..21626895e4 100644
--- a/api/src/main/java/com/velocitypowered/api/command/RawCommand.java
+++ b/api/src/main/java/com/velocitypowered/api/command/RawCommand.java
@@ -8,9 +8,9 @@
package com.velocitypowered.api.command;
/**
- * A specialized sub-interface of {@code Command} which indicates the proxy should pass
- * the command and its arguments directly without further processing.
- * This is useful for bolting on external command frameworks to Velocity.
+ * A specialized sub-interface of {@code Command} which indicates the proxy should pass the command
+ * and its arguments directly without further processing. This is useful for bolting on external
+ * command frameworks to Velocity.
*/
public interface RawCommand extends InvocableCommand Prefer using {@link BrigadierCommand}, which is also
* backwards-compatible with older clients.
diff --git a/api/src/main/java/com/velocitypowered/api/command/VelocityBrigadierMessage.java b/api/src/main/java/com/velocitypowered/api/command/VelocityBrigadierMessage.java
index 0ae69591ef..68af560659 100644
--- a/api/src/main/java/com/velocitypowered/api/command/VelocityBrigadierMessage.java
+++ b/api/src/main/java/com/velocitypowered/api/command/VelocityBrigadierMessage.java
@@ -15,8 +15,8 @@
import org.jetbrains.annotations.NotNull;
/**
- * Represents an implementation of brigadier's {@link Message}, providing support for {@link
- * Component} messages.
+ * Represents an implementation of brigadier's {@link Message}, providing support for
+ * {@link Component} messages.
*/
public final class VelocityBrigadierMessage implements Message, ComponentLike {
diff --git a/api/src/main/java/com/velocitypowered/api/event/Continuation.java b/api/src/main/java/com/velocitypowered/api/event/Continuation.java
index 30672ef606..260617b69d 100644
--- a/api/src/main/java/com/velocitypowered/api/event/Continuation.java
+++ b/api/src/main/java/com/velocitypowered/api/event/Continuation.java
@@ -8,8 +8,8 @@
package com.velocitypowered.api.event;
/**
- * Represents a continuation of a paused event handler. Any of the resume methods
- * may only be called once otherwise an {@link IllegalStateException} is expected.
+ * Represents a continuation of a paused event handler. Any of the resume methods may only be called
+ * once otherwise an {@link IllegalStateException} is expected.
*/
public interface Continuation {
diff --git a/api/src/main/java/com/velocitypowered/api/event/EventManager.java b/api/src/main/java/com/velocitypowered/api/event/EventManager.java
index 2261e22208..562e320b1e 100644
--- a/api/src/main/java/com/velocitypowered/api/event/EventManager.java
+++ b/api/src/main/java/com/velocitypowered/api/event/EventManager.java
@@ -15,36 +15,36 @@
public interface EventManager {
/**
- * Requests that the specified {@code listener} listen for events and associate it with the {@code
- * plugin}.
+ * Requests that the specified {@code listener} listen for events and associate it with the
+ * {@code plugin}.
*
- * @param plugin the plugin to associate with the listener
+ * @param plugin the plugin to associate with the listener
* @param listener the listener to register
*/
void register(Object plugin, Object listener);
/**
- * Requests that the specified {@code handler} listen for events and associate it with the {@code
- * plugin}.
+ * Requests that the specified {@code handler} listen for events and associate it with the
+ * {@code plugin}.
*
- * @param plugin the plugin to associate with the handler
+ * @param plugin the plugin to associate with the handler
* @param eventClass the class for the event handler to register
- * @param handler the handler to register
- * @param If this method returns {@code true}, the method is guaranteed to be executed
- * asynchronously. Otherwise, the handler may be executed on the current thread or
- * asynchronously. This still means you must consider thread-safety in your
- * event listeners as the "current thread" can and will be different each time. If any method handler targeting an event type is marked with {@code true}, then every
* handler targeting that event type will be executed asynchronously.
- * Velocity typically fires this event asynchronously and does not wait for a response. However,
- * it will wait for all {@link DisconnectEvent}s for every player on the proxy to fire
- * successfully before the proxy shuts down. This event is the sole exception to the
- * {@link AwaitingEvent} contract.
+ * Velocity typically fires this event asynchronously and does not wait for a response. However, it
+ * will wait for all {@link DisconnectEvent}s for every player on the proxy to fire successfully
+ * before the proxy shuts down. This event is the sole exception to the {@link AwaitingEvent}
+ * contract.
* Command
. Use one of the following
* registrable subinterfaces:
- * Velocity will wait for this event to finish firing before proceeding further with server - * startup (for the console command source) and logins (for players) but it is strongly - * recommended to minimize the amount of work that must be done in this event. + * Velocity will wait for this event to finish firing before proceeding further with server startup + * (for the console command source) and logins (for players) but it is strongly recommended to + * minimize the amount of work that must be done in this event. *
*/ @AwaitingEvent diff --git a/api/src/main/java/com/velocitypowered/api/event/player/GameProfileRequestEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/GameProfileRequestEvent.java index 78a3985488..b734ad8636 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/GameProfileRequestEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/GameProfileRequestEvent.java @@ -9,7 +9,7 @@ import com.google.common.base.Preconditions; import com.velocitypowered.api.event.annotation.AwaitingEvent; -import com.velocitypowered.api.proxy.InboundConnection; +import com.velocitypowered.api.network.connection.InboundConnection; import com.velocitypowered.api.util.GameProfile; import org.checkerframework.checker.nullness.qual.Nullable; @@ -19,9 +19,9 @@ * a user, i.e. skin replacement. * *- * Velocity will wait for this event to finish firing before proceeding with the rest of the login - * process, but you should try to limit the work done in any event that fires during the login - * process. + * Velocity will wait for this event to finish firing before proceeding with the rest of the login + * process, but you should try to limit the work done in any event that fires during the login + * process. *
*/ @AwaitingEvent @@ -36,9 +36,9 @@ public final class GameProfileRequestEvent { /** * Creates a new instance. * - * @param connection the connection connecting to the proxy + * @param connection the connection connecting to the proxy * @param originalProfile the original {@link GameProfile} for the user - * @param onlineMode whether or not the user connected in online or offline mode + * @param onlineMode whether or not the user connected in online or offline mode */ public GameProfileRequestEvent(InboundConnection connection, GameProfile originalProfile, boolean onlineMode) { diff --git a/api/src/main/java/com/velocitypowered/api/event/player/KickedFromServerEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/KickedFromServerEvent.java index 92f5880b30..eccf6975d3 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/KickedFromServerEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/KickedFromServerEvent.java @@ -10,7 +10,7 @@ import com.google.common.base.Preconditions; import com.velocitypowered.api.event.ResultedEvent; import com.velocitypowered.api.event.annotation.AwaitingEvent; -import com.velocitypowered.api.proxy.Player; +import com.velocitypowered.api.proxy.player.Player; import com.velocitypowered.api.proxy.server.RegisteredServer; import net.kyori.adventure.text.Component; import org.checkerframework.checker.nullness.qual.NonNull; @@ -19,9 +19,9 @@ /** * Fired when a player is kicked from a server. You may either allow Velocity to kick the player * (with an optional reason override) or redirect the player to a separate server. By default, - * Velocity will notify the user (if they are already connected to a server) or disconnect them - * (if they are not on a server and no other servers are available). Velocity will wait on this - * event to finish firing before taking the specified action. + * Velocity will notify the user (if they are already connected to a server) or disconnect them (if + * they are not on a server and no other servers are available). Velocity will wait on this event to + * finish firing before taking the specified action. */ @AwaitingEvent public final class KickedFromServerEvent implements @@ -36,14 +36,14 @@ public final class KickedFromServerEvent implements /** * Creates a {@code KickedFromServerEvent} instance. * - * @param player the player affected - * @param server the server the player disconnected from - * @param originalReason the reason for being kicked, optional + * @param player the player affected + * @param server the server the player disconnected from + * @param originalReason the reason for being kicked, optional * @param duringServerConnect whether or not the player was kicked during the connection process - * @param result the initial result + * @param result the initial result */ public KickedFromServerEvent(Player player, RegisteredServer server, - @Nullable Component originalReason, boolean duringServerConnect, + @Nullable Component originalReason, boolean duringServerConnect, ServerKickResult result) { this.player = Preconditions.checkNotNull(player, "player"); this.server = Preconditions.checkNotNull(server, "server"); @@ -88,7 +88,7 @@ public boolean kickedDuringServerConnect() { * * @return whether or not the player got kicked * @deprecated {@link #kickedDuringServerConnect()} has a better name and reflects the actual - * result + * result */ @Deprecated public boolean kickedDuringLogin() { @@ -161,11 +161,11 @@ public RegisteredServer getServer() { } /** - * Creates a new redirect result to forward the player to the specified {@code server}. - * The specified {@code message} will be sent to the player after the redirection. - * Use {@code Component.empty()} to skip sending any messages to the player. + * Creates a new redirect result to forward the player to the specified {@code server}. The + * specified {@code message} will be sent to the player after the redirection. Use + * {@code Component.empty()} to skip sending any messages to the player. * - * @param server the server to send the player to + * @param server the server to send the player to * @param message the message will be sent to the player after redirecting * @return the redirect result */ @@ -175,8 +175,8 @@ public static RedirectPlayer redirect(RegisteredServer server, } /** - * Creates a new redirect result to forward the player to the specified {@code server}. - * The kick reason will be displayed to the player + * Creates a new redirect result to forward the player to the specified {@code server}. The kick + * reason will be displayed to the player * * @param server the server to send the player to * @return the redirect result diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PlayerChannelRegisterEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/PlayerChannelRegisterEvent.java index 5e0760adc7..c646db0ec6 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/PlayerChannelRegisterEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/PlayerChannelRegisterEvent.java @@ -8,13 +8,13 @@ package com.velocitypowered.api.event.player; import com.google.common.base.Preconditions; -import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.messages.ChannelIdentifier; +import com.velocitypowered.api.proxy.player.Player; import java.util.List; /** - * This event is fired when a client ({@link Player}) sends a plugin message through the - * register channel. Velocity will not wait on this event to finish firing. + * This event is fired when a client ({@link Player}) sends a plugin message through the register + * channel. Velocity will not wait on this event to finish firing. */ public final class PlayerChannelRegisterEvent implements PlayerReferentEvent { @@ -37,8 +37,8 @@ public List- * Note: For historical reasons, Velocity does wait on this event to finish - * firing before continuing the server connection process. This behavior is - * deprecated and likely to be removed in Polymer. + * Note: For historical reasons, Velocity does wait on this event to finish + * firing before continuing the server connection process. This behavior is + * deprecated and likely to be removed in Polymer. *
*/ @AwaitingEvent @@ -33,8 +33,8 @@ public final class ServerConnectedEvent implements PlayerReferentEvent { /** * Constructs a ServerConnectedEvent. * - * @param player the player that was connected - * @param server the server the player was connected to + * @param player the player that was connected + * @param server the server the player was connected to * @param previousServer the server the player was previously connected to, null if none */ public ServerConnectedEvent(Player player, RegisteredServer server, diff --git a/api/src/main/java/com/velocitypowered/api/event/player/ServerLoginPluginMessageEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/ServerLoginPluginMessageEvent.java index d5866c7133..b9f3305ddf 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/ServerLoginPluginMessageEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/ServerLoginPluginMessageEvent.java @@ -15,7 +15,7 @@ import com.velocitypowered.api.event.ResultedEvent; import com.velocitypowered.api.event.annotation.AwaitingEvent; import com.velocitypowered.api.event.player.ServerLoginPluginMessageEvent.ResponseResult; -import com.velocitypowered.api.proxy.ServerConnection; +import com.velocitypowered.api.network.connection.ServerConnection; import com.velocitypowered.api.proxy.messages.ChannelIdentifier; import java.io.ByteArrayInputStream; import java.util.Arrays; @@ -23,12 +23,13 @@ /** * Fired when a server sends a login plugin message to the proxy. Plugins have the opportunity to - * respond to the messages as needed. Velocity will wait on this event to finish. The server will - * be responsible for continuing the login process once the server is satisfied with any login - * plugin responses sent by proxy plugins (or messages indicating a lack of response). + * respond to the messages as needed. Velocity will wait on this event to finish. The server will be + * responsible for continuing the login process once the server is satisfied with any login plugin + * responses sent by proxy plugins (or messages indicating a lack of response). */ @AwaitingEvent public class ServerLoginPluginMessageEvent implements ResultedEventNote: The resource-pack location should always: - * - Use HTTPS with a valid certificate. - * - Be in a crawler-accessible location. Having it behind Cloudflare or other DoS/Bot/crawler - * protection may cause issues in downloading. - * - Be on a web-server with enough bandwidth and reliable connection - * so the download does not time out or fail.
+ * - Use HTTPS with a valid certificate. - Be in a crawler-accessible location. Having it behind + * Cloudflare or other DoS/Bot/crawler protection may cause issues in downloading. - Be on a + * web-server with enough bandwidth and reliable connection so the download does not time out or + * fail. * *Do also make sure that the resource pack is in the correct format for the version - * of the client. It is also highly recommended to always provide the resource-pack SHA-1 hash - * of the resource pack with {@link ResourcePackInfo.Builder#hash(byte[])} - * whenever possible to save bandwidth. If a hash is present the client will first check - * if it already has a resource pack by that hash cached.
+ * of the client. It is also highly recommended to always provide the resource-pack SHA-1 hash of + * the resource pack with {@link ResourcePackInfo.Builder#hash(byte[])} whenever possible to save + * bandwidth. If a hash is present the client will first check if it already has a resource pack + * by that hash cached. * * @param url The url where the resource pack can be found * @return a ResourcePackInfo builder diff --git a/api/src/main/java/com/velocitypowered/api/proxy/config/ProxyConfig.java b/api/src/main/java/com/velocitypowered/api/proxy/config/ProxyConfig.java index eae807eba2..18bf08161e 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/config/ProxyConfig.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/config/ProxyConfig.java @@ -70,9 +70,9 @@ public interface ProxyConfig { boolean isOnlineMode(); /** - * If client's ISP/AS sent from this proxy is different from the one from Mojang's - * authentication server, the player is kicked. This disallows some VPN and proxy - * connections but is a weak form of protection. + * If client's ISP/AS sent from this proxy is different from the one from Mojang's authentication + * server, the player is kicked. This disallows some VPN and proxy connections but is a weak form + * of protection. * * @return whether to prevent client proxy connections by checking the IP with Mojang servers */ diff --git a/api/src/main/java/com/velocitypowered/api/proxy/crypto/IdentifiedKey.java b/api/src/main/java/com/velocitypowered/api/proxy/crypto/IdentifiedKey.java index 19bb612112..623498736b 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/crypto/IdentifiedKey.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/crypto/IdentifiedKey.java @@ -20,8 +20,7 @@ public interface IdentifiedKey extends KeySigned { /** - * Returns RSA public key. - * Note: this key is at least 2048 bits but may be larger. + * Returns RSA public key. Note: this key is at least 2048 bits but may be larger. * * @return the RSA public key in question */ @@ -32,15 +31,14 @@ public interface IdentifiedKey extends KeySigned { * Validates a signature against this public key. * * @param signature the signature data - * @param toVerify the signed data - * + * @param toVerify the signed data * @return validity of the signature */ boolean verifyDataSignature(byte[] signature, byte[]... toVerify); /** - * Retrieves the signature holders UUID. - * Returns null before the {@link com.velocitypowered.api.event.connection.LoginEvent}. + * Retrieves the signature holders UUID. Returns null before the + * {@link com.velocitypowered.api.event.connection.LoginEvent}. * * @return the holder UUID or null if not present */ @@ -68,11 +66,11 @@ enum Revision { this.backwardsCompatibleTo = backwardsCompatibleTo; this.applicableTo = applicableTo; } - + public SetDOES NOT WORK YET FOR MESSAGES AND COMMANDS!
* Addendum: Does not work for 1.19.1 until the user has authenticated. * diff --git a/api/src/main/java/com/velocitypowered/api/proxy/messages/ChannelIdentifier.java b/api/src/main/java/com/velocitypowered/api/proxy/messages/ChannelIdentifier.java index f5bc406b60..8352c731db 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/messages/ChannelIdentifier.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/messages/ChannelIdentifier.java @@ -7,6 +7,8 @@ package com.velocitypowered.api.proxy.messages; +import net.kyori.adventure.key.Key; + /** * Represents a channel identifier for use with plugin messaging. */ @@ -18,4 +20,27 @@ public interface ChannelIdentifier { * @return the textual representation of the identifier */ String id(); + + /** + * Returns a channel identifier to identify a channel for Minecraft clients older than Minecraft + * 1.13. + * + * @param name the channel name to use + * @return the channel identifier with the given name + */ + static ChannelIdentifier legacy(String name) { + return new LegacyChannelIdentifier(name); + } + + + /** + * Returns a channel identifier to identify a channel for Minecraft clients newer or equal to + * Minecraft 1.13. This uses a Minecraft resource code of the form {@code namespace:name}. + * + * @param key the channel name to use + * @return the channel identifier with the given name + */ + static ChannelIdentifier ofKey(Key key) { + return new MinecraftChannelIdentifier(key); + } } diff --git a/api/src/main/java/com/velocitypowered/api/proxy/messages/ChannelMessageSink.java b/api/src/main/java/com/velocitypowered/api/proxy/messages/ChannelMessageSink.java index b310f13bcb..19f0dc268b 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/messages/ChannelMessageSink.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/messages/ChannelMessageSink.java @@ -16,7 +16,7 @@ public interface ChannelMessageSink { * Sends a plugin message to this target. * * @param identifier the channel identifier to send the message on - * @param data the data to send + * @param data the data to send * @return whether or not the message could be sent */ boolean sendPluginMessage(ChannelIdentifier identifier, byte[] data); diff --git a/api/src/main/java/com/velocitypowered/api/proxy/messages/LegacyChannelIdentifier.java b/api/src/main/java/com/velocitypowered/api/proxy/messages/LegacyChannelIdentifier.java index 6e45efb484..539fbb64aa 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/messages/LegacyChannelIdentifier.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/messages/LegacyChannelIdentifier.java @@ -17,7 +17,7 @@ * messages, please see {@link MinecraftChannelIdentifier}. This class is immutable and safe for * multi-threaded use. */ -public final class LegacyChannelIdentifier implements ChannelIdentifier { +final class LegacyChannelIdentifier implements ChannelIdentifier { private final String name; @@ -26,7 +26,7 @@ public final class LegacyChannelIdentifier implements ChannelIdentifier { * * @param name the name for the channel */ - public LegacyChannelIdentifier(String name) { + LegacyChannelIdentifier(String name) { Preconditions.checkArgument(!Strings.isNullOrEmpty(name), "provided name is empty"); this.name = name; } @@ -54,7 +54,7 @@ public boolean equals(@Nullable Object o) { @Override public int hashCode() { - return Objects.hash(name); + return name.hashCode(); } @Override diff --git a/api/src/main/java/com/velocitypowered/api/proxy/messages/MinecraftChannelIdentifier.java b/api/src/main/java/com/velocitypowered/api/proxy/messages/MinecraftChannelIdentifier.java index b003d1b206..9d8247c628 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/messages/MinecraftChannelIdentifier.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/messages/MinecraftChannelIdentifier.java @@ -7,11 +7,7 @@ package com.velocitypowered.api.proxy.messages; -import static com.google.common.base.Preconditions.checkArgument; - -import com.google.common.base.Strings; import java.util.Objects; -import java.util.regex.Pattern; import net.kyori.adventure.key.Key; import org.checkerframework.checker.nullness.qual.Nullable; @@ -19,94 +15,17 @@ * Represents a Minecraft 1.13+ channel identifier. This class is immutable and safe for * multi-threaded use. */ -public final class MinecraftChannelIdentifier implements ChannelIdentifier { - - private static final Pattern VALID_IDENTIFIER_REGEX = Pattern.compile("[a-z0-9/\\-_]*"); - - private final String namespace; - private final String name; - - private MinecraftChannelIdentifier(String namespace, String name) { - this.namespace = namespace; - this.name = name; - } - - /** - * Creates an identifier in the default namespace ({@code minecraft}). Plugins are strongly - * encouraged to provide their own namespace. - * - * @param name the name in the default namespace to use - * @return a new channel identifier - */ - public static MinecraftChannelIdentifier forDefaultNamespace(String name) { - return new MinecraftChannelIdentifier("minecraft", name); - } - - /** - * Creates an identifier in the specified namespace. - * - * @param namespace the namespace to use - * @param name the channel name inside the specified namespace - * @return a new channel identifier - */ - public static MinecraftChannelIdentifier create(String namespace, String name) { - checkArgument(!Strings.isNullOrEmpty(namespace), "namespace is null or empty"); - checkArgument(name != null, "namespace is null or empty"); - checkArgument(VALID_IDENTIFIER_REGEX.matcher(namespace).matches(), - "namespace is not valid, must match: %s got %s", - VALID_IDENTIFIER_REGEX.toString(), - namespace); - checkArgument(VALID_IDENTIFIER_REGEX.matcher(name).matches(), - "name is not valid, must match: %s got %s", - VALID_IDENTIFIER_REGEX.toString(), - name); - return new MinecraftChannelIdentifier(namespace, name); - } +final class MinecraftChannelIdentifier implements ChannelIdentifier { - /** - * Creates an channel identifier from the specified Minecraft identifier. - * - * @param identifier the Minecraft identifier - * @return a new channel identifier - */ - public static MinecraftChannelIdentifier from(String identifier) { - int colonPos = identifier.indexOf(':'); - if (colonPos == -1) { - throw new IllegalArgumentException("Identifier does not contain a colon."); - } - if (colonPos + 1 == identifier.length()) { - throw new IllegalArgumentException("Identifier is empty."); - } - String namespace = identifier.substring(0, colonPos); - String name = identifier.substring(colonPos + 1); - return create(namespace, name); - } - - /** - * Creates an channel identifier from the specified Minecraft identifier. - * - * @param key the Minecraft key to use - * @return a new channel identifier - */ - public static MinecraftChannelIdentifier from(Key key) { - return create(key.namespace(), key.value()); - } - - public String getNamespace() { - return namespace; - } - - public String getName() { - return name; - } + private final Key key; - public Key asKey() { - return Key.key(namespace, name); + MinecraftChannelIdentifier(Key key) { + this.key = key; } @Override public String toString() { - return namespace + ":" + name + " (modern)"; + return this.key.asString() + " (modern)"; } @Override @@ -118,17 +37,16 @@ public boolean equals(@Nullable Object o) { return false; } MinecraftChannelIdentifier that = (MinecraftChannelIdentifier) o; - return Objects.equals(namespace, that.namespace) - && Objects.equals(name, that.name); + return Objects.equals(key, that.key); } @Override public int hashCode() { - return Objects.hash(namespace, name); + return key.hashCode(); } @Override public String id() { - return namespace + ":" + name; + return key.asString(); } } diff --git a/api/src/main/java/com/velocitypowered/api/proxy/player/ChatSession.java b/api/src/main/java/com/velocitypowered/api/proxy/player/ChatSession.java index 8a9da8f22c..a779c5aa72 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/player/ChatSession.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/player/ChatSession.java @@ -14,6 +14,7 @@ * Represents a chat session held by a player. */ public interface ChatSession extends KeyIdentifiable { + /** * Returns the {@link UUID} of the session. * diff --git a/api/src/main/java/com/velocitypowered/api/proxy/Player.java b/api/src/main/java/com/velocitypowered/api/proxy/player/Player.java similarity index 84% rename from api/src/main/java/com/velocitypowered/api/proxy/Player.java rename to api/src/main/java/com/velocitypowered/api/proxy/player/Player.java index 64c2e5a564..a86ac2351c 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/Player.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/player/Player.java @@ -5,17 +5,18 @@ * reference the LICENSE file in the api top-level directory. */ -package com.velocitypowered.api.proxy; +package com.velocitypowered.api.proxy.player; import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.event.player.PlayerResourcePackStatusEvent; +import com.velocitypowered.api.network.connection.InboundConnection; +import com.velocitypowered.api.network.connection.ServerConnection; +import com.velocitypowered.api.proxy.ConnectionRequestBuilder; +import com.velocitypowered.api.proxy.ProxyServer; import com.velocitypowered.api.proxy.crypto.KeyIdentifiable; import com.velocitypowered.api.proxy.messages.ChannelIdentifier; import com.velocitypowered.api.proxy.messages.ChannelMessageSink; import com.velocitypowered.api.proxy.messages.ChannelMessageSource; -import com.velocitypowered.api.proxy.player.PlayerSettings; -import com.velocitypowered.api.proxy.player.ResourcePackInfo; -import com.velocitypowered.api.proxy.player.TabList; import com.velocitypowered.api.proxy.server.RegisteredServer; import com.velocitypowered.api.util.GameProfile; import com.velocitypowered.api.util.ModInfo; @@ -186,19 +187,17 @@ public interface Player extends void spoofChatInput(String input); /** - * Queues and sends a new Resource-pack offer to the player. - * To monitor the status of the sent resource pack, subscribe to - * {@link PlayerResourcePackStatusEvent}. - * To create a {@link ResourcePackInfo} use the - * {@link ProxyServer#createResourcePackBuilder(String)} builder. + * Queues and sends a new Resource-pack offer to the player. To monitor the status of the sent + * resource pack, subscribe to {@link PlayerResourcePackStatusEvent}. To create a + * {@link ResourcePackInfo} use the {@link ProxyServer#createResourcePackBuilder(String)} + * builder. * * @param packInfo the resource-pack in question */ void sendResourcePackOffer(ResourcePackInfo packInfo); /** - * Gets the {@link ResourcePackInfo} of the currently applied - * resource-pack or null if none. + * Gets the {@link ResourcePackInfo} of the currently applied resource-pack or null if none. * * @return the applied resource pack or null if none. */ @@ -206,9 +205,8 @@ public interface Player extends ResourcePackInfo appliedResourcePack(); /** - * Gets the {@link ResourcePackInfo} of the resource pack - * the user is currently downloading or is currently - * prompted to install or null if none. + * Gets the {@link ResourcePackInfo} of the resource pack the user is currently downloading or is + * currently prompted to install or null if none. * * @return the pending resource pack or null if none */ @@ -217,9 +215,9 @@ public interface Player extends /** * Note that this method does not send a plugin message to the server the player - * is connected to. You should only use this method if you are trying to communicate - * with a mod that is installed on the player's client. To send a plugin message to the server - * from the player, you should use the equivalent method on the instance returned by + * is connected to. You should only use this method if you are trying to communicate with + * a mod that is installed on the player's client. To send a plugin message to the server from the + * player, you should use the equivalent method on the instance returned by * {@link #connectedServer()}. * * @inheritDoc @@ -234,9 +232,9 @@ public interface Player extends @Override default @NotNull HoverEventNote that a successful connection to a server does not mean that we will be in this state.
- * After a handshake reset, if the next server is vanilla we will still be in the {@link
- * #NOT_STARTED} phase, which means we must NOT send a reset packet. This is handled by overriding
- * the {@link #resetConnectionPhase(ConnectedPlayer)} in this element (it is usually a no-op).
+ * After a handshake reset, if the next server is vanilla we will still be in the
+ * {@link #NOT_STARTED} phase, which means we must NOT send a reset packet. This is handled by
+ * overriding the {@link #resetConnectionPhase(ConnectedPlayer)} in this element (it is usually a
+ * no-op).
*/
COMPLETE(null) {
@Override
@@ -181,8 +182,8 @@ boolean onHandle(ConnectedPlayer player,
*
* @param packetToAdvanceOn The ID of the packet discriminator that indicates that the client has
* moved onto a new phase, and as such, Velocity should do so too
- * (inspecting {@link #nextPhase()}. A null indicates there is
- * no further phase to transition to.
+ * (inspecting {@link #nextPhase()}. A null indicates there is no further
+ * phase to transition to.
*/
LegacyForgeHandshakeClientPhase(Integer packetToAdvanceOn) {
this.packetToAdvanceOn = packetToAdvanceOn;
diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/ClientConfigData.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/ClientConfigData.java
index 84ed2a5bbe..aa6a62a008 100644
--- a/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/ClientConfigData.java
+++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/ClientConfigData.java
@@ -23,8 +23,7 @@
import org.jetbrains.annotations.Nullable;
/**
- * Holds the registry data that is sent
- * to the client during the config stage.
+ * Holds the registry data that is sent to the client during the config stage.
*/
public class ClientConfigData {
@@ -35,7 +34,7 @@ public class ClientConfigData {
private final String brand;
private ClientConfigData(@Nullable VelocityResourcePackInfo resourcePackInfo, DataTag tag,
- RegistrySync registry, Key[] features, String brand) {
+ RegistrySync registry, Key[] features, String brand) {
this.resourcePackInfo = resourcePackInfo;
this.tag = tag;
this.registry = registry;
@@ -76,6 +75,7 @@ public static ClientConfigData.Builder builder() {
* Builder for ClientConfigData.
*/
public static class Builder {
+
private VelocityResourcePackInfo resourcePackInfo;
private DataTag tag;
private RegistrySync registry;
diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/DataTag.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/DataTag.java
index 9a7d0de737..4cb93571aa 100644
--- a/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/DataTag.java
+++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/DataTag.java
@@ -27,6 +27,7 @@
* Represents a data tag.
*/
public class DataTag {
+
private final ImmutableList