Add API to allow overriding of the configuration storage system.

This commit is contained in:
md_5 2013-01-12 12:29:22 +11:00
parent b4105f8081
commit 7a137b7e34
7 changed files with 165 additions and 5 deletions

View File

@ -6,6 +6,8 @@ import com.google.common.base.Preconditions;
import java.util.Collection;
import java.util.logging.Logger;
import lombok.Getter;
import net.md_5.bungee.api.config.ConfigurationAdapter;
import net.md_5.bungee.api.plugin.Plugin;
public abstract class ProxyServer
{
@ -63,4 +65,12 @@ public abstract class ProxyServer
* @return the plugin manager
*/
public abstract PluginManager getPluginManager();
/**
* Set the configuration adapter to be used. Must be called from
* {@link Plugin#onLoad()}.
*
* @param adapter the adapter to use
*/
public abstract void setConfigurationAdapter(ConfigurationAdapter adapter);
}

View File

@ -0,0 +1,57 @@
package net.md_5.bungee.api.config;
import java.util.List;
import net.md_5.bungee.api.CommandSender;
/**
* This class allows plugins to set their own configuration adapter to load
* settings from a different place.
*/
public interface ConfigurationAdapter
{
/**
* Gets an integer from the specified path.
*
* @param path the path to retrieve the integer from
* @return the retrieved integer
*/
public int getInt(String path);
/**
* Gets a string from the specified path.
*
* @param path the path to retrieve the string from.
* @return the retrieved string
*/
public String getString(String path);
/**
* Get a string list from the specified path.
*
* @param path the path to retrieve the list from.
* @return the retrieved list.
*/
public List<String> getStringList(String path);
/**
* Get the configuration all servers which may be accessible via the proxy.
*
* @return all accessible servers
*/
public List<ServerInfo> getServers();
/**
* Get information about all hosts to bind the proxy to.
*
* @return a list of all hosts to bind to
*/
public List<ListenerInfo> getListeners();
/**
* Set the permissions of the specified {@link CommandSender}
*
* @param sender the sender to set permissions on.
*/
public void setPermissions(CommandSender sender);
}

View File

@ -0,0 +1,26 @@
package net.md_5.bungee.api.config;
import java.net.InetSocketAddress;
import lombok.Data;
/**
* Class representing the configuration of a server listener. Used for allowing
* multiple listeners on different ports.
*/
@Data
public class ListenerInfo
{
/**
* Host to bind to.
*/
private final InetSocketAddress host;
/**
* Displayed motd.
*/
private final String motd;
/**
* Max amount of slots displayed on the ping page.
*/
private final int maxPlayers;
}

View File

@ -0,0 +1,27 @@
package net.md_5.bungee.api.config;
import java.net.InetSocketAddress;
import lombok.AllArgsConstructor;
import lombok.Data;
/**
* Class used to represent a server to connect to.
*/
@Data
@AllArgsConstructor
public class ServerInfo
{
/**
* Name this server displays as.
*/
private final String name;
/**
* Connectable address of this server.
*/
private final InetSocketAddress address;
/**
* Permission node required to access this server.
*/
private String permission;
}

View File

@ -1,8 +1,10 @@
package net.md_5.bungee.api.connection;
import java.net.InetSocketAddress;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import net.md_5.bungee.api.Callback;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.ServerPing;
/**
@ -12,8 +14,18 @@ import net.md_5.bungee.api.ServerPing;
public abstract class Server implements Connection
{
/**
* Information about the address, name and configuration regarding this
* server.
*/
@Getter
private final String name;
private final ServerInfo info;
@Override
public InetSocketAddress getAddress()
{
return info.getAddress();
}
/**
* Send data by any available means to this server.

View File

@ -1,6 +1,7 @@
package net.md_5.bungee.api.plugin;
import lombok.Getter;
import net.md_5.bungee.api.config.ConfigurationAdapter;
/**
* Represents any Plugin that may be loaded at runtime to enhance existing
@ -12,6 +13,15 @@ public class Plugin
@Getter
private PluginDescription description;
/**
* Called when the plugin has just been loaded. Most of the proxy will not
* be initialized, so only use it for registering
* {@link ConfigurationAdapter}'s and other predefined behavior.
*/
public void onLoad()
{
}
/**
* Called when this plugin is enabled.
*/

View File

@ -115,14 +115,32 @@ public class PluginManager
return plugins.get(name);
}
/**
* Enable all plugins by calling the {@link Plugin#onEnable()} method.
*/
public void enablePlugins()
{
for (Map.Entry<String, Plugin> plugin : plugins.entrySet())
{
try
{
plugin.getValue().onEnable();
} catch (Exception ex)
{
ProxyServer.getInstance().getLogger().log(Level.WARNING, "Exception encountered when loading plugin: " + plugin.getKey(), ex);
}
}
}
/**
* Load a plugin from the specified file. This file must be in jar format.
* This will not enable plugins, {@link #enablePlugins()} must be called.
*
* @param file the file to load from
* @throws Exception Any exceptions encountered when loading a plugin from
* this file.
*/
public void load(File file) throws Exception
public void loadPlugin(File file) throws Exception
{
Preconditions.checkNotNull(file, "file");
Preconditions.checkArgument(file.isFile(), "Must load from file");
@ -142,7 +160,7 @@ public class PluginManager
plugin.init(desc);
plugins.put(pdf.getName(), plugin);
plugin.onEnable();
plugin.onLoad();
}
}
}
@ -152,7 +170,7 @@ public class PluginManager
*
* @param folder the folder to search for plugins in
*/
public void loadAll(File folder)
public void loadPlugins(File folder)
{
Preconditions.checkNotNull(folder, "folder");
Preconditions.checkArgument(folder.isDirectory(), "Must load from a directory");
@ -163,7 +181,7 @@ public class PluginManager
{
try
{
load(file);
loadPlugin(file);
} catch (Exception ex)
{
ProxyServer.getInstance().getLogger().log(Level.WARNING, "Could not load plugin from file " + file, ex);