mirror of
https://github.com/SpigotMC/BungeeCord.git
synced 2024-12-26 02:27:56 +01:00
Revert "#2447: Add API for fluent server connect requests"
This reverts commit 7ce9ae50e7
.
This commit is contained in:
parent
95ed7a5775
commit
c9f22868b3
@ -1,101 +0,0 @@
|
|||||||
package net.md_5.bungee.api;
|
|
||||||
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.NonNull;
|
|
||||||
import net.md_5.bungee.api.config.ServerInfo;
|
|
||||||
import net.md_5.bungee.api.event.ServerConnectEvent;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A request to connect a server.
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
@Builder
|
|
||||||
public class ServerConnectRequest
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The result from this callback after request has been executed by proxy.
|
|
||||||
*/
|
|
||||||
public enum Result
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ServerConnectEvent to the new server was canceled.
|
|
||||||
*/
|
|
||||||
EVENT_CANCEL,
|
|
||||||
/**
|
|
||||||
* Already connected to target server.
|
|
||||||
*/
|
|
||||||
ALREADY_CONNECTED,
|
|
||||||
/**
|
|
||||||
* Already connecting to target server.
|
|
||||||
*/
|
|
||||||
ALREADY_CONNECTING,
|
|
||||||
/**
|
|
||||||
* Successfully connected to server.
|
|
||||||
*/
|
|
||||||
SUCCESS,
|
|
||||||
/**
|
|
||||||
* Connection failed, error can be accessed from callback method handle.
|
|
||||||
*/
|
|
||||||
FAIL
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Target server to connect to.
|
|
||||||
*/
|
|
||||||
@NonNull
|
|
||||||
private final ServerInfo target;
|
|
||||||
/**
|
|
||||||
* Reason for connecting to server.
|
|
||||||
*/
|
|
||||||
@NonNull
|
|
||||||
private final ServerConnectEvent.Reason reason;
|
|
||||||
/**
|
|
||||||
* Callback to execute post request.
|
|
||||||
*/
|
|
||||||
private final Callback<Result> result;
|
|
||||||
/**
|
|
||||||
* Timeout in milliseconds for request.
|
|
||||||
*/
|
|
||||||
private final int connectTimeout;
|
|
||||||
/**
|
|
||||||
* Should the player be attempted to connect to the next server in their
|
|
||||||
* queue if the initial request fails.
|
|
||||||
*/
|
|
||||||
private final boolean retry;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class that sets default properties/adds methods to the lombok builder
|
|
||||||
* generated class.
|
|
||||||
*/
|
|
||||||
public static class ServerConnectRequestBuilder
|
|
||||||
{
|
|
||||||
|
|
||||||
private Callback<Result> result;
|
|
||||||
private int connectTimeout = 5000; // TODO: Configurable
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the callback to execute on explicit succession of the request.
|
|
||||||
*
|
|
||||||
* @param callback the callback to execute
|
|
||||||
* @return this builder for chaining
|
|
||||||
* @deprecated recommended to use callback providing generic type of
|
|
||||||
* {@link Result}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public ServerConnectRequestBuilder callback(final Callback<Boolean> callback)
|
|
||||||
{
|
|
||||||
this.result = new Callback<Result>()
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void done(final Result result, final Throwable error)
|
|
||||||
{
|
|
||||||
callback.done( ( result == Result.SUCCESS ) ? Boolean.TRUE : Boolean.FALSE, error );
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -6,7 +6,6 @@ import java.util.UUID;
|
|||||||
import net.md_5.bungee.api.Callback;
|
import net.md_5.bungee.api.Callback;
|
||||||
import net.md_5.bungee.api.ChatMessageType;
|
import net.md_5.bungee.api.ChatMessageType;
|
||||||
import net.md_5.bungee.api.CommandSender;
|
import net.md_5.bungee.api.CommandSender;
|
||||||
import net.md_5.bungee.api.ServerConnectRequest;
|
|
||||||
import net.md_5.bungee.api.SkinConfiguration;
|
import net.md_5.bungee.api.SkinConfiguration;
|
||||||
import net.md_5.bungee.api.Title;
|
import net.md_5.bungee.api.Title;
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
@ -124,15 +123,6 @@ public interface ProxiedPlayer extends Connection, CommandSender
|
|||||||
*/
|
*/
|
||||||
void connect(ServerInfo target, Callback<Boolean> callback, ServerConnectEvent.Reason reason);
|
void connect(ServerInfo target, Callback<Boolean> callback, ServerConnectEvent.Reason reason);
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 request request to connect with
|
|
||||||
*/
|
|
||||||
void connect(ServerConnectRequest request);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the server this player is connected to.
|
* Gets the server this player is connected to.
|
||||||
*
|
*
|
||||||
|
@ -27,7 +27,6 @@ import lombok.Setter;
|
|||||||
import net.md_5.bungee.api.Callback;
|
import net.md_5.bungee.api.Callback;
|
||||||
import net.md_5.bungee.api.ChatMessageType;
|
import net.md_5.bungee.api.ChatMessageType;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
import net.md_5.bungee.api.ServerConnectRequest;
|
|
||||||
import net.md_5.bungee.api.SkinConfiguration;
|
import net.md_5.bungee.api.SkinConfiguration;
|
||||||
import net.md_5.bungee.api.Title;
|
import net.md_5.bungee.api.Title;
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
@ -254,21 +253,12 @@ public final class UserConnection implements ProxiedPlayer
|
|||||||
{
|
{
|
||||||
Preconditions.checkNotNull( info, "info" );
|
Preconditions.checkNotNull( info, "info" );
|
||||||
|
|
||||||
connect( ServerConnectRequest.builder().callback( callback ).retry( retry ).reason( reason ).target( info ).build() );
|
ServerConnectEvent event = new ServerConnectEvent( this, info, reason );
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void connect(final ServerConnectRequest request)
|
|
||||||
{
|
|
||||||
Preconditions.checkNotNull( request, "request" );
|
|
||||||
|
|
||||||
final Callback<ServerConnectRequest.Result> callback = request.getResult();
|
|
||||||
ServerConnectEvent event = new ServerConnectEvent( this, request.getTarget(), request.getReason() );
|
|
||||||
if ( bungee.getPluginManager().callEvent( event ).isCancelled() )
|
if ( bungee.getPluginManager().callEvent( event ).isCancelled() )
|
||||||
{
|
{
|
||||||
if ( callback != null )
|
if ( callback != null )
|
||||||
{
|
{
|
||||||
callback.done( ServerConnectRequest.Result.EVENT_CANCEL, null );
|
callback.done( false, null );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( getServer() == null && !ch.isClosing() )
|
if ( getServer() == null && !ch.isClosing() )
|
||||||
@ -284,7 +274,7 @@ public final class UserConnection implements ProxiedPlayer
|
|||||||
{
|
{
|
||||||
if ( callback != null )
|
if ( callback != null )
|
||||||
{
|
{
|
||||||
callback.done( ServerConnectRequest.Result.ALREADY_CONNECTED, null );
|
callback.done( false, null );
|
||||||
}
|
}
|
||||||
|
|
||||||
sendMessage( bungee.getTranslation( "already_connected" ) );
|
sendMessage( bungee.getTranslation( "already_connected" ) );
|
||||||
@ -294,7 +284,7 @@ public final class UserConnection implements ProxiedPlayer
|
|||||||
{
|
{
|
||||||
if ( callback != null )
|
if ( callback != null )
|
||||||
{
|
{
|
||||||
callback.done( ServerConnectRequest.Result.ALREADY_CONNECTING, null );
|
callback.done( false, null );
|
||||||
}
|
}
|
||||||
|
|
||||||
sendMessage( bungee.getTranslation( "already_connecting" ) );
|
sendMessage( bungee.getTranslation( "already_connecting" ) );
|
||||||
@ -322,7 +312,7 @@ public final class UserConnection implements ProxiedPlayer
|
|||||||
{
|
{
|
||||||
if ( callback != null )
|
if ( callback != null )
|
||||||
{
|
{
|
||||||
callback.done( ( future.isSuccess() ) ? ServerConnectRequest.Result.SUCCESS : ServerConnectRequest.Result.FAIL, future.cause() );
|
callback.done( future.isSuccess(), future.cause() );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !future.isSuccess() )
|
if ( !future.isSuccess() )
|
||||||
@ -331,7 +321,7 @@ public final class UserConnection implements ProxiedPlayer
|
|||||||
pendingConnects.remove( target );
|
pendingConnects.remove( target );
|
||||||
|
|
||||||
ServerInfo def = updateAndGetNextServer( target );
|
ServerInfo def = updateAndGetNextServer( target );
|
||||||
if ( request.isRetry() && def != null && ( getServer() == null || def != getServer().getInfo() ) )
|
if ( retry && def != null && ( getServer() == null || def != getServer().getInfo() ) )
|
||||||
{
|
{
|
||||||
sendMessage( bungee.getTranslation( "fallback_lobby" ) );
|
sendMessage( bungee.getTranslation( "fallback_lobby" ) );
|
||||||
connect( def, null, true, ServerConnectEvent.Reason.LOBBY_FALLBACK );
|
connect( def, null, true, ServerConnectEvent.Reason.LOBBY_FALLBACK );
|
||||||
@ -349,7 +339,7 @@ public final class UserConnection implements ProxiedPlayer
|
|||||||
.channel( PipelineUtils.getChannel() )
|
.channel( PipelineUtils.getChannel() )
|
||||||
.group( ch.getHandle().eventLoop() )
|
.group( ch.getHandle().eventLoop() )
|
||||||
.handler( initializer )
|
.handler( initializer )
|
||||||
.option( ChannelOption.CONNECT_TIMEOUT_MILLIS, request.getConnectTimeout() )
|
.option( ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000 ) // TODO: Configurable
|
||||||
.remoteAddress( target.getAddress() );
|
.remoteAddress( target.getAddress() );
|
||||||
// Windows is bugged, multi homed users will just have to live with random connecting IPs
|
// Windows is bugged, multi homed users will just have to live with random connecting IPs
|
||||||
if ( getPendingConnection().getListener().isSetLocalAddress() && !PlatformDependent.isWindows() )
|
if ( getPendingConnection().getListener().isSetLocalAddress() && !PlatformDependent.isWindows() )
|
||||||
|
Loading…
Reference in New Issue
Block a user