From fff5598704b2d59fd2e0b1a48b0b157aa27589e0 Mon Sep 17 00:00:00 2001 From: sk89q Date: Mon, 26 Sep 2011 15:32:01 -0700 Subject: Added server list ping event. --- src/main/java/org/bukkit/event/Event.java | 6 ++ .../bukkit/event/server/ServerListPingEvent.java | 80 ++++++++++++++++++++++ .../org/bukkit/event/server/ServerListener.java | 7 ++ .../org/bukkit/plugin/java/JavaPluginLoader.java | 7 ++ 4 files changed, 100 insertions(+) create mode 100644 src/main/java/org/bukkit/event/server/ServerListPingEvent.java diff --git a/src/main/java/org/bukkit/event/Event.java b/src/main/java/org/bukkit/event/Event.java index eb4c87d8..80e28132 100644 --- a/src/main/java/org/bukkit/event/Event.java +++ b/src/main/java/org/bukkit/event/Event.java @@ -504,6 +504,12 @@ public abstract class Event implements Serializable { * @see org.bukkit.event.server.MapInitializeEvent */ MAP_INITIALIZE (Category.SERVER), + /** + * Called when a client pings a server. + * + * @see org.bukkit.event.server.ServerListPingEvent + */ + SERVER_LIST_PING (Category.SERVER), /** * WORLD EVENTS diff --git a/src/main/java/org/bukkit/event/server/ServerListPingEvent.java b/src/main/java/org/bukkit/event/server/ServerListPingEvent.java new file mode 100644 index 00000000..b1f588f1 --- /dev/null +++ b/src/main/java/org/bukkit/event/server/ServerListPingEvent.java @@ -0,0 +1,80 @@ +package org.bukkit.event.server; + +import java.net.InetAddress; + +import org.bukkit.event.Event; + +/** + * Called when a server list ping is coming in. + * + * @author sk89q + */ +public class ServerListPingEvent extends ServerEvent { + + private InetAddress address; + private String motd; + private int numPlayers; + private int maxPlayers; + + public ServerListPingEvent(InetAddress address, String motd, int numPlayers, int maxPlayers) { + super(Event.Type.SERVER_LIST_PING); + this.address = address; + this.motd = motd; + this.numPlayers = numPlayers; + this.maxPlayers = maxPlayers; + } + + /** + * Get the address the ping is coming from. + * + * @return the address + */ + public InetAddress getAddress() { + return address; + } + + /** + * Get the message of the day message. + * + * @return the message of the day + */ + public String getMotd() { + return motd; + } + + /** + * Change the message of the day message. + * + * @param motd the message of the day + */ + public void setMotd(String motd) { + this.motd = motd; + } + + /** + * Get the number of players sent. + * + * @return the number of players + */ + public int getNumPlayers() { + return numPlayers; + } + + /** + * Get the maximum number of players sent. + * + * @return the the maximum number of player + */ + public int getMaxPlayers() { + return maxPlayers; + } + + /** + * Set the maximum number of players sent. + * + * @param maxPlayers the maximum number of player + */ + public void setMaxPlayers(int maxPlayers) { + this.maxPlayers = maxPlayers; + } +} diff --git a/src/main/java/org/bukkit/event/server/ServerListener.java b/src/main/java/org/bukkit/event/server/ServerListener.java index f4bf722a..d49b1e0a 100644 --- a/src/main/java/org/bukkit/event/server/ServerListener.java +++ b/src/main/java/org/bukkit/event/server/ServerListener.java @@ -34,4 +34,11 @@ public class ServerListener implements Listener { * @param event Relevant event details */ public void onMapInitialize(MapInitializeEvent event) {} + + /** + * Called when a server list ping has come in. + * + * @param event Relevant event details + */ + public void onServerListPing(ServerListPingEvent event) {} } diff --git a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java index 33d8bbe6..5489b852 100644 --- a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java +++ b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java @@ -584,6 +584,13 @@ public class JavaPluginLoader implements PluginLoader { } }; + case SERVER_LIST_PING: + return new EventExecutor() { + public void execute(Listener listener, Event event) { + ((ServerListener) listener).onServerListPing((ServerListPingEvent) event); + } + }; + // World Events case CHUNK_LOAD: return new EventExecutor() { -- cgit v1.2.3