Make the ServerConnectedEvent async to allow stalling it. Closes #538 by @BjoernAkAManf.
This commit is contained in:
parent
4463b0c1b2
commit
f07cfe0cf7
@ -3,9 +3,9 @@ package net.md_5.bungee.api.event;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import net.md_5.bungee.api.Callback;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.connection.Server;
|
||||
import net.md_5.bungee.api.plugin.Event;
|
||||
|
||||
/**
|
||||
* Not to be confused with {@link ServerConnectEvent}, this event is called once
|
||||
@ -16,7 +16,7 @@ import net.md_5.bungee.api.plugin.Event;
|
||||
@Data
|
||||
@ToString(callSuper = false)
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class ServerConnectedEvent extends Event
|
||||
public class ServerConnectedEvent extends AsyncEvent<ServerConnectedEvent>
|
||||
{
|
||||
|
||||
/**
|
||||
@ -27,4 +27,11 @@ public class ServerConnectedEvent extends Event
|
||||
* The server itself.
|
||||
*/
|
||||
private final Server server;
|
||||
|
||||
public ServerConnectedEvent(ProxiedPlayer player, Server server, Callback<ServerConnectedEvent> done)
|
||||
{
|
||||
super( done );
|
||||
this.player = player;
|
||||
this.server = server;
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import java.util.Queue;
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.SecretKey;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.md_5.bungee.api.Callback;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
@ -99,13 +100,16 @@ public class ServerConnector extends PacketHandler
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(Packet1Login login) throws Exception
|
||||
public void handle(final Packet1Login login) throws Exception
|
||||
{
|
||||
Preconditions.checkState( thisState == State.LOGIN, "Not exepcting LOGIN" );
|
||||
|
||||
ServerConnection server = new ServerConnection( ch, target );
|
||||
ServerConnectedEvent event = new ServerConnectedEvent( user, server );
|
||||
bungee.getPluginManager().callEvent( event );
|
||||
final ServerConnection server = new ServerConnection( ch, target );
|
||||
Callback<ServerConnectedEvent> callback = new Callback<ServerConnectedEvent>()
|
||||
{
|
||||
@Override
|
||||
public void done(ServerConnectedEvent result, Throwable error)
|
||||
{
|
||||
|
||||
ch.write( BungeeCord.getInstance().registerChannels() );
|
||||
Queue<DefinedPacket> packetQueue = target.getPacketQueue();
|
||||
@ -204,6 +208,11 @@ public class ServerConnector extends PacketHandler
|
||||
bungee.getPluginManager().callEvent( new ServerSwitchEvent( user ) );
|
||||
|
||||
thisState = State.FINISHED;
|
||||
}
|
||||
};
|
||||
|
||||
ServerConnectedEvent event = new ServerConnectedEvent( user, server, callback );
|
||||
bungee.getPluginManager().callEvent( event );
|
||||
|
||||
throw new CancelSendSignal();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user