#3628: Convert PostLoginEvent to AsyncEvent and expose target server
This commit is contained in:
parent
d6c5197cb9
commit
17e23d5c3f
@ -3,8 +3,9 @@ package net.md_5.bungee.api.event;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
import net.md_5.bungee.api.Callback;
|
||||||
|
import net.md_5.bungee.api.config.ServerInfo;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
import net.md_5.bungee.api.plugin.Event;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Event called as soon as a connection has a {@link ProxiedPlayer} and is ready
|
* Event called as soon as a connection has a {@link ProxiedPlayer} and is ready
|
||||||
@ -13,11 +14,22 @@ import net.md_5.bungee.api.plugin.Event;
|
|||||||
@Data
|
@Data
|
||||||
@ToString(callSuper = false)
|
@ToString(callSuper = false)
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
public class PostLoginEvent extends Event
|
public class PostLoginEvent extends AsyncEvent<PostLoginEvent>
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The player involved with this event.
|
* The player involved with this event.
|
||||||
*/
|
*/
|
||||||
private final ProxiedPlayer player;
|
private final ProxiedPlayer player;
|
||||||
|
/**
|
||||||
|
* The server to which the player will initially be connected.
|
||||||
|
*/
|
||||||
|
private ServerInfo target;
|
||||||
|
|
||||||
|
public PostLoginEvent(ProxiedPlayer player, ServerInfo target, Callback<PostLoginEvent> done)
|
||||||
|
{
|
||||||
|
super( done );
|
||||||
|
this.player = player;
|
||||||
|
this.target = target;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -652,28 +652,37 @@ public class InitialHandler extends PacketHandler implements PendingConnection
|
|||||||
}
|
}
|
||||||
|
|
||||||
ch.getHandle().pipeline().get( HandlerBoss.class ).setHandler( new UpstreamBridge( bungee, userCon ) );
|
ch.getHandle().pipeline().get( HandlerBoss.class ).setHandler( new UpstreamBridge( bungee, userCon ) );
|
||||||
bungee.getPluginManager().callEvent( new PostLoginEvent( userCon ) );
|
|
||||||
|
|
||||||
|
ServerInfo initialServer;
|
||||||
|
if ( bungee.getReconnectHandler() != null )
|
||||||
|
{
|
||||||
|
initialServer = bungee.getReconnectHandler().getServer( userCon );
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
initialServer = AbstractReconnectHandler.getForcedHost( InitialHandler.this );
|
||||||
|
}
|
||||||
|
if ( initialServer == null )
|
||||||
|
{
|
||||||
|
initialServer = bungee.getServerInfo( listener.getDefaultServer() );
|
||||||
|
}
|
||||||
|
|
||||||
|
Callback<PostLoginEvent> complete = new Callback<PostLoginEvent>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void done(PostLoginEvent result, Throwable error)
|
||||||
|
{
|
||||||
// #3612: Don't progress further if disconnected during event
|
// #3612: Don't progress further if disconnected during event
|
||||||
if ( ch.isClosed() )
|
if ( ch.isClosed() )
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerInfo server;
|
userCon.connect( result.getTarget(), null, true, ServerConnectEvent.Reason.JOIN_PROXY );
|
||||||
if ( bungee.getReconnectHandler() != null )
|
|
||||||
{
|
|
||||||
server = bungee.getReconnectHandler().getServer( userCon );
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
server = AbstractReconnectHandler.getForcedHost( InitialHandler.this );
|
|
||||||
}
|
|
||||||
if ( server == null )
|
|
||||||
{
|
|
||||||
server = bungee.getServerInfo( listener.getDefaultServer() );
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
userCon.connect( server, null, true, ServerConnectEvent.Reason.JOIN_PROXY );
|
// fire post-login event
|
||||||
|
bungee.getPluginManager().callEvent( new PostLoginEvent( userCon, initialServer, complete ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user