Add new event for @mbax

This commit is contained in:
md_5 2012-11-02 09:19:55 +11:00
parent 30abf975c2
commit 6f005064a1
4 changed files with 46 additions and 1 deletions

View File

@ -15,6 +15,7 @@ import net.md_5.bungee.packet.Packet3Chat;
import net.md_5.bungee.packet.Packet9Respawn;
import net.md_5.bungee.packet.PacketFAPluginMessage;
import net.md_5.bungee.packet.PacketInputStream;
import net.md_5.bungee.plugin.ServerConnectEvent;
public class UserConnection extends GenericConnection implements CommandSender
{
@ -39,7 +40,10 @@ public class UserConnection extends GenericConnection implements CommandSender
public void connect(String server)
{
InetSocketAddress addr = BungeeCord.instance.config.getServer(server);
ServerConnectEvent event = new ServerConnectEvent(this, server);
event.setNewServer(server);
BungeeCord.instance.pluginManager.onServerConnect(event);
InetSocketAddress addr = BungeeCord.instance.config.getServer(event.getNewServer());
connect(server, addr);
}

View File

@ -44,6 +44,13 @@ public abstract class JavaPlugin
{
}
/**
* Called when a user is connecting to a new server.
*/
public void onServerConnect(ServerConnectEvent event)
{
}
/**
* Register a command for use with the proxy.
*/

View File

@ -97,4 +97,13 @@ public class JavaPluginManager extends JavaPlugin
p.onLogin(event);
}
}
@Override
public void onServerConnect(ServerConnectEvent event)
{
for (JavaPlugin p : plugins)
{
p.onServerConnect(event);
}
}
}

View File

@ -0,0 +1,25 @@
package net.md_5.bungee.plugin;
import lombok.Data;
import net.md_5.bungee.UserConnection;
/**
* Event called when the decision is made to decide which server to connect to.
*/
@Data
public class ServerConnectEvent
{
/**
* User in question.
*/
private final UserConnection connection;
/**
* Name of the server they are connecting to.
*/
private final String server;
/**
* Name of the server which they will be forwarded to instead.
*/
private String newServer;
}