2016-12-24 05:55:17 +01:00
|
|
|
package net.ME1312.SubServers.Bungee;
|
2016-12-05 04:21:04 +01:00
|
|
|
|
2017-08-22 15:02:23 +02:00
|
|
|
import net.ME1312.SubServers.Bungee.Event.SubAddHostEvent;
|
2016-12-24 05:55:17 +01:00
|
|
|
import net.ME1312.SubServers.Bungee.Event.SubAddServerEvent;
|
2017-08-22 15:02:23 +02:00
|
|
|
import net.ME1312.SubServers.Bungee.Event.SubRemoveHostEvent;
|
|
|
|
import net.ME1312.SubServers.Bungee.Event.SubRemoveServerEvent;
|
2018-01-22 16:01:33 +01:00
|
|
|
import net.ME1312.SubServers.Bungee.Host.*;
|
2017-08-22 15:02:23 +02:00
|
|
|
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidHostException;
|
2017-01-26 23:19:48 +01:00
|
|
|
import net.ME1312.SubServers.Bungee.Library.NamedContainer;
|
2016-12-24 05:55:17 +01:00
|
|
|
import net.ME1312.SubServers.Bungee.Library.UniversalFile;
|
2017-01-30 21:22:36 +01:00
|
|
|
import net.ME1312.SubServers.Bungee.Library.Util;
|
2016-12-24 05:55:17 +01:00
|
|
|
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
|
|
|
import net.ME1312.SubServers.Bungee.Network.SubDataServer;
|
2017-12-10 15:14:49 +01:00
|
|
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
2016-12-05 04:21:04 +01:00
|
|
|
|
2017-08-22 15:02:23 +02:00
|
|
|
import java.lang.reflect.InvocationTargetException;
|
2016-12-15 22:04:39 +01:00
|
|
|
import java.net.InetAddress;
|
|
|
|
import java.net.InetSocketAddress;
|
2017-01-26 23:19:48 +01:00
|
|
|
import java.util.*;
|
2016-12-05 04:21:04 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* SubAPI Class
|
|
|
|
*/
|
|
|
|
public final class SubAPI {
|
2017-01-26 23:19:48 +01:00
|
|
|
LinkedList<NamedContainer<Runnable, Runnable>> listeners = new LinkedList<NamedContainer<Runnable, Runnable>>();
|
2017-12-13 18:29:50 +01:00
|
|
|
LinkedList<Runnable> reloadListeners = new LinkedList<Runnable>();
|
2018-01-12 22:56:22 +01:00
|
|
|
private static HashMap<String, Object> knownSignatures = new HashMap<String, Object>();
|
2017-12-06 23:34:47 +01:00
|
|
|
boolean ready = false;
|
2018-01-12 22:56:22 +01:00
|
|
|
private final SubPlugin plugin;
|
2016-12-05 04:21:04 +01:00
|
|
|
private static SubAPI api;
|
|
|
|
|
|
|
|
protected SubAPI(SubPlugin plugin) {
|
|
|
|
this.plugin = plugin;
|
|
|
|
api = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the SubAPI Methods
|
|
|
|
*
|
|
|
|
* @return SubAPI
|
|
|
|
*/
|
|
|
|
public static SubAPI getInstance() {
|
|
|
|
return api;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the SubServers Internals
|
|
|
|
*
|
|
|
|
* @deprecated Use SubAPI Methods when available
|
|
|
|
* @return SubPlugin Internals
|
|
|
|
*/
|
|
|
|
@Deprecated
|
|
|
|
public SubPlugin getInternals() {
|
|
|
|
return plugin;
|
|
|
|
}
|
|
|
|
|
2017-01-26 23:19:48 +01:00
|
|
|
/**
|
|
|
|
* Adds a SubAPI Listener
|
|
|
|
*
|
|
|
|
* @param enable An Event that will be called when SubAPI is ready
|
2017-12-13 18:29:50 +01:00
|
|
|
* @param disable An Event that will be called before SubAPI is disabled (your plugin should reset it's values in case this is a hard-reset instead of a shutdown)
|
2017-01-26 23:19:48 +01:00
|
|
|
*/
|
|
|
|
public void addListener(Runnable enable, Runnable disable) {
|
2017-12-13 18:29:50 +01:00
|
|
|
if (!Util.isNull(enable, disable)) listeners.add(new NamedContainer<Runnable, Runnable>(enable, disable));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a SubAPI Listener
|
|
|
|
*
|
|
|
|
* @param enable An Event that will be called when SubAPI is ready
|
|
|
|
* @param reload An Event that will be called after SubAPI is soft-reloaded
|
|
|
|
* @param disable An Event that will be called before SubAPI is disabled (your plugin should reset it's values in case this is a hard-reset instead of a shutdown)
|
|
|
|
*/
|
|
|
|
public void addListener(Runnable enable, Runnable reload, Runnable disable) {
|
|
|
|
addListener(enable, disable);
|
|
|
|
if (reload != null) reloadListeners.add(reload);
|
2017-01-26 23:19:48 +01:00
|
|
|
}
|
|
|
|
|
2016-12-05 04:21:04 +01:00
|
|
|
/**
|
|
|
|
* Gets the SubData Network Manager
|
|
|
|
*
|
|
|
|
* @return SubData Network Manager
|
|
|
|
*/
|
2016-12-15 22:04:39 +01:00
|
|
|
public SubDataServer getSubDataNetwork() {
|
2016-12-05 04:21:04 +01:00
|
|
|
return plugin.subdata;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a Driver for Hosts
|
|
|
|
*
|
|
|
|
* @param driver Driver to add
|
|
|
|
* @param handle Handle to Bind
|
|
|
|
*/
|
|
|
|
public void addHostDriver(Class<? extends Host> driver, String handle) {
|
2017-01-30 21:22:36 +01:00
|
|
|
if (Util.isNull(driver, handle)) throw new NullPointerException();
|
2018-01-12 22:56:22 +01:00
|
|
|
if (plugin.hostDrivers.keySet().contains(handle.toUpperCase().replace('-', '_').replace(' ', '_'))) throw new IllegalStateException("Driver already exists: " + handle);
|
|
|
|
plugin.hostDrivers.put(handle.toUpperCase().replace('-', '_').replace(' ', '_'), driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a list of all available Host Drivers
|
|
|
|
*
|
|
|
|
* @return Host Driver handle list
|
|
|
|
*/
|
|
|
|
public List<String> getHostDrivers() {
|
|
|
|
return new LinkedList<String>(plugin.hostDrivers.keySet());
|
2016-12-05 04:21:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the Hosts
|
|
|
|
*
|
|
|
|
* @return Host Map
|
|
|
|
*/
|
|
|
|
public Map<String, Host> getHosts() {
|
|
|
|
return new TreeMap<>(plugin.hosts);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a Host
|
|
|
|
*
|
|
|
|
* @param name Host name
|
|
|
|
* @return a Host
|
|
|
|
*/
|
|
|
|
public Host getHost(String name) {
|
2017-01-30 21:22:36 +01:00
|
|
|
if (Util.isNull(name)) throw new NullPointerException();
|
2016-12-05 04:21:04 +01:00
|
|
|
return getHosts().get(name.toLowerCase());
|
|
|
|
}
|
|
|
|
|
2017-08-22 15:02:23 +02:00
|
|
|
/**
|
|
|
|
* Add a Host to the Network
|
|
|
|
*
|
|
|
|
* @param driver Driver to initiate
|
|
|
|
* @param name Name of the Host
|
|
|
|
* @param enabled Enabled Status
|
|
|
|
* @param address Address of the Host
|
|
|
|
* @param directory Directory of the Host
|
|
|
|
* @param gitBash Git Bash Directory
|
|
|
|
* @return The Host
|
|
|
|
* @throws NoSuchMethodException
|
|
|
|
* @throws IllegalAccessException
|
|
|
|
* @throws InvocationTargetException
|
|
|
|
* @throws InstantiationException
|
|
|
|
*/
|
|
|
|
public Host addHost(String driver, String name, boolean enabled, InetAddress address, String directory, String gitBash) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
|
|
|
|
return addHost(null, driver, name, enabled, address, directory, gitBash);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a Host to the Network
|
|
|
|
*
|
|
|
|
* @param player Player who added
|
|
|
|
* @param driver Driver to initiate
|
|
|
|
* @param name Name of the Host
|
|
|
|
* @param enabled Enabled Status
|
|
|
|
* @param address Address of the Host
|
|
|
|
* @param directory Directory of the Host
|
|
|
|
* @param gitBash Git Bash Directory
|
|
|
|
* @return The Host
|
|
|
|
* @throws NoSuchMethodException
|
|
|
|
* @throws IllegalAccessException
|
|
|
|
* @throws InvocationTargetException
|
|
|
|
* @throws InstantiationException
|
|
|
|
*/
|
|
|
|
public Host addHost(UUID player, String driver, String name, boolean enabled, InetAddress address, String directory, String gitBash) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
|
|
|
|
if (Util.isNull(driver, name, enabled, address, directory, gitBash)) throw new NullPointerException();
|
2018-01-12 22:56:22 +01:00
|
|
|
if (!getHostDrivers().contains(driver.toUpperCase().replace('-', '_').replace(' ', '_'))) throw new InvalidHostException("Invalid Driver for host: " + name);
|
|
|
|
return addHost(player, plugin.hostDrivers.get(driver.toUpperCase().replace('-', '_').replace(' ', '_')), name, enabled, address, directory, gitBash);
|
2017-12-17 22:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a Host with a potentially unregistered driver to the Network
|
|
|
|
*
|
|
|
|
* @param driver Driver to initiate
|
|
|
|
* @param name Name of the Host
|
|
|
|
* @param enabled Enabled Status
|
|
|
|
* @param address Address of the Host
|
|
|
|
* @param directory Directory of the Host
|
|
|
|
* @param gitBash Git Bash Directory
|
|
|
|
* @return The Host
|
|
|
|
* @throws NoSuchMethodException
|
|
|
|
* @throws IllegalAccessException
|
|
|
|
* @throws InvocationTargetException
|
|
|
|
* @throws InstantiationException
|
|
|
|
*/
|
|
|
|
public Host addHost(Class<? extends Host> driver, String name, boolean enabled, InetAddress address, String directory, String gitBash) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
|
|
|
|
return addHost(null, driver, name, enabled, address, directory, gitBash);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a Host with a potentially unregistered driver to the Network
|
|
|
|
*
|
|
|
|
* @param player Player who added
|
|
|
|
* @param driver Driver to initiate
|
|
|
|
* @param name Name of the Host
|
|
|
|
* @param enabled Enabled Status
|
|
|
|
* @param address Address of the Host
|
|
|
|
* @param directory Directory of the Host
|
|
|
|
* @param gitBash Git Bash Directory
|
|
|
|
* @return The Host
|
|
|
|
* @throws NoSuchMethodException
|
|
|
|
* @throws IllegalAccessException
|
|
|
|
* @throws InvocationTargetException
|
|
|
|
* @throws InstantiationException
|
|
|
|
*/
|
|
|
|
public Host addHost(UUID player, Class<? extends Host> driver, String name, boolean enabled, InetAddress address, String directory, String gitBash) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
|
|
|
|
if (Util.isNull(driver, name, enabled, address, directory, gitBash)) throw new NullPointerException();
|
2018-01-12 22:56:22 +01:00
|
|
|
Host host = driver.getConstructor(SubPlugin.class, String.class, Boolean.class, InetAddress.class, String.class, String.class).newInstance(plugin, name, (Boolean) enabled, address, directory, gitBash);
|
|
|
|
return addHost(player, host)?host:null;
|
2017-12-17 22:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a Host with a potentially invalid/unregistered driver to the Network
|
|
|
|
*
|
|
|
|
* @param host Host to add
|
|
|
|
* @return Success status
|
|
|
|
*/
|
|
|
|
public boolean addHost(Host host) {
|
|
|
|
return addHost(null, host);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a Host with a potentially invalid/unregistered driver to the Network
|
|
|
|
*
|
|
|
|
* @param player Player who added
|
|
|
|
* @param host Host to add
|
|
|
|
* @return Success status
|
|
|
|
*/
|
|
|
|
public boolean addHost(UUID player, Host host) {
|
2017-08-22 15:02:23 +02:00
|
|
|
SubAddHostEvent event = new SubAddHostEvent(player, host);
|
|
|
|
plugin.getPluginManager().callEvent(event);
|
|
|
|
if (!event.isCancelled()) {
|
2017-12-17 22:04:05 +01:00
|
|
|
plugin.hosts.put(host.getName().toLowerCase(), host);
|
|
|
|
return true;
|
2017-08-22 15:02:23 +02:00
|
|
|
} else {
|
2017-12-17 22:04:05 +01:00
|
|
|
return false;
|
2017-08-22 15:02:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a Host from the Network
|
|
|
|
*
|
|
|
|
* @param name Name of the Host
|
|
|
|
* @return Success Status
|
|
|
|
*/
|
|
|
|
public boolean removeHost(String name) {
|
|
|
|
return removeHost(null, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a Host from the Network
|
|
|
|
*
|
|
|
|
* @param player Player Removing
|
|
|
|
* @param name Name of the Host
|
|
|
|
* @return Success Status
|
|
|
|
*/
|
|
|
|
public boolean removeHost(UUID player, String name) {
|
|
|
|
if (Util.isNull(name, getHost(name))) throw new NullPointerException();
|
|
|
|
SubRemoveHostEvent event = new SubRemoveHostEvent(player, getHost(name));
|
|
|
|
plugin.getPluginManager().callEvent(event);
|
|
|
|
if (event.isCancelled()) {
|
2017-12-09 09:43:29 +01:00
|
|
|
try {
|
|
|
|
List<String> subservers = new ArrayList<String>();
|
|
|
|
subservers.addAll(getHost(name).getSubServers().keySet());
|
|
|
|
|
|
|
|
for (String server : subservers) {
|
|
|
|
getHost(name).removeSubServer(server);
|
|
|
|
}
|
|
|
|
subservers.clear();
|
|
|
|
getHost(name).getCreator().terminate();
|
|
|
|
getHost(name).getCreator().waitFor();
|
|
|
|
plugin.hosts.remove(name.toLowerCase());
|
|
|
|
return true;
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
return false;
|
|
|
|
}
|
2017-08-22 15:02:23 +02:00
|
|
|
} else return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Force Remove a Host from the Network
|
|
|
|
*
|
|
|
|
* @param name Name of the Host
|
|
|
|
* @return Success Status
|
|
|
|
*/
|
|
|
|
public boolean forceRemoveHost(String name) {
|
|
|
|
return forceRemoveHost(null, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Force Remove a Host from the Network
|
|
|
|
*
|
|
|
|
* @param player Player Removing
|
|
|
|
* @param name Name of the Host
|
|
|
|
* @return Success Status
|
|
|
|
*/
|
|
|
|
public boolean forceRemoveHost(UUID player, String name) {
|
|
|
|
if (Util.isNull(name, getHost(name))) throw new NullPointerException();
|
|
|
|
SubRemoveHostEvent event = new SubRemoveHostEvent(player, getHost(name));
|
|
|
|
plugin.getPluginManager().callEvent(event);
|
2017-12-09 09:43:29 +01:00
|
|
|
try {
|
|
|
|
List<String> subservers = new ArrayList<String>();
|
|
|
|
subservers.addAll(getHost(name).getSubServers().keySet());
|
|
|
|
|
|
|
|
for (String server : subservers) {
|
|
|
|
getHost(name).removeSubServer(server);
|
|
|
|
}
|
|
|
|
subservers.clear();
|
|
|
|
getHost(name).getCreator().terminate();
|
|
|
|
getHost(name).getCreator().waitFor();
|
|
|
|
plugin.hosts.remove(name.toLowerCase());
|
|
|
|
return true;
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
return false;
|
|
|
|
}
|
2017-08-22 15:02:23 +02:00
|
|
|
}
|
|
|
|
|
2017-08-26 07:19:59 +02:00
|
|
|
/**
|
2017-12-06 23:34:47 +01:00
|
|
|
* Gets the Server Groups (Group names are case sensitive here)
|
2017-08-26 07:19:59 +02:00
|
|
|
*
|
|
|
|
* @return Group Map
|
|
|
|
*/
|
|
|
|
public Map<String, List<Server>> getGroups() {
|
2017-12-06 23:34:47 +01:00
|
|
|
TreeMap<String, List<Server>> groups = new TreeMap<String, List<Server>>();
|
|
|
|
HashMap<String, String> conflitresolver = new HashMap<String, String>();
|
|
|
|
for (Server server : getServers().values()) {
|
|
|
|
for (String name : server.getGroups()) {
|
|
|
|
String group = name;
|
|
|
|
if (conflitresolver.keySet().contains(name.toLowerCase())) {
|
|
|
|
group = conflitresolver.get(name.toLowerCase());
|
|
|
|
} else {
|
|
|
|
conflitresolver.put(name.toLowerCase(), name);
|
|
|
|
}
|
|
|
|
List<Server> list = (groups.keySet().contains(group))?groups.get(group):new ArrayList<Server>();
|
|
|
|
list.add(server);
|
|
|
|
groups.put(group, list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return groups;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the Server Groups (Group names are all lowercase here)
|
|
|
|
*
|
|
|
|
* @return Group Map
|
|
|
|
*/
|
|
|
|
public Map<String, List<Server>> getLowercaseGroups() {
|
|
|
|
Map<String, List<Server>> groups = getGroups();
|
|
|
|
TreeMap<String, List<Server>> lowercaseGroups = new TreeMap<String, List<Server>>();
|
|
|
|
for (String key : groups.keySet()) {
|
|
|
|
lowercaseGroups.put(key.toLowerCase(), groups.get(key));
|
|
|
|
}
|
|
|
|
return lowercaseGroups;
|
2017-08-26 07:19:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-12-06 23:34:47 +01:00
|
|
|
* Gets a Server Group (Group names are case insensitive here)
|
2017-08-26 07:19:59 +02:00
|
|
|
*
|
|
|
|
* @param name Group name
|
|
|
|
* @return a Server Group
|
|
|
|
*/
|
|
|
|
public List<Server> getGroup(String name) {
|
2017-12-09 09:43:29 +01:00
|
|
|
if (Util.isNull(name)) throw new NullPointerException();
|
|
|
|
return Util.getCaseInsensitively(getGroups(), name);
|
2017-08-26 07:19:59 +02:00
|
|
|
}
|
|
|
|
|
2016-12-05 04:21:04 +01:00
|
|
|
/**
|
|
|
|
* Gets the Servers (including SubServers)
|
|
|
|
*
|
|
|
|
* @return Server Map
|
|
|
|
*/
|
|
|
|
public Map<String, Server> getServers() {
|
|
|
|
TreeMap<String, Server> servers = new TreeMap<String, Server>();
|
|
|
|
servers.putAll(plugin.exServers);
|
|
|
|
for (Host host : plugin.hosts.values()) {
|
|
|
|
servers.putAll(host.getSubServers());
|
|
|
|
}
|
|
|
|
return servers;
|
|
|
|
}
|
|
|
|
|
2017-08-22 15:02:23 +02:00
|
|
|
/**
|
|
|
|
* Gets a Server
|
|
|
|
*
|
|
|
|
* @param name Server name
|
|
|
|
* @return a Server
|
|
|
|
*/
|
|
|
|
public Server getServer(String name) {
|
|
|
|
if (Util.isNull(name)) throw new NullPointerException();
|
|
|
|
return getServers().get(name.toLowerCase());
|
|
|
|
}
|
|
|
|
|
2016-12-15 22:04:39 +01:00
|
|
|
/**
|
|
|
|
* Adds a Server to the Network
|
|
|
|
*
|
|
|
|
* @param name Name of the Server
|
|
|
|
* @param ip IP of the Server
|
|
|
|
* @param port Port of the Server
|
|
|
|
* @param motd MOTD of the Server
|
2016-12-19 01:38:02 +01:00
|
|
|
* @param hidden if the server should be hidden from players
|
2016-12-15 22:04:39 +01:00
|
|
|
* @param restricted Players will need a permission to join if true
|
|
|
|
* @return The Server
|
|
|
|
*/
|
2016-12-19 01:38:02 +01:00
|
|
|
public Server addServer(String name, InetAddress ip, int port, String motd, boolean hidden, boolean restricted) {
|
|
|
|
return addServer(null, name, ip, port, motd, hidden, restricted);
|
2016-12-15 22:04:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a Server to the Network
|
|
|
|
*
|
|
|
|
* @param player Player who added
|
|
|
|
* @param name Name of the Server
|
|
|
|
* @param ip IP of the Server
|
|
|
|
* @param port Port of the Server
|
|
|
|
* @param motd MOTD of the Server
|
2016-12-19 01:38:02 +01:00
|
|
|
* @param hidden If the server should be hidden from players
|
2016-12-15 22:04:39 +01:00
|
|
|
* @param restricted Players will need a permission to join if true
|
|
|
|
* @return The Server
|
|
|
|
*/
|
2016-12-19 01:38:02 +01:00
|
|
|
public Server addServer(UUID player, String name, InetAddress ip, int port, String motd, boolean hidden, boolean restricted) {
|
2017-08-27 20:37:25 +02:00
|
|
|
Server server = new ServerContainer(name, new InetSocketAddress(ip, port), motd, hidden, restricted);
|
2016-12-15 22:04:39 +01:00
|
|
|
SubAddServerEvent event = new SubAddServerEvent(player, null, server);
|
|
|
|
plugin.getPluginManager().callEvent(event);
|
|
|
|
if (!event.isCancelled()) {
|
|
|
|
plugin.exServers.put(name.toLowerCase(), server);
|
|
|
|
return server;
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-05 04:21:04 +01:00
|
|
|
/**
|
2017-08-22 15:02:23 +02:00
|
|
|
* Remove a Server from the Network
|
2016-12-05 04:21:04 +01:00
|
|
|
*
|
2017-08-22 15:02:23 +02:00
|
|
|
* @param name Name of the Server
|
|
|
|
* @return Success Status
|
2016-12-05 04:21:04 +01:00
|
|
|
*/
|
2017-08-22 15:02:23 +02:00
|
|
|
public boolean removeServer(String name) {
|
|
|
|
return removeServer(null, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a Server from the Network
|
|
|
|
*
|
|
|
|
* @param player Player Removing
|
|
|
|
* @param name Name of the Server
|
|
|
|
* @return Success Status
|
|
|
|
*/
|
|
|
|
public boolean removeServer(UUID player, String name) {
|
|
|
|
if (Util.isNull(name, getServer(name))) throw new NullPointerException();
|
|
|
|
SubRemoveServerEvent event = new SubRemoveServerEvent(player, null, getServer(name));
|
|
|
|
plugin.getPluginManager().callEvent(event);
|
|
|
|
if (event.isCancelled()) {
|
|
|
|
plugin.exServers.remove(name.toLowerCase());
|
|
|
|
return true;
|
|
|
|
} else return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Force Remove a Server from the Network
|
|
|
|
*
|
|
|
|
* @param name Name of the Server
|
|
|
|
* @return Success Status
|
|
|
|
*/
|
|
|
|
public boolean forceRemoveServer(String name) {
|
|
|
|
return forceRemoveServer(null, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Force Remove a Server from the Network
|
|
|
|
*
|
|
|
|
* @param player Player Removing
|
|
|
|
* @param name Name of the Server
|
|
|
|
* @return Success Status
|
|
|
|
*/
|
|
|
|
public boolean forceRemoveServer(UUID player, String name) {
|
|
|
|
if (Util.isNull(name, getServer(name))) throw new NullPointerException();
|
|
|
|
SubRemoveServerEvent event = new SubRemoveServerEvent(player, null, getServer(name));
|
|
|
|
plugin.getPluginManager().callEvent(event);
|
|
|
|
plugin.exServers.remove(name.toLowerCase());
|
|
|
|
return true;
|
2016-12-05 04:21:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the SubServers
|
|
|
|
*
|
|
|
|
* @return SubServer Map
|
|
|
|
*/
|
|
|
|
public Map<String, SubServer> getSubServers() {
|
|
|
|
TreeMap<String, SubServer> servers = new TreeMap<String, SubServer>();
|
|
|
|
for (Host host : plugin.hosts.values()) {
|
|
|
|
servers.putAll(host.getSubServers());
|
|
|
|
}
|
|
|
|
return servers;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a SubServer
|
|
|
|
*
|
|
|
|
* @param name SubServer name
|
|
|
|
* @return a SubServer
|
|
|
|
*/
|
|
|
|
public SubServer getSubServer(String name) {
|
2017-01-30 21:22:36 +01:00
|
|
|
if (Util.isNull(name)) throw new NullPointerException();
|
2016-12-05 04:21:04 +01:00
|
|
|
return getSubServers().get(name.toLowerCase());
|
|
|
|
}
|
|
|
|
|
2018-01-22 16:01:33 +01:00
|
|
|
/**
|
|
|
|
* Gets the known Proxies
|
|
|
|
*
|
|
|
|
* @return Proxy Map
|
|
|
|
*/
|
|
|
|
public Map<String, Proxy> getProxies() {
|
|
|
|
return new TreeMap<String, Proxy>(plugin.proxies);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a Proxy
|
|
|
|
*
|
|
|
|
* @param name Proxy name
|
|
|
|
* @return a Proxy
|
|
|
|
*/
|
|
|
|
public Proxy getProxy(String name) {
|
|
|
|
if (Util.isNull(name)) throw new NullPointerException();
|
|
|
|
return getProxies().get(name.toLowerCase());
|
|
|
|
}
|
|
|
|
|
2017-12-10 15:14:49 +01:00
|
|
|
/**
|
|
|
|
* Get players on this network across all known proxies
|
|
|
|
*
|
|
|
|
* @return Player Collection
|
|
|
|
*/
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
public Collection<NamedContainer<String, UUID>> getGlobalPlayers() {
|
|
|
|
List<NamedContainer<String, UUID>> players = new ArrayList<NamedContainer<String, UUID>>();
|
|
|
|
if (plugin.redis) {
|
|
|
|
try {
|
|
|
|
for (UUID player : (Set<UUID>) plugin.redis("getPlayersOnline")) players.add(new NamedContainer<>((String) plugin.redis("getNameFromUuid", new NamedContainer<>(UUID.class, player)), player));
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (ProxiedPlayer player : plugin.getPlayers()) players.add(new NamedContainer<>(player.getName(), player.getUniqueId()));
|
|
|
|
}
|
|
|
|
return players;
|
|
|
|
}
|
|
|
|
|
2017-01-21 17:49:37 +01:00
|
|
|
/**
|
2018-01-02 23:29:25 +01:00
|
|
|
* Adds to the SubServers Lang
|
2017-01-21 17:49:37 +01:00
|
|
|
*
|
2018-01-02 23:29:25 +01:00
|
|
|
* @param channel Lang Channel
|
2017-01-21 17:49:37 +01:00
|
|
|
* @param key Key
|
|
|
|
* @param value Lang Value
|
|
|
|
*/
|
2018-01-02 23:29:25 +01:00
|
|
|
public void setLang(String channel, String key, String value) {
|
|
|
|
if (Util.isNull(channel, key, value)) throw new NullPointerException();
|
|
|
|
LinkedHashMap<String, String> map = (plugin.lang.keySet().contains(channel.toLowerCase()))?plugin.lang.get(channel.toLowerCase()):new LinkedHashMap<String, String>();
|
|
|
|
map.put(key, value);
|
|
|
|
plugin.lang.put(channel.toLowerCase(), map);
|
2017-01-21 17:49:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-01-12 22:56:22 +01:00
|
|
|
* Gets the current SubServers Lang Channels
|
2017-01-21 17:49:37 +01:00
|
|
|
*
|
2018-01-12 22:56:22 +01:00
|
|
|
* @return SubServers Lang Channel list
|
2018-01-02 23:29:25 +01:00
|
|
|
*/
|
2018-01-12 22:56:22 +01:00
|
|
|
public Collection<String> getLangChannels() {
|
|
|
|
return plugin.lang.keySet();
|
2018-01-02 23:29:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets values from the SubServers Lang
|
|
|
|
*
|
|
|
|
* @param channel Lang Channel
|
2017-01-21 17:49:37 +01:00
|
|
|
* @return Lang Value
|
|
|
|
*/
|
2018-01-02 23:29:25 +01:00
|
|
|
public Map<String, String> getLang(String channel) {
|
|
|
|
if (Util.isNull(channel)) throw new NullPointerException();
|
2018-01-12 22:56:22 +01:00
|
|
|
return new LinkedHashMap<>(plugin.lang.get(channel.toLowerCase()));
|
2017-01-21 17:49:37 +01:00
|
|
|
}
|
|
|
|
|
2016-12-19 01:38:02 +01:00
|
|
|
/**
|
2018-01-02 23:29:25 +01:00
|
|
|
* Gets a value from the SubServers Lang
|
2016-12-19 01:38:02 +01:00
|
|
|
*
|
2018-01-02 23:29:25 +01:00
|
|
|
* @param channel Lang Channel
|
|
|
|
* @param key Key
|
|
|
|
* @return Lang Values
|
2016-12-19 01:38:02 +01:00
|
|
|
*/
|
2018-01-02 23:29:25 +01:00
|
|
|
public String getLang(String channel, String key) {
|
|
|
|
if (Util.isNull(channel, key)) throw new NullPointerException();
|
|
|
|
return getLang(channel).get(key);
|
2016-12-19 01:38:02 +01:00
|
|
|
}
|
|
|
|
|
2017-12-13 18:29:50 +01:00
|
|
|
/**
|
|
|
|
* Get an Object Signature without linking the Signature to any object
|
|
|
|
*
|
|
|
|
* @return Anonymous Object Signature
|
|
|
|
*/
|
|
|
|
public String signAnonymousObject() {
|
|
|
|
return plugin.getNewSignature();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Signs an Object
|
|
|
|
*
|
|
|
|
* @param object Object to Sign
|
|
|
|
* @return Object's Signature (or an empty string if the object was null)
|
|
|
|
*/
|
|
|
|
public String signObject(Object object) {
|
|
|
|
if (object == null) {
|
|
|
|
return "";
|
|
|
|
} else {
|
|
|
|
String signature = signAnonymousObject();
|
|
|
|
knownSignatures.put(signature, object);
|
|
|
|
return signature;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get an Object by it's Signature
|
|
|
|
*
|
|
|
|
* @param signature Object's Signature
|
|
|
|
* @param <R> Expected Object Type
|
|
|
|
* @return Object that is tied to this Signature (or null if the signature is unknown)
|
|
|
|
*/
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
public <R> R getObjectBySignature(String signature) {
|
|
|
|
if (Util.isNull(signature)) throw new NullPointerException();
|
|
|
|
return (R) knownSignatures.get(signature);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invalidate an Object Signature. This will remove the link between the Signature and the Object
|
|
|
|
*
|
|
|
|
* @param signature Object's Signature
|
|
|
|
*/
|
|
|
|
public void invalidateObjectSignature(String signature) {
|
|
|
|
knownSignatures.remove(signature);
|
|
|
|
}
|
|
|
|
|
2016-12-19 01:38:02 +01:00
|
|
|
/**
|
2017-01-21 17:49:37 +01:00
|
|
|
* Gets the Runtime Directory
|
2016-12-19 01:38:02 +01:00
|
|
|
*
|
2017-01-21 17:49:37 +01:00
|
|
|
* @return Directory
|
2016-12-19 01:38:02 +01:00
|
|
|
*/
|
2017-01-21 17:49:37 +01:00
|
|
|
public UniversalFile getRuntimeDirectory() {
|
|
|
|
return plugin.dir;
|
2016-12-19 01:38:02 +01:00
|
|
|
}
|
|
|
|
|
2016-12-05 04:21:04 +01:00
|
|
|
/**
|
|
|
|
* Gets the SubServers Version
|
|
|
|
*
|
|
|
|
* @return SubServers Version
|
|
|
|
*/
|
|
|
|
public Version getWrapperVersion() {
|
|
|
|
return plugin.version;
|
|
|
|
}
|
2017-01-21 17:49:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the BungeeCord Version
|
|
|
|
*
|
|
|
|
* @return BungeeCord Version
|
|
|
|
*/
|
|
|
|
public Version getProxyVersion() {
|
|
|
|
return new Version(plugin.getVersion());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the Recommended Minecraft Version
|
|
|
|
*
|
|
|
|
* @return Minecraft Version
|
|
|
|
*/
|
|
|
|
public Version getGameVersion() {
|
2017-12-13 18:29:50 +01:00
|
|
|
if (System.getProperty("subservers.minecraft.version", "").length() > 0) {
|
|
|
|
return new Version(System.getProperty("subservers.minecraft.version"));
|
|
|
|
} else {
|
|
|
|
String raw = plugin.getGameVersion();
|
|
|
|
if (raw.contains(",")) {
|
|
|
|
String[] split = raw.split(",\\s*");
|
|
|
|
return new Version(split[split.length - 1]);
|
|
|
|
} else if (raw.contains("-")) {
|
|
|
|
String[] split = raw.split("\\s*-\\s*");
|
|
|
|
return new Version(split[split.length - 1]);
|
|
|
|
} else {
|
|
|
|
return new Version(plugin.getGameVersion());
|
|
|
|
}
|
|
|
|
}
|
2017-01-21 17:49:37 +01:00
|
|
|
}
|
2016-12-05 04:21:04 +01:00
|
|
|
}
|