#2376 Add ServerConnectEvent Reason API

This commit is contained in:
Mystiflow
2018-03-14 15:13:10 +00:00
committed by md_5
parent d4bbe0d8db
commit 7241eb37c9
8 changed files with 118 additions and 22 deletions

View File

@@ -10,6 +10,7 @@ import net.md_5.bungee.api.SkinConfiguration;
import net.md_5.bungee.api.Title;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.event.ServerConnectEvent;
import net.md_5.bungee.api.score.Scoreboard;
/**
@@ -87,6 +88,15 @@ 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 reason the reason for connecting to the new server
*/
void connect(ServerInfo target, ServerConnectEvent.Reason reason);
/**
* Connects / transfers this user to the specified connection, gracefully
* closing the current one. Depending on the implementation, this method
@@ -99,6 +109,19 @@ public interface ProxiedPlayer extends Connection, CommandSender
*/
void connect(ServerInfo target, Callback<Boolean> callback);
/**
* 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.
* @param reason the reason for connecting to the new server
*/
void connect(ServerInfo target, Callback<Boolean> callback, ServerConnectEvent.Reason reason);
/**
* Gets the server this player is connected to.
*

View File

@@ -34,10 +34,57 @@ public class ServerConnectEvent extends Event implements Cancellable
* Cancelled state.
*/
private boolean cancelled;
private final Reason reason;
@Deprecated
public ServerConnectEvent(ProxiedPlayer player, ServerInfo target)
{
this( player, target, Reason.UNKNOWN );
}
public ServerConnectEvent(ProxiedPlayer player, ServerInfo target, Reason reason)
{
this.player = player;
this.target = target;
this.reason = reason;
}
public enum Reason
{
/**
* Redirection to lobby server due to being unable to connect to
* original server
*/
LOBBY_FALLBACK,
/**
* Execution of a command
*/
COMMAND,
/**
* Redirecting to another server when client loses connection to server
* due to an exception.
*/
SERVER_DOWN_REDIRECT,
/**
* Redirecting to another server when kicked from original server.
*/
KICK_REDIRECT,
/**
* Plugin message request.
*/
PLUGIN_MESSAGE,
/**
* Initial proxy connect.
*/
JOIN_PROXY,
/**
* Plugin initiated connect.
*/
PLUGIN,
/**
* Unknown cause.
*/
UNKNOWN
}
}