diff --git a/api/src/main/java/net/md_5/bungee/api/ProxyConnection.java b/api/src/main/java/net/md_5/bungee/api/ProxyConnection.java new file mode 100644 index 00000000..c6ba8bee --- /dev/null +++ b/api/src/main/java/net/md_5/bungee/api/ProxyConnection.java @@ -0,0 +1,18 @@ +package net.md_5.bungee.api; + +import java.net.InetSocketAddress; + +/** + * A proxy connection is defined as a connection directly connected to a socket. + * It should expose information about the remote peer, however not be specific + * to a type of connection, whether server or player. + */ +public abstract class ProxyConnection { + + /** + * Gets the remote address of this connection. + * + * @return the remote address + */ + public abstract InetSocketAddress getAddress(); +} diff --git a/api/src/main/java/net/md_5/bungee/api/ProxyServer.java b/api/src/main/java/net/md_5/bungee/api/ProxyServer.java index 1de8da1a..423b868c 100644 --- a/api/src/main/java/net/md_5/bungee/api/ProxyServer.java +++ b/api/src/main/java/net/md_5/bungee/api/ProxyServer.java @@ -1,6 +1,8 @@ package net.md_5.bungee.api; +import net.md_5.bungee.api.plugin.PluginManager; import com.google.common.base.Preconditions; +import java.util.Collection; import lombok.Getter; public abstract class ProxyServer { @@ -13,4 +15,42 @@ public abstract class ProxyServer { Preconditions.checkArgument(instance == null, "Instance already set"); ProxyServer.instance = instance; } + + /** + * Gets the name of the currently running proxy software. + * + * @return the name of this instance + */ + public abstract String getName(); + + /** + * Gets the version of the currently running proxy software. + * + * @return the version of this instance + */ + public abstract String getVersion(); + + /** + * The current number of players connected to this proxy. This total should + * include virtual players that may be connected from other servers. + * + * @return current player count + */ + public abstract int playerCount(); + + /** + * Return all currently networked connections to this proxy. + * + * @return all networked users + */ + public abstract Collection getConnections(); + + /** + * Get the {@link PluginManager} associated with loading plugins and + * dispatching events. It is recommended that implementations use the + * provided PluginManager class. + * + * @return the plugin manager + */ + public abstract PluginManager getPluginManager(); } diff --git a/api/src/main/java/net/md_5/bungee/api/plugin/Event.java b/api/src/main/java/net/md_5/bungee/api/plugin/Event.java new file mode 100644 index 00000000..90db9139 --- /dev/null +++ b/api/src/main/java/net/md_5/bungee/api/plugin/Event.java @@ -0,0 +1,7 @@ +package net.md_5.bungee.api.plugin; + +/** + * Dummy class which all callable events must extend. + */ +public abstract class Event { +} diff --git a/api/src/main/java/net/md_5/bungee/api/plugin/Listener.java b/api/src/main/java/net/md_5/bungee/api/plugin/Listener.java new file mode 100644 index 00000000..4cfb17e8 --- /dev/null +++ b/api/src/main/java/net/md_5/bungee/api/plugin/Listener.java @@ -0,0 +1,7 @@ +package net.md_5.bungee.api.plugin; + +/** + * Dummy interface which all event subscribers and listeners must implement. + */ +public interface Listener { +} diff --git a/api/src/main/java/net/md_5/bungee/api/plugin/Plugin.java b/api/src/main/java/net/md_5/bungee/api/plugin/Plugin.java new file mode 100644 index 00000000..e546aef3 --- /dev/null +++ b/api/src/main/java/net/md_5/bungee/api/plugin/Plugin.java @@ -0,0 +1,4 @@ +package net.md_5.bungee.api.plugin; + +public class Plugin { +} diff --git a/api/src/main/java/net/md_5/bungee/api/plugin/PluginManager.java b/api/src/main/java/net/md_5/bungee/api/plugin/PluginManager.java new file mode 100644 index 00000000..f4cdd054 --- /dev/null +++ b/api/src/main/java/net/md_5/bungee/api/plugin/PluginManager.java @@ -0,0 +1,50 @@ +package net.md_5.bungee.api.plugin; + +import com.google.common.eventbus.EventBus; +import com.google.common.eventbus.Subscribe; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +/** + * Class to manage bridging between plugin duties and implementation duties, for + * example event handling and plugin management. + */ +public class PluginManager { + + private final EventBus eventBus = new EventBus(); + private final Map plugins = new HashMap<>(); + + /** + * Returns the {@link Plugin} objects corresponding to all loaded plugins. + * + * @return the set of loaded plugins + */ + public Collection getPlugins() { + return plugins.values(); + } + + /** + * Dispatch an event to all subscribed listeners and return the event once + * it has been handled by these listeners. + * + * @param the type bounds, must be a class which extends event + * @param event the event to call + * @return the called event + */ + public T callEvent(T event) { + eventBus.post(event); + return event; + } + + /** + * Register a {@link Listener} for receiving called events. Methods in this + * Object which wish to receive events must be annotated with the + * {@link Subscribe} annotation. + * + * @param listener the listener to register events for + */ + public void registerListener(Listener listener) { + eventBus.register(listener); + } +}