2016-12-24 05:55:17 +01:00
|
|
|
package net.ME1312.SubServers.Bungee;
|
2016-12-05 04:21:04 +01:00
|
|
|
|
2020-11-14 08:07:25 +01:00
|
|
|
import net.ME1312.Galaxi.Library.Container.ContainedPair;
|
2020-11-16 21:34:59 +01:00
|
|
|
import net.ME1312.Galaxi.Library.Container.Pair;
|
2021-10-24 06:14:07 +02:00
|
|
|
import net.ME1312.Galaxi.Library.Try;
|
2020-11-16 21:34:59 +01:00
|
|
|
import net.ME1312.Galaxi.Library.Util;
|
|
|
|
import net.ME1312.Galaxi.Library.Version.Version;
|
2020-06-12 07:45:49 +02:00
|
|
|
import net.ME1312.SubData.Server.DataProtocol;
|
2019-04-18 16:02:09 +02:00
|
|
|
import net.ME1312.SubData.Server.DataServer;
|
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;
|
2019-05-09 22:17:15 +02:00
|
|
|
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidServerException;
|
2020-11-16 21:34:59 +01:00
|
|
|
|
|
|
|
import com.google.common.collect.Range;
|
2020-11-14 19:12:08 +01:00
|
|
|
import net.md_5.bungee.api.config.ServerInfo;
|
2018-05-24 04:27:20 +02:00
|
|
|
import net.md_5.bungee.protocol.ProtocolConstants;
|
2016-12-05 04:21:04 +01:00
|
|
|
|
2021-10-24 06:14:07 +02:00
|
|
|
import java.io.File;
|
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
|
|
|
|
*/
|
2020-11-14 04:41:56 +01:00
|
|
|
public final class SubAPI implements BungeeAPI {
|
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>();
|
2019-08-30 21:44:54 +02:00
|
|
|
private final SubProxy plugin;
|
2016-12-05 04:21:04 +01:00
|
|
|
private static SubAPI api;
|
|
|
|
|
2020-06-12 07:45:49 +02:00
|
|
|
SubAPI(SubProxy plugin) {
|
2016-12-05 04:21:04 +01:00
|
|
|
this.plugin = plugin;
|
2018-07-22 07:35:04 +02:00
|
|
|
GAME_VERSION = getGameVersion();
|
2016-12-05 04:21:04 +01:00
|
|
|
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
|
2019-08-30 21:44:54 +02:00
|
|
|
public SubProxy getInternals() {
|
2016-12-05 04:21:04 +01:00
|
|
|
return plugin;
|
|
|
|
}
|
|
|
|
|
2017-01-26 23:19:48 +01:00
|
|
|
/**
|
2021-02-07 05:53:03 +01:00
|
|
|
* Adds a SubAPI Reload Listener
|
2017-01-26 23:19:48 +01:00
|
|
|
*
|
2017-12-13 18:29:50 +01:00
|
|
|
* @param reload An Event that will be called after SubAPI is soft-reloaded
|
|
|
|
*/
|
2021-02-07 05:53:03 +01:00
|
|
|
public void addListener(Runnable reload) {
|
2017-12-13 18:29:50 +01:00
|
|
|
if (reload != null) reloadListeners.add(reload);
|
2017-01-26 23:19:48 +01:00
|
|
|
}
|
|
|
|
|
2016-12-05 04:21:04 +01:00
|
|
|
/**
|
2020-06-12 07:45:49 +02:00
|
|
|
* Gets the SubData Network
|
2016-12-05 04:21:04 +01:00
|
|
|
*
|
2020-06-12 07:45:49 +02:00
|
|
|
* @return SubData Network
|
2016-12-05 04:21:04 +01:00
|
|
|
*/
|
2019-04-18 16:02:09 +02:00
|
|
|
public DataServer getSubDataNetwork() {
|
2016-12-05 04:21:04 +01:00
|
|
|
return plugin.subdata;
|
|
|
|
}
|
|
|
|
|
2020-06-12 07:45:49 +02:00
|
|
|
/**
|
|
|
|
* Gets the SubData Network Protocol
|
|
|
|
*
|
|
|
|
* @return SubData Network Protocol
|
|
|
|
*/
|
|
|
|
public DataProtocol getSubDataProtocol() {
|
|
|
|
return plugin.subprotocol;
|
|
|
|
}
|
|
|
|
|
2016-12-05 04:21:04 +01:00
|
|
|
/**
|
|
|
|
* Adds a Driver for Hosts
|
|
|
|
*
|
|
|
|
* @param driver Driver to add
|
|
|
|
* @param handle Handle to Bind
|
|
|
|
*/
|
|
|
|
public void addHostDriver(Class<? extends Host> driver, String handle) {
|
2021-10-24 06:14:07 +02:00
|
|
|
Util.nullpo(driver, handle);
|
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) {
|
2021-06-15 06:09:51 +02:00
|
|
|
if (Util.isNull(name)) return null;
|
|
|
|
return plugin.hosts.get(name.toLowerCase());
|
2016-12-05 04:21:04 +01:00
|
|
|
}
|
|
|
|
|
2017-08-22 15:02:23 +02:00
|
|
|
/**
|
|
|
|
* Add a Host to the Network
|
|
|
|
*
|
|
|
|
* @param driver Driver to initiate
|
2019-01-05 22:04:45 +01:00
|
|
|
* @param name The Name of your Host
|
|
|
|
* @param ports The range of ports to auto-select from
|
|
|
|
* @param log Whether apps like SubCreator should log to console (does not apply to servers)
|
|
|
|
* @param enabled If your host is Enabled
|
|
|
|
* @param address The address of your Host
|
|
|
|
* @param directory The runtime directory of your Host
|
|
|
|
* @param gitBash The Git Bash directory
|
2017-08-22 15:02:23 +02:00
|
|
|
* @return The Host
|
|
|
|
* @throws NoSuchMethodException
|
|
|
|
* @throws IllegalAccessException
|
|
|
|
* @throws InvocationTargetException
|
|
|
|
* @throws InstantiationException
|
|
|
|
*/
|
2019-01-05 22:04:45 +01:00
|
|
|
public Host addHost(String driver, String name, boolean enabled, Range<Integer> ports, boolean log, InetAddress address, String directory, String gitBash) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
|
|
|
|
return addHost(null, driver, name, enabled, ports, log, address, directory, gitBash);
|
2017-08-22 15:02:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a Host to the Network
|
|
|
|
*
|
|
|
|
* @param player Player who added
|
|
|
|
* @param driver Driver to initiate
|
2019-01-05 22:04:45 +01:00
|
|
|
* @param name The Name of your Host
|
|
|
|
* @param ports The range of ports to auto-select from
|
|
|
|
* @param log Whether apps like SubCreator should log to console (does not apply to servers)
|
|
|
|
* @param enabled If your host is Enabled
|
|
|
|
* @param address The address of your Host
|
|
|
|
* @param directory The runtime directory of your Host
|
|
|
|
* @param gitBash The Git Bash directory
|
2017-08-22 15:02:23 +02:00
|
|
|
* @return The Host
|
|
|
|
* @throws NoSuchMethodException
|
|
|
|
* @throws IllegalAccessException
|
|
|
|
* @throws InvocationTargetException
|
|
|
|
* @throws InstantiationException
|
|
|
|
*/
|
2019-01-05 22:04:45 +01:00
|
|
|
public Host addHost(UUID player, String driver, String name, boolean enabled, Range<Integer> ports, boolean log, InetAddress address, String directory, String gitBash) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
|
2021-10-24 06:14:07 +02:00
|
|
|
Util.nullpo(driver, name, enabled, ports, log, address, directory, gitBash);
|
2018-01-12 22:56:22 +01:00
|
|
|
if (!getHostDrivers().contains(driver.toUpperCase().replace('-', '_').replace(' ', '_'))) throw new InvalidHostException("Invalid Driver for host: " + name);
|
2019-01-05 22:04:45 +01:00
|
|
|
return addHost(player, plugin.hostDrivers.get(driver.toUpperCase().replace('-', '_').replace(' ', '_')), name, enabled, ports, log, address, directory, gitBash);
|
2018-10-08 23:07:44 +02:00
|
|
|
}
|
2017-12-17 22:04:05 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a Host with a potentially unregistered driver to the Network
|
|
|
|
*
|
|
|
|
* @param driver Driver to initiate
|
2019-01-05 22:04:45 +01:00
|
|
|
* @param name The Name of your Host
|
|
|
|
* @param ports The range of ports to auto-select from
|
|
|
|
* @param log Whether apps like SubCreator should log to console (does not apply to servers)
|
|
|
|
* @param enabled If your host is Enabled
|
|
|
|
* @param address The address of your Host
|
|
|
|
* @param directory The runtime directory of your Host
|
|
|
|
* @param gitBash The Git Bash directory
|
2017-12-17 22:04:05 +01:00
|
|
|
* @return The Host
|
|
|
|
* @throws NoSuchMethodException
|
|
|
|
* @throws IllegalAccessException
|
|
|
|
* @throws InvocationTargetException
|
|
|
|
* @throws InstantiationException
|
|
|
|
*/
|
2019-01-05 22:04:45 +01:00
|
|
|
public Host addHost(Class<? extends Host> driver, String name, boolean enabled, Range<Integer> ports, boolean log, InetAddress address, String directory, String gitBash) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
|
|
|
|
return addHost(null, driver, name, enabled, ports, log, address, directory, gitBash);
|
2017-12-17 22:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a Host with a potentially unregistered driver to the Network
|
|
|
|
*
|
|
|
|
* @param player Player who added
|
|
|
|
* @param driver Driver to initiate
|
2019-01-05 22:04:45 +01:00
|
|
|
* @param name The Name of your Host
|
|
|
|
* @param ports The range of ports to auto-select from
|
|
|
|
* @param log Whether apps like SubCreator should log to console (does not apply to servers)
|
|
|
|
* @param enabled If your host is Enabled
|
|
|
|
* @param address The address of your Host
|
|
|
|
* @param directory The runtime directory of your Host
|
|
|
|
* @param gitBash The Git Bash directory
|
2017-12-17 22:04:05 +01:00
|
|
|
* @return The Host
|
|
|
|
* @throws NoSuchMethodException
|
|
|
|
* @throws IllegalAccessException
|
|
|
|
* @throws InvocationTargetException
|
|
|
|
* @throws InstantiationException
|
|
|
|
*/
|
2019-01-05 22:04:45 +01:00
|
|
|
public Host addHost(UUID player, Class<? extends Host> driver, String name, boolean enabled, Range<Integer> ports, boolean log, InetAddress address, String directory, String gitBash) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
|
2021-10-24 06:14:07 +02:00
|
|
|
Util.nullpo(driver, name, enabled, ports, log, address, directory, gitBash);
|
2021-06-06 07:28:22 +02:00
|
|
|
Host host = plugin.constructHost(driver, name, enabled, ports, log, address, directory, gitBash);
|
2018-01-12 22:56:22 +01:00
|
|
|
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) {
|
2021-10-24 06:14:07 +02:00
|
|
|
Util.nullpo(name, getHost(name));
|
2017-08-22 15:02:23 +02:00
|
|
|
SubRemoveHostEvent event = new SubRemoveHostEvent(player, getHost(name));
|
|
|
|
plugin.getPluginManager().callEvent(event);
|
2021-07-09 07:46:10 +02:00
|
|
|
if (!event.isCancelled()) {
|
2019-08-30 02:01:52 +02:00
|
|
|
if (getHost(name).destroy()) {
|
2017-12-09 09:43:29 +01:00
|
|
|
plugin.hosts.remove(name.toLowerCase());
|
|
|
|
return true;
|
2019-08-30 02:01:52 +02:00
|
|
|
} else {
|
2017-12-09 09:43:29 +01:00
|
|
|
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) {
|
2021-10-24 06:14:07 +02:00
|
|
|
Util.nullpo(name, getHost(name));
|
2017-08-22 15:02:23 +02:00
|
|
|
SubRemoveHostEvent event = new SubRemoveHostEvent(player, getHost(name));
|
|
|
|
plugin.getPluginManager().callEvent(event);
|
2019-08-30 02:01:52 +02:00
|
|
|
if (getHost(name).destroy()) {
|
2017-12-09 09:43:29 +01:00
|
|
|
plugin.hosts.remove(name.toLowerCase());
|
|
|
|
return true;
|
2019-08-30 02:01:52 +02:00
|
|
|
} else {
|
2017-12-09 09:43:29 +01:00
|
|
|
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);
|
|
|
|
}
|
2021-06-12 00:16:05 +02:00
|
|
|
List<Server> list = (groups.keySet().contains(group))?groups.get(group):new LinkedList<Server>();
|
2017-12-06 23:34:47 +01:00
|
|
|
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
|
|
|
|
*/
|
2020-11-14 08:07:25 +01:00
|
|
|
public Pair<String, List<Server>> getGroup(String name) {
|
2021-06-15 06:09:51 +02:00
|
|
|
if (Util.isNull(name)) return null;
|
2020-06-12 07:45:49 +02:00
|
|
|
for (Map.Entry<String, List<Server>> group : getLowercaseGroups().entrySet()) {
|
2020-11-14 08:07:25 +01:00
|
|
|
if (group.getKey().equalsIgnoreCase(name)) return new ContainedPair<>(group.getKey(), group.getValue());
|
2020-06-12 07:45:49 +02:00
|
|
|
}
|
|
|
|
return null;
|
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) {
|
2021-06-15 06:09:51 +02:00
|
|
|
if (Util.isNull(name)) return null;
|
|
|
|
Server server = plugin.exServers.getOrDefault(name.toLowerCase(), null);
|
|
|
|
return (server == null)? getSubServer(name) : server;
|
2017-08-22 15:02:23 +02:00
|
|
|
}
|
|
|
|
|
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) {
|
2020-06-12 07:45:49 +02:00
|
|
|
Server server = ServerImpl.construct(name, new InetSocketAddress(ip, port), motd, hidden, restricted);
|
2021-06-06 07:28:22 +02:00
|
|
|
return (addServer(player, server))?server:null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a Server to the Network
|
|
|
|
*
|
|
|
|
* @param server Server to add
|
|
|
|
* @return Success status
|
|
|
|
*/
|
|
|
|
public boolean addServer(Server server) {
|
|
|
|
return addServer(null, server);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a Server to the Network
|
|
|
|
*
|
|
|
|
* @param player Player who added
|
|
|
|
* @param server Server to add
|
|
|
|
* @return Success status
|
|
|
|
*/
|
|
|
|
public boolean addServer(UUID player, Server server) {
|
|
|
|
if (getServers().keySet().contains(server.getName().toLowerCase())) throw new InvalidServerException("A Server already exists with this name!");
|
2016-12-15 22:04:39 +01:00
|
|
|
SubAddServerEvent event = new SubAddServerEvent(player, null, server);
|
|
|
|
plugin.getPluginManager().callEvent(event);
|
|
|
|
if (!event.isCancelled()) {
|
2021-06-06 07:28:22 +02:00
|
|
|
plugin.exServers.put(server.getName().toLowerCase(), server);
|
|
|
|
return true;
|
2016-12-15 22:04:39 +01:00
|
|
|
} else {
|
2021-06-06 07:28:22 +02:00
|
|
|
return false;
|
2016-12-15 22:04:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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) {
|
2021-10-24 06:14:07 +02:00
|
|
|
Util.nullpo(name, getServer(name));
|
2017-08-22 15:02:23 +02:00
|
|
|
SubRemoveServerEvent event = new SubRemoveServerEvent(player, null, getServer(name));
|
|
|
|
plugin.getPluginManager().callEvent(event);
|
2021-07-09 07:46:10 +02:00
|
|
|
if (!event.isCancelled()) {
|
2017-08-22 15:02:23 +02:00
|
|
|
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) {
|
2021-10-24 06:14:07 +02:00
|
|
|
Util.nullpo(name, getServer(name));
|
2017-08-22 15:02:23 +02:00
|
|
|
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) {
|
2021-06-15 06:09:51 +02:00
|
|
|
if (Util.isNull(name)) return null;
|
|
|
|
SubServer server;
|
|
|
|
for (Host host : plugin.hosts.values()) {
|
|
|
|
server = host.getSubServer(name);
|
|
|
|
if (server != null) return server;
|
|
|
|
}
|
|
|
|
return null;
|
2016-12-05 04:21:04 +01:00
|
|
|
}
|
|
|
|
|
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) {
|
2021-06-15 06:09:51 +02:00
|
|
|
if (Util.isNull(name)) return null;
|
|
|
|
Proxy proxy = plugin.proxies.getOrDefault(name.toLowerCase(), null);
|
2020-07-25 07:20:59 +02:00
|
|
|
if (proxy == null && plugin.mProxy != null && plugin.mProxy.getName().equalsIgnoreCase(name)) proxy = plugin.mProxy;
|
2020-06-12 07:45:49 +02:00
|
|
|
return proxy;
|
2018-01-22 16:01:33 +01:00
|
|
|
}
|
|
|
|
|
2018-08-09 20:54:56 +02:00
|
|
|
/**
|
2020-11-14 08:07:25 +01:00
|
|
|
* Get the Master Proxy Value
|
2018-08-09 20:54:56 +02:00
|
|
|
*
|
|
|
|
* @return Master Proxy
|
|
|
|
*/
|
|
|
|
public Proxy getMasterProxy() {
|
2020-07-25 07:20:59 +02:00
|
|
|
return plugin.mProxy;
|
2018-08-09 20:54:56 +02:00
|
|
|
}
|
|
|
|
|
2020-11-14 19:12:08 +01:00
|
|
|
/**
|
|
|
|
* Get the number of players on this network across all known proxies
|
|
|
|
*
|
|
|
|
* @return Remote Player Count
|
|
|
|
*/
|
|
|
|
public int getRemotePlayerCount() {
|
|
|
|
return plugin.rPlayers.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get players on this server across all known proxies
|
|
|
|
*
|
|
|
|
* @param server Server to search
|
|
|
|
* @return Remote Player Map
|
|
|
|
*/
|
|
|
|
public Map<UUID, RemotePlayer> getRemotePlayers(ServerInfo server) {
|
|
|
|
if (server instanceof Server) {
|
|
|
|
HashMap<UUID, RemotePlayer> players = new HashMap<UUID, RemotePlayer>();
|
|
|
|
for (UUID id : Util.getBackwards(plugin.rPlayerLinkS, (Server) server))
|
|
|
|
players.put(id, plugin.rPlayers.get(id));
|
|
|
|
return players;
|
|
|
|
} else {
|
|
|
|
return new HashMap<>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-10 15:14:49 +01:00
|
|
|
/**
|
|
|
|
* Get players on this network across all known proxies
|
|
|
|
*
|
2020-11-14 19:12:08 +01:00
|
|
|
* @return Remote Player Map
|
2017-12-10 15:14:49 +01:00
|
|
|
*/
|
2020-11-14 19:12:08 +01:00
|
|
|
public Map<UUID, RemotePlayer> getRemotePlayers() {
|
2020-07-25 07:20:59 +02:00
|
|
|
return new HashMap<UUID, RemotePlayer>(plugin.rPlayers);
|
2017-12-10 15:14:49 +01:00
|
|
|
}
|
|
|
|
|
2020-06-12 07:45:49 +02:00
|
|
|
/**
|
|
|
|
* Get a player on this network by searching across all known proxies
|
|
|
|
*
|
|
|
|
* @param name Player name
|
|
|
|
* @return Remote Player
|
|
|
|
*/
|
2020-11-14 19:12:08 +01:00
|
|
|
public RemotePlayer getRemotePlayer(String name) {
|
2021-10-24 06:14:07 +02:00
|
|
|
Util.nullpo(name);
|
2021-06-15 06:09:51 +02:00
|
|
|
for (RemotePlayer player : plugin.rPlayers.values()) {
|
2020-07-25 07:20:59 +02:00
|
|
|
if (player.getName().equalsIgnoreCase(name)) return player;
|
|
|
|
}
|
|
|
|
return null;
|
2020-06-12 07:45:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a player on this network by searching across all known proxies
|
|
|
|
*
|
|
|
|
* @param id Player UUID
|
|
|
|
* @return Remote Player
|
|
|
|
*/
|
2020-11-14 19:12:08 +01:00
|
|
|
public RemotePlayer getRemotePlayer(UUID id) {
|
2021-10-24 06:14:07 +02:00
|
|
|
Util.nullpo(id);
|
2021-06-15 06:09:51 +02:00
|
|
|
return plugin.rPlayers.getOrDefault(id, null);
|
2020-06-12 07:45:49 +02:00
|
|
|
}
|
|
|
|
|
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) {
|
2021-10-24 06:14:07 +02:00
|
|
|
Util.nullpo(channel, key, value);
|
2021-06-15 06:09:51 +02:00
|
|
|
LinkedHashMap<String, String> map = (plugin.exLang.containsKey(channel.toLowerCase()))?plugin.exLang.get(channel.toLowerCase()):new LinkedHashMap<String, String>();
|
2018-01-02 23:29:25 +01:00
|
|
|
map.put(key, value);
|
2019-04-29 17:05:06 +02:00
|
|
|
plugin.exLang.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() {
|
2019-04-29 17:05:06 +02:00
|
|
|
return plugin.exLang.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) {
|
2021-06-15 06:09:51 +02:00
|
|
|
if (Util.isNull(channel)) return null;
|
2019-04-29 17:05:06 +02:00
|
|
|
return new LinkedHashMap<>(plugin.exLang.get(channel.toLowerCase()));
|
2017-01-21 17:49:37 +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) {
|
2021-10-24 06:14:07 +02:00
|
|
|
Util.nullpo(signature);
|
2021-06-15 06:09:51 +02:00
|
|
|
return (R) knownSignatures.getOrDefault(signature, null);
|
2017-12-13 18:29:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
*/
|
2021-10-24 06:14:07 +02:00
|
|
|
public File getRuntimeDirectory() {
|
2017-01-21 17:49:37 +01:00
|
|
|
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
|
|
|
|
2018-07-29 20:39:42 +02:00
|
|
|
/**
|
|
|
|
* Gets the SubServers Build Signature
|
|
|
|
*
|
|
|
|
* @return SubServers Build Signature (or null if unsigned)
|
|
|
|
*/
|
|
|
|
public Version getWrapperBuild() {
|
2019-08-30 21:44:54 +02:00
|
|
|
return (SubProxy.class.getPackage().getSpecificationTitle() != null)?new Version(SubProxy.class.getPackage().getSpecificationTitle()):null;
|
2018-07-29 20:39:42 +02:00
|
|
|
}
|
|
|
|
|
2017-01-21 17:49:37 +01:00
|
|
|
/**
|
|
|
|
* Gets the BungeeCord Version
|
|
|
|
*
|
|
|
|
* @return BungeeCord Version
|
|
|
|
*/
|
|
|
|
public Version getProxyVersion() {
|
|
|
|
return new Version(plugin.getVersion());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-05-24 04:27:20 +02:00
|
|
|
* Get an array of compatible Minecraft Versions
|
|
|
|
*
|
|
|
|
* @return Minecraft Versions
|
|
|
|
*/
|
|
|
|
public Version[] getGameVersion() {
|
|
|
|
if (GAME_VERSION == null) {
|
|
|
|
if (System.getProperty("subservers.minecraft.version", "").length() > 0) {
|
|
|
|
return new Version[]{new Version(System.getProperty("subservers.minecraft.version"))};
|
2021-10-24 06:14:07 +02:00
|
|
|
} else if (Try.all.get(() -> ProtocolConstants.SUPPORTED_VERSIONS != null, false)) {
|
2018-05-24 04:27:20 +02:00
|
|
|
List<Version> versions = new LinkedList<Version>();
|
|
|
|
for (String version : ProtocolConstants.SUPPORTED_VERSIONS) versions.add(new Version(version));
|
|
|
|
Collections.sort(versions);
|
|
|
|
return versions.toArray(new Version[versions.size()]);
|
2021-10-24 06:14:07 +02:00
|
|
|
} else if (Try.all.get(() -> plugin.getGameVersion() != null, false)) {
|
2018-05-24 04:27:20 +02:00
|
|
|
String raw = plugin.getGameVersion();
|
|
|
|
if (raw.contains("-") || raw.contains(",")) {
|
|
|
|
List<Version> versions = new LinkedList<Version>();
|
|
|
|
for (String version : raw.split("(?:\\s*-|,)\\s*")) versions.add(new Version(version));
|
|
|
|
Collections.sort(versions);
|
|
|
|
return versions.toArray(new Version[versions.size()]);
|
|
|
|
} else {
|
|
|
|
return new Version[]{new Version(plugin.getGameVersion())};
|
2018-05-23 06:26:03 +02:00
|
|
|
}
|
2017-12-13 18:29:50 +01:00
|
|
|
} else {
|
2018-05-24 04:27:20 +02:00
|
|
|
plugin.getLogger().warning("Could not determine compatible Minecraft version(s); Now using 1.x.x as a placeholder.");
|
|
|
|
plugin.getLogger().warning("Use this launch argument to specify a compatible Minecraft version: -Dsubservers.minecraft.version=1.x.x");
|
|
|
|
return new Version[]{new Version("1.x.x")};
|
2017-12-13 18:29:50 +01:00
|
|
|
}
|
2018-05-24 04:27:20 +02:00
|
|
|
} else return GAME_VERSION;
|
2017-01-21 17:49:37 +01:00
|
|
|
}
|
2018-07-22 07:35:04 +02:00
|
|
|
private final Version[] GAME_VERSION;
|
2016-12-05 04:21:04 +01:00
|
|
|
}
|