From f1c32f84f46589632d7721d8de87d5589ef8e6a6 Mon Sep 17 00:00:00 2001 From: Mystiflow Date: Wed, 25 Mar 2020 18:19:55 +1100 Subject: [PATCH] #2379: Add ServerSwitchEvent getFrom API --- .../java/net/md_5/bungee/api/event/ServerSwitchEvent.java | 6 ++++++ proxy/src/main/java/net/md_5/bungee/ServerConnector.java | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/api/src/main/java/net/md_5/bungee/api/event/ServerSwitchEvent.java b/api/src/main/java/net/md_5/bungee/api/event/ServerSwitchEvent.java index 4722517a..4414ec79 100644 --- a/api/src/main/java/net/md_5/bungee/api/event/ServerSwitchEvent.java +++ b/api/src/main/java/net/md_5/bungee/api/event/ServerSwitchEvent.java @@ -3,6 +3,7 @@ package net.md_5.bungee.api.event; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; +import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.plugin.Event; @@ -19,4 +20,9 @@ public class ServerSwitchEvent extends Event * Player whom the server is for. */ private final ProxiedPlayer player; + /** + * Server the player is switch from. May be null if initial proxy + * connection. + */ + private final ServerInfo from; } diff --git a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java index 65d4b0b1..28b0ac9d 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java @@ -292,10 +292,11 @@ public class ServerConnector extends PacketHandler user.setServerJoinQueue( null ); user.setDimensionChange( false ); + ServerInfo from = ( user.getServer() == null ) ? null : user.getServer().getInfo(); user.setServer( server ); ch.getHandle().pipeline().get( HandlerBoss.class ).setHandler( new DownstreamBridge( bungee, user, server ) ); - bungee.getPluginManager().callEvent( new ServerSwitchEvent( user ) ); + bungee.getPluginManager().callEvent( new ServerSwitchEvent( user, from ) ); thisState = State.FINISHED;