Api spec is already looking really good.

This commit is contained in:
md_5 2013-01-10 18:16:29 +11:00
parent 162f75423d
commit e3664cb654
6 changed files with 126 additions and 0 deletions

View File

@ -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();
}

View File

@ -1,6 +1,8 @@
package net.md_5.bungee.api; package net.md_5.bungee.api;
import net.md_5.bungee.api.plugin.PluginManager;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import java.util.Collection;
import lombok.Getter; import lombok.Getter;
public abstract class ProxyServer { public abstract class ProxyServer {
@ -13,4 +15,42 @@ public abstract class ProxyServer {
Preconditions.checkArgument(instance == null, "Instance already set"); Preconditions.checkArgument(instance == null, "Instance already set");
ProxyServer.instance = instance; 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<ProxyConnection> 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();
} }

View File

@ -0,0 +1,7 @@
package net.md_5.bungee.api.plugin;
/**
* Dummy class which all callable events must extend.
*/
public abstract class Event {
}

View File

@ -0,0 +1,7 @@
package net.md_5.bungee.api.plugin;
/**
* Dummy interface which all event subscribers and listeners must implement.
*/
public interface Listener {
}

View File

@ -0,0 +1,4 @@
package net.md_5.bungee.api.plugin;
public class Plugin {
}

View File

@ -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<String, Plugin> plugins = new HashMap<>();
/**
* Returns the {@link Plugin} objects corresponding to all loaded plugins.
*
* @return the set of loaded plugins
*/
public Collection<Plugin> getPlugins() {
return plugins.values();
}
/**
* Dispatch an event to all subscribed listeners and return the event once
* it has been handled by these listeners.
*
* @param <T> the type bounds, must be a class which extends event
* @param event the event to call
* @return the called event
*/
public <T extends Event> 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);
}
}