Fixed PreLoginEvent, LoginEvent support for bungee

This commit is contained in:
LAX1DUDE 2022-12-26 18:58:57 -08:00
parent 9555cac002
commit 45230ab32c
2 changed files with 20 additions and 5 deletions

View File

@ -63,6 +63,7 @@ import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.event.LoginEvent; import net.md_5.bungee.api.event.LoginEvent;
import net.md_5.bungee.api.event.PostLoginEvent; import net.md_5.bungee.api.event.PostLoginEvent;
import net.md_5.bungee.api.event.PreLoginEvent;
import net.md_5.bungee.chat.ComponentSerializer; import net.md_5.bungee.chat.ComponentSerializer;
import net.md_5.bungee.connection.LoginResult; import net.md_5.bungee.connection.LoginResult;
import net.md_5.bungee.connection.UpstreamBridge; import net.md_5.bungee.connection.UpstreamBridge;
@ -701,11 +702,12 @@ public class HttpWebSocketHandler extends ChannelInboundHandlerAdapter {
} }
final EaglerInitialHandler initialHandler = new EaglerInitialHandler(bungee, conf, ch, gameProtocolVersion, final EaglerInitialHandler initialHandler = new EaglerInitialHandler(bungee, conf, ch, gameProtocolVersion,
usernameStr, clientUUID, baseAddress, ctx.channel().attr(EaglerPipeline.HOST).get()); usernameStr, clientUUID, baseAddress, ctx.channel().attr(EaglerPipeline.HOST).get());
Callback<LoginEvent> complete = (Callback<LoginEvent>) new Callback<LoginEvent>() { final Callback<LoginEvent> complete = (Callback<LoginEvent>) new Callback<LoginEvent>() {
public void done(final LoginEvent result, final Throwable error) { public void done(final LoginEvent result, final Throwable error) {
if (result.isCancelled()) { if (result.isCancelled()) {
final BaseComponent[] reason = result.getCancelReasonComponents(); final BaseComponent[] reason = result.getCancelReasonComponents();
sendLoginDenied(ctx, ComponentSerializer.toString(reason != null ? reason sendErrorCode(ctx, HandshakePacketTypes.SERVER_ERROR_CUSTOM_MESSAGE,
ComponentSerializer.toString(reason != null ? reason
: TextComponent.fromLegacyText(bungee.getTranslation("kick_message", new Object[0])))) : TextComponent.fromLegacyText(bungee.getTranslation("kick_message", new Object[0]))))
.addListener(ChannelFutureListener.CLOSE); .addListener(ChannelFutureListener.CLOSE);
return; return;
@ -872,8 +874,21 @@ public class HttpWebSocketHandler extends ChannelInboundHandlerAdapter {
}); });
} }
}; };
final Callback<PreLoginEvent> completePre = new Callback<PreLoginEvent>() {
public void done(PreLoginEvent var1, Throwable var2) {
if (var1.isCancelled()) {
final BaseComponent[] reason = var1.getCancelReasonComponents();
sendErrorCode(ctx, HandshakePacketTypes.SERVER_ERROR_CUSTOM_MESSAGE,
ComponentSerializer.toString(reason != null ? reason
: TextComponent.fromLegacyText(bungee.getTranslation("kick_message", new Object[0]))))
.addListener(ChannelFutureListener.CLOSE);
}else {
bungee.getPluginManager().callEvent(new LoginEvent(initialHandler, complete)); bungee.getPluginManager().callEvent(new LoginEvent(initialHandler, complete));
} }
}
};
bungee.getPluginManager().callEvent(new PreLoginEvent(initialHandler, completePre));
}
private static class EventException extends RuntimeException { private static class EventException extends RuntimeException {
public EventException(Throwable t) { public EventException(Throwable t) {