mirror of
https://github.com/SpigotMC/BungeeCord.git
synced 2024-11-23 18:55:22 +01:00
More work on the API: Up next, command senders.
This commit is contained in:
parent
e3664cb654
commit
9196f8f61e
@ -23,6 +23,13 @@
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>13.0.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.yaml</groupId>
|
||||
<artifactId>snakeyaml</artifactId>
|
||||
<version>1.11</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
19
api/src/main/java/net/md_5/bungee/api/Callback.java
Normal file
19
api/src/main/java/net/md_5/bungee/api/Callback.java
Normal file
@ -0,0 +1,19 @@
|
||||
package net.md_5.bungee.api;
|
||||
|
||||
/**
|
||||
* Represents a method which may be called once a result has been computed
|
||||
* asynchronously.
|
||||
*
|
||||
* @param <V> the type of result
|
||||
*/
|
||||
public interface Callback<V>
|
||||
{
|
||||
|
||||
/**
|
||||
* Called when the result is done.
|
||||
*
|
||||
* @param result the result of the computation
|
||||
* @param error the error(s) that occurred, if any
|
||||
*/
|
||||
public void done(V result, Throwable error);
|
||||
}
|
@ -7,7 +7,8 @@ import java.net.InetSocketAddress;
|
||||
* 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 {
|
||||
public abstract class ProxyConnection
|
||||
{
|
||||
|
||||
/**
|
||||
* Gets the remote address of this connection.
|
||||
|
@ -3,15 +3,24 @@ 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 java.util.logging.Logger;
|
||||
import lombok.Getter;
|
||||
|
||||
public abstract class ProxyServer {
|
||||
public abstract class ProxyServer
|
||||
{
|
||||
|
||||
@Getter
|
||||
private static ProxyServer instance;
|
||||
|
||||
public static void setInstance(ProxyServer instance) {
|
||||
Preconditions.checkNotNull(instance, "Instance null");
|
||||
/**
|
||||
* Sets the proxy instance. This method may only be called once per an
|
||||
* application.
|
||||
*
|
||||
* @param instance the new instance to set
|
||||
*/
|
||||
public static void setInstance(ProxyServer instance)
|
||||
{
|
||||
Preconditions.checkNotNull(instance, "instance");
|
||||
Preconditions.checkArgument(instance == null, "Instance already set");
|
||||
ProxyServer.instance = instance;
|
||||
}
|
||||
@ -38,6 +47,14 @@ public abstract class ProxyServer {
|
||||
*/
|
||||
public abstract int playerCount();
|
||||
|
||||
/**
|
||||
* Gets the main logger which can be used as a suitable replacement for
|
||||
* {@link System#out} and {@link System#err}.
|
||||
*
|
||||
* @return the {@link Logger} instance
|
||||
*/
|
||||
public abstract Logger getLogger();
|
||||
|
||||
/**
|
||||
* Return all currently networked connections to this proxy.
|
||||
*
|
||||
|
32
api/src/main/java/net/md_5/bungee/api/RemoteServer.java
Normal file
32
api/src/main/java/net/md_5/bungee/api/RemoteServer.java
Normal file
@ -0,0 +1,32 @@
|
||||
package net.md_5.bungee.api;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
/**
|
||||
* Represents a destination which this proxy might connect to.
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
public abstract class RemoteServer extends ProxyConnection
|
||||
{
|
||||
|
||||
@Getter
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* Send data by any available means to this server.
|
||||
*
|
||||
* @param channel the channel to send this data via
|
||||
* @param data the data to send
|
||||
*/
|
||||
public abstract void sendData(String channel, byte[] data);
|
||||
|
||||
/**
|
||||
* Asynchronously gets the current player count on this server.
|
||||
*
|
||||
* TODO: Return all info available via the standard query protocol
|
||||
*
|
||||
* @param callback the callback to call when the count has been retrieved.
|
||||
*/
|
||||
public abstract void getPlayerCount(Callback<Integer> callback);
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package net.md_5.bungee.api.plugin;
|
||||
|
||||
/**
|
||||
* Events that implement this indicate that they may be cancelled and thus
|
||||
* prevented from happening.
|
||||
*/
|
||||
public interface Cancellable
|
||||
{
|
||||
|
||||
/**
|
||||
* Get whether or not this event is cancelled.
|
||||
*
|
||||
* @return the cancelled state of this event
|
||||
*/
|
||||
public boolean isCancelled();
|
||||
|
||||
/**
|
||||
* Sets the cancelled state of this event.
|
||||
*
|
||||
* @param cancel the state to set
|
||||
*/
|
||||
public void setCancelled(boolean cancel);
|
||||
}
|
@ -3,5 +3,6 @@ package net.md_5.bungee.api.plugin;
|
||||
/**
|
||||
* Dummy class which all callable events must extend.
|
||||
*/
|
||||
public abstract class Event {
|
||||
public abstract class Event
|
||||
{
|
||||
}
|
||||
|
@ -3,5 +3,6 @@ package net.md_5.bungee.api.plugin;
|
||||
/**
|
||||
* Dummy interface which all event subscribers and listeners must implement.
|
||||
*/
|
||||
public interface Listener {
|
||||
public interface Listener
|
||||
{
|
||||
}
|
||||
|
@ -1,4 +1,33 @@
|
||||
package net.md_5.bungee.api.plugin;
|
||||
|
||||
public class Plugin {
|
||||
import java.util.logging.Logger;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
|
||||
/**
|
||||
* Represents any Plugin that may be loaded at runtime to enhance existing
|
||||
* functionality.
|
||||
*/
|
||||
public class Plugin
|
||||
{
|
||||
|
||||
/**
|
||||
* Called when this plugin is loaded.
|
||||
*/
|
||||
public void onLoad()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when this plugin is enabled.
|
||||
*/
|
||||
public void onEnable()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when this plugin is disabled.
|
||||
*/
|
||||
public void onDisable()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,14 @@
|
||||
package net.md_5.bungee.api.plugin;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class PluginDescription
|
||||
{
|
||||
|
||||
private final String name;
|
||||
private final String main;
|
||||
private final String version;
|
||||
private final String author;
|
||||
private final String id;
|
||||
}
|
@ -1,7 +1,9 @@
|
||||
package net.md_5.bungee.api.plugin;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.eventbus.EventBus;
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -10,7 +12,8 @@ import java.util.Map;
|
||||
* Class to manage bridging between plugin duties and implementation duties, for
|
||||
* example event handling and plugin management.
|
||||
*/
|
||||
public class PluginManager {
|
||||
public class PluginManager
|
||||
{
|
||||
|
||||
private final EventBus eventBus = new EventBus();
|
||||
private final Map<String, Plugin> plugins = new HashMap<>();
|
||||
@ -20,10 +23,53 @@ public class PluginManager {
|
||||
*
|
||||
* @return the set of loaded plugins
|
||||
*/
|
||||
public Collection<Plugin> getPlugins() {
|
||||
public Collection<Plugin> getPlugins()
|
||||
{
|
||||
return plugins.values();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a loaded plugin identified by the specified name.
|
||||
*
|
||||
* @param name of the plugin to retrieve
|
||||
* @return the retrieved plugin or null if not loaded
|
||||
*/
|
||||
public Plugin getPlugin(String name)
|
||||
{
|
||||
return plugins.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a plugin from the specified file. This file must be in jar or zip
|
||||
* format.
|
||||
*
|
||||
* @param file the file to load from
|
||||
*/
|
||||
public void load(File file)
|
||||
{
|
||||
Preconditions.checkNotNull(file, "file");
|
||||
Preconditions.checkArgument(file.isFile(), "Must load from file");
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all plugins from the specified folder.
|
||||
*
|
||||
* @param folder the folder to search for plugins in
|
||||
*/
|
||||
public void loadAll(File folder)
|
||||
{
|
||||
Preconditions.checkNotNull(folder, "folder");
|
||||
Preconditions.checkArgument(folder.isDirectory(), "Must load from a directory");
|
||||
|
||||
for (File file : folder.listFiles())
|
||||
{
|
||||
if (file.getName().endsWith(".jar"))
|
||||
{
|
||||
load(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch an event to all subscribed listeners and return the event once
|
||||
* it has been handled by these listeners.
|
||||
@ -32,7 +78,8 @@ public class PluginManager {
|
||||
* @param event the event to call
|
||||
* @return the called event
|
||||
*/
|
||||
public <T extends Event> T callEvent(T event) {
|
||||
public <T extends Event> T callEvent(T event)
|
||||
{
|
||||
eventBus.post(event);
|
||||
return event;
|
||||
}
|
||||
@ -44,7 +91,8 @@ public class PluginManager {
|
||||
*
|
||||
* @param listener the listener to register events for
|
||||
*/
|
||||
public void registerListener(Listener listener) {
|
||||
public void registerListener(Listener listener)
|
||||
{
|
||||
eventBus.register(listener);
|
||||
}
|
||||
}
|
||||
|
@ -39,11 +39,6 @@
|
||||
<artifactId>bcprov-ext-jdk15on</artifactId>
|
||||
<version>1.47</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.yaml</groupId>
|
||||
<artifactId>snakeyaml</artifactId>
|
||||
<version>1.11</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
Loading…
Reference in New Issue
Block a user