fix: fixed legacy minecraft version plugin message sending
This commit is contained in:
parent
a500090723
commit
afda8ecbc3
@ -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),
|
||||
|
@ -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");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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");
|
||||
|
Loading…
x
Reference in New Issue
Block a user