From 9ce148681d246dd82eaf21bec6fc22821f66e4ea Mon Sep 17 00:00:00 2001 From: md_5 Date: Sun, 20 Jan 2013 15:02:45 +1100 Subject: [PATCH] Add server connected event --- .../api/event/ServerConnectedEvent.java | 30 +++++++++++++++++++ .../net/md_5/bungee/ServerConnection.java | 7 ++++- 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 api/src/main/java/net/md_5/bungee/api/event/ServerConnectedEvent.java diff --git a/api/src/main/java/net/md_5/bungee/api/event/ServerConnectedEvent.java b/api/src/main/java/net/md_5/bungee/api/event/ServerConnectedEvent.java new file mode 100644 index 00000000..e8370b88 --- /dev/null +++ b/api/src/main/java/net/md_5/bungee/api/event/ServerConnectedEvent.java @@ -0,0 +1,30 @@ +package net.md_5.bungee.api.event; + +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; +import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.api.connection.Server; +import net.md_5.bungee.api.plugin.Event; + +/** + * Not to be confused with {@link ServerConnectEvent}, this event is called once + * a connection to a server is fully operational, and is about to hand over + * control of the session to the player. It is useful if you wish to send + * information to the server before the player logs in. + */ +@Data +@ToString(callSuper = true) +@EqualsAndHashCode(callSuper = true) +public class ServerConnectedEvent extends Event +{ + + /** + * Player whom the server is for. + */ + private final ProxiedPlayer player; + /** + * The server itself. + */ + private final Server server; +} diff --git a/proxy/src/main/java/net/md_5/bungee/ServerConnection.java b/proxy/src/main/java/net/md_5/bungee/ServerConnection.java index 1a56ab2c..415003f7 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnection.java @@ -8,9 +8,11 @@ import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; import javax.crypto.SecretKey; import net.md_5.bungee.api.Callback; +import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.ServerPing; import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.Server; +import net.md_5.bungee.api.event.ServerConnectedEvent; import net.md_5.bungee.packet.DefinedPacket; import net.md_5.bungee.packet.Packet1Login; import net.md_5.bungee.packet.Packet2Handshake; @@ -81,7 +83,10 @@ public class ServerConnection extends GenericConnection implements Server } Packet1Login login = new Packet1Login(loginResponse); - return new ServerConnection(name, socket, in, out, login); + ServerConnection server = new ServerConnection(name, socket, in, out, login); + ServerConnectedEvent event = new ServerConnectedEvent(user, server); + ProxyServer.getInstance().getPluginManager().callEvent(event); + return server; } catch (KickException ex) { throw ex;