diff --git a/api/src/main/java/com/velocitypowered/api/proxy/messages/MinecraftPluginChannelId.java b/api/src/main/java/com/velocitypowered/api/proxy/messages/KeyedPluginChannelId.java similarity index 68% rename from api/src/main/java/com/velocitypowered/api/proxy/messages/MinecraftPluginChannelId.java rename to api/src/main/java/com/velocitypowered/api/proxy/messages/KeyedPluginChannelId.java index b5b6b583d..14b66c836 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/messages/MinecraftPluginChannelId.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/messages/KeyedPluginChannelId.java @@ -8,20 +8,16 @@ package com.velocitypowered.api.proxy.messages; import com.google.common.base.Preconditions; -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; /** - * Represents a Minecraft 1.13+ channel identifier. + * Represents a modern namespaced channel identifier. */ -public final class MinecraftPluginChannelId implements PluginChannelId { +public final class KeyedPluginChannelId implements PluginChannelId { private final Key key; - MinecraftPluginChannelId(Key key) { + KeyedPluginChannelId(Key key) { this.key = Preconditions.checkNotNull(key, "key"); } @@ -38,7 +34,7 @@ public final class MinecraftPluginChannelId implements PluginChannelId { return false; } - MinecraftPluginChannelId that = (MinecraftPluginChannelId) o; + KeyedPluginChannelId that = (KeyedPluginChannelId) o; return key.equals(that.key); } diff --git a/api/src/main/java/com/velocitypowered/api/proxy/messages/PairedPluginChannelId.java b/api/src/main/java/com/velocitypowered/api/proxy/messages/PairedPluginChannelId.java index b31cbc0b6..2bce1abc0 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/messages/PairedPluginChannelId.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/messages/PairedPluginChannelId.java @@ -12,9 +12,8 @@ import com.google.common.base.Strings; import net.kyori.adventure.key.Key; /** - * Reperesents a legacy channel identifier (for Minecraft 1.12 and below). For modern 1.13 plugin - * messages, please see {@link MinecraftPluginChannelId}. This class is immutable and safe for - * multi-threaded use. + * Reperesents a legacy channel identifier (for Minecraft 1.12 and below) paired with a namespaced + * key for 1.13 and above. This class is immutable and safe for multi-threaded use. */ public final class PairedPluginChannelId implements PluginChannelId { diff --git a/api/src/main/java/com/velocitypowered/api/proxy/messages/PluginChannelId.java b/api/src/main/java/com/velocitypowered/api/proxy/messages/PluginChannelId.java index 037caf1f0..49c4dd767 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/messages/PluginChannelId.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/messages/PluginChannelId.java @@ -22,8 +22,8 @@ public interface PluginChannelId { * @param key the key instance to wrap * @return a wrapped plugin channel ID */ - static MinecraftPluginChannelId wrap(Key key) { - return new MinecraftPluginChannelId(key); + static KeyedPluginChannelId wrap(Key key) { + return new KeyedPluginChannelId(key); } /** diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/PluginMessageUtil.java b/proxy/src/main/java/com/velocitypowered/proxy/network/PluginMessageUtil.java index 04036e472..8db301011 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/PluginMessageUtil.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/PluginMessageUtil.java @@ -22,7 +22,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.collect.ImmutableList; import com.velocitypowered.api.network.ProtocolVersion; -import com.velocitypowered.api.proxy.messages.MinecraftPluginChannelId; +import com.velocitypowered.api.proxy.messages.KeyedPluginChannelId; import com.velocitypowered.api.proxy.messages.PairedPluginChannelId; import com.velocitypowered.api.proxy.messages.PluginChannelId; import com.velocitypowered.api.util.ProxyVersion; @@ -178,8 +178,8 @@ public final class PluginMessageUtil { } public static String channelIdForVersion(PluginChannelId id, ProtocolVersion version) { - if (id instanceof MinecraftPluginChannelId) { - return ((MinecraftPluginChannelId) id).key().asString(); + if (id instanceof KeyedPluginChannelId) { + return ((KeyedPluginChannelId) id).key().asString(); } else if (id instanceof PairedPluginChannelId) { if (version.gte(ProtocolVersion.MINECRAFT_1_13)) { return ((PairedPluginChannelId) id).modernChannelKey().asString(); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/VelocityChannelRegistrar.java b/proxy/src/main/java/com/velocitypowered/proxy/util/VelocityChannelRegistrar.java index e87795a3f..9eafa4852 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/util/VelocityChannelRegistrar.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/VelocityChannelRegistrar.java @@ -21,7 +21,7 @@ import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableSet; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.proxy.messages.ChannelRegistrar; -import com.velocitypowered.api.proxy.messages.MinecraftPluginChannelId; +import com.velocitypowered.api.proxy.messages.KeyedPluginChannelId; import com.velocitypowered.api.proxy.messages.PairedPluginChannelId; import com.velocitypowered.api.proxy.messages.PluginChannelId; import java.util.Collection; @@ -38,12 +38,12 @@ public class VelocityChannelRegistrar implements ChannelRegistrar { public void register(PluginChannelId... identifiers) { for (PluginChannelId identifier : identifiers) { Preconditions.checkArgument(identifier instanceof PairedPluginChannelId - || identifier instanceof MinecraftPluginChannelId, "identifier is unknown"); + || identifier instanceof KeyedPluginChannelId, "identifier is unknown"); } for (PluginChannelId identifier : identifiers) { - if (identifier instanceof MinecraftPluginChannelId) { - MinecraftPluginChannelId modern = (MinecraftPluginChannelId) identifier; + if (identifier instanceof KeyedPluginChannelId) { + KeyedPluginChannelId modern = (KeyedPluginChannelId) identifier; byLegacyId.put(modern.key().asString(), identifier); byKey.put(modern.key().asString(), identifier); } else { @@ -58,13 +58,13 @@ public class VelocityChannelRegistrar implements ChannelRegistrar { public void unregister(PluginChannelId... identifiers) { for (PluginChannelId identifier : identifiers) { Preconditions.checkArgument(identifier instanceof PairedPluginChannelId - || identifier instanceof MinecraftPluginChannelId, + || identifier instanceof KeyedPluginChannelId, "identifier is unknown"); } for (PluginChannelId identifier : identifiers) { - if (identifier instanceof MinecraftPluginChannelId) { - MinecraftPluginChannelId modern = (MinecraftPluginChannelId) identifier; + if (identifier instanceof KeyedPluginChannelId) { + KeyedPluginChannelId modern = (KeyedPluginChannelId) identifier; byKey.remove(modern.key().asString(), identifier); } else { PairedPluginChannelId paired = (PairedPluginChannelId) identifier; diff --git a/proxy/src/test/java/com/velocitypowered/proxy/util/VelocityChannelRegistrarTest.java b/proxy/src/test/java/com/velocitypowered/proxy/util/VelocityChannelRegistrarTest.java index a59d295ce..ed10149f9 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/util/VelocityChannelRegistrarTest.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/util/VelocityChannelRegistrarTest.java @@ -20,7 +20,7 @@ package com.velocitypowered.proxy.util; import static org.junit.jupiter.api.Assertions.assertEquals; import com.google.common.collect.ImmutableSet; -import com.velocitypowered.api.proxy.messages.MinecraftPluginChannelId; +import com.velocitypowered.api.proxy.messages.KeyedPluginChannelId; import com.velocitypowered.api.proxy.messages.PairedPluginChannelId; import com.velocitypowered.api.proxy.messages.PluginChannelId; import net.kyori.adventure.key.Key; @@ -28,7 +28,7 @@ import org.junit.jupiter.api.Test; class VelocityChannelRegistrarTest { - private static final MinecraftPluginChannelId MODERN = PluginChannelId.wrap( + private static final KeyedPluginChannelId MODERN = PluginChannelId.wrap( Key.key("velocity", "moderntest")); private static final PairedPluginChannelId SIMPLE_LEGACY = PluginChannelId.withLegacy("VelocityTest", Key.key("velocity", "test"));