From afda8ecbc344bc811321fa7f9c3ed7594b81a38f Mon Sep 17 00:00:00 2001 From: Adrian Date: Fri, 3 Mar 2023 15:57:43 -0500 Subject: [PATCH] fix: fixed legacy minecraft version plugin message sending --- .../authmevelocity/velocity/AuthMeVelocityPlugin.java | 7 +++++-- .../velocity/listener/ConnectListener.java | 10 ++++++++-- .../velocity/listener/PluginMessageListener.java | 3 ++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/AuthMeVelocityPlugin.java b/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/AuthMeVelocityPlugin.java index 38ce207..d0971bb 100644 --- a/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/AuthMeVelocityPlugin.java +++ b/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/AuthMeVelocityPlugin.java @@ -28,6 +28,7 @@ import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.ProxyServer; import com.velocitypowered.api.proxy.ServerConnection; import com.velocitypowered.api.proxy.messages.ChannelIdentifier; +import com.velocitypowered.api.proxy.messages.LegacyChannelIdentifier; import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier; import com.velocitypowered.api.proxy.server.RegisteredServer; import io.github._4drian3d.authmevelocity.api.velocity.AuthMeVelocityAPI; @@ -74,8 +75,10 @@ import java.util.function.Predicate; } ) public final class AuthMeVelocityPlugin implements AuthMeVelocityAPI { - public static final ChannelIdentifier AUTHMEVELOCITY_CHANNEL + public static final ChannelIdentifier MODERN_CHANNEL = MinecraftChannelIdentifier.create("authmevelocity", "main"); + public static final ChannelIdentifier LEGACY_CHANNEL + = new LegacyChannelIdentifier("authmevelocity:main"); @Inject private ProxyServer proxy; @Inject @@ -109,7 +112,7 @@ public final class AuthMeVelocityPlugin implements AuthMeVelocityAPI { final int pluginId = 16128; final Metrics metrics = metricsFactory.make(this, pluginId); - proxy.getChannelRegistrar().register(AUTHMEVELOCITY_CHANNEL); + proxy.getChannelRegistrar().register(MODERN_CHANNEL, LEGACY_CHANNEL); List.of( new ProxyListener(this), diff --git a/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/listener/ConnectListener.java b/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/listener/ConnectListener.java index dee9c9a..3835d7b 100644 --- a/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/listener/ConnectListener.java +++ b/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/listener/ConnectListener.java @@ -106,8 +106,14 @@ public final class ConnectListener { plugin.logDebug("ServerPostConnectEvent | Already logged player and connected to an Auth server"); final ByteArrayDataOutput buf = ByteStreams.newDataOutput(); buf.writeUTF("LOGIN"); - player.getCurrentServer().ifPresent(sv -> - sv.sendPluginMessage(AuthMeVelocityPlugin.AUTHMEVELOCITY_CHANNEL, buf.toByteArray())); + player.getCurrentServer().ifPresent(sv -> { + var byteArray = buf.toByteArray(); + if (!sv.sendPluginMessage(AuthMeVelocityPlugin.MODERN_CHANNEL, byteArray)) { + plugin.logDebug("ServerPostConnectEvent | Failed to send on Modern Channel"); + var legacyResult = sv.sendPluginMessage(AuthMeVelocityPlugin.LEGACY_CHANNEL, byteArray); + if(!legacyResult) plugin.logDebug("ServerPostConnectEvent | Failed to send on Legacy Channel"); + } + }); } } } diff --git a/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/listener/PluginMessageListener.java b/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/listener/PluginMessageListener.java index 608b95a..2ca3ead 100644 --- a/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/listener/PluginMessageListener.java +++ b/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/listener/PluginMessageListener.java @@ -50,7 +50,8 @@ public class PluginMessageListener { public void onPluginMessage(final PluginMessageEvent event, Continuation continuation) { final boolean cancelled = !event.getResult().isAllowed() || !(event.getSource() instanceof ServerConnection) - || !event.getIdentifier().equals(AuthMeVelocityPlugin.AUTHMEVELOCITY_CHANNEL); + || !(event.getIdentifier().equals(AuthMeVelocityPlugin.MODERN_CHANNEL) + || event.getIdentifier().equals(AuthMeVelocityPlugin.LEGACY_CHANNEL)); if (cancelled) { continuation.resume(); plugin.logDebug("PluginMessageEvent | Not allowed");