Implement a connect callback - see #760
This commit is contained in:
parent
f7d3dfd61d
commit
075518b643
@ -1,5 +1,6 @@
|
||||
package net.md_5.bungee.api.connection;
|
||||
|
||||
import net.md_5.bungee.api.Callback;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.tab.TabListHandler;
|
||||
@ -35,6 +36,18 @@ public interface ProxiedPlayer extends Connection, CommandSender
|
||||
*/
|
||||
void connect(ServerInfo target);
|
||||
|
||||
/**
|
||||
* Connects / transfers this user to the specified connection, gracefully
|
||||
* closing the current one. Depending on the implementation, this method
|
||||
* might return before the user has been connected.
|
||||
*
|
||||
* @param target the new server to connect to
|
||||
* @param callback the method called when the connection is complete, or
|
||||
* when an exception is encountered. The boolean parameter denotes success
|
||||
* or failure.
|
||||
*/
|
||||
void connect(ServerInfo target, Callback<Boolean> callback);
|
||||
|
||||
/**
|
||||
* Gets the server this player is connected to.
|
||||
*
|
||||
|
@ -19,6 +19,7 @@ import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import net.md_5.bungee.api.Callback;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
@ -162,7 +163,13 @@ public final class UserConnection implements ProxiedPlayer
|
||||
@Override
|
||||
public void connect(ServerInfo target)
|
||||
{
|
||||
connect( target, false );
|
||||
connect( target, null );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connect(ServerInfo target, Callback<Boolean> callback)
|
||||
{
|
||||
connect( target, callback, false );
|
||||
}
|
||||
|
||||
void sendDimensionSwitch()
|
||||
@ -178,7 +185,7 @@ public final class UserConnection implements ProxiedPlayer
|
||||
connect( target );
|
||||
}
|
||||
|
||||
public void connect(ServerInfo info, final boolean retry)
|
||||
public void connect(ServerInfo info, final Callback<Boolean> callback, final boolean retry)
|
||||
{
|
||||
Preconditions.checkNotNull( info, "info" );
|
||||
|
||||
@ -219,6 +226,8 @@ public final class UserConnection implements ProxiedPlayer
|
||||
@Override
|
||||
public void operationComplete(ChannelFuture future) throws Exception
|
||||
{
|
||||
callback.done( future.isSuccess(), future.cause() );
|
||||
|
||||
if ( !future.isSuccess() )
|
||||
{
|
||||
future.channel().close();
|
||||
@ -228,7 +237,7 @@ public final class UserConnection implements ProxiedPlayer
|
||||
if ( retry && target != def && ( getServer() == null || def != getServer().getInfo() ) )
|
||||
{
|
||||
sendMessage( bungee.getTranslation( "fallback_lobby" ) );
|
||||
connect( def, false );
|
||||
connect( def, null, false );
|
||||
} else
|
||||
{
|
||||
if ( dimensionChange )
|
||||
|
@ -383,7 +383,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
|
||||
{
|
||||
server = AbstractReconnectHandler.getForcedHost( InitialHandler.this );
|
||||
}
|
||||
userCon.connect( server, true );
|
||||
userCon.connect( server, null, true );
|
||||
|
||||
thisState = State.FINISHED;
|
||||
}
|
||||
@ -419,7 +419,10 @@ public class InitialHandler extends PacketHandler implements PendingConnection
|
||||
@Override
|
||||
public void disconnect(BaseComponent reason)
|
||||
{
|
||||
disconnect( new BaseComponent[]{reason} );
|
||||
disconnect( new BaseComponent[]
|
||||
{
|
||||
reason
|
||||
} );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user