Improved efficiency when accessing maps

Also, #75 Support for hosts, groups, and external servers on signs
This commit is contained in:
ME1312 2022-03-18 11:57:38 -04:00
parent f6ce5c92fb
commit 58ae08db1e
No known key found for this signature in database
GPG Key ID: FEFFE2F698E88FA8
59 changed files with 365 additions and 219 deletions

View File

@ -19,7 +19,7 @@ public class Logger {
* @return Logger
*/
public static java.util.logging.Logger get(String prefix) {
if (!existing.keySet().contains(prefix)) {
if (!existing.containsKey(prefix)) {
java.util.logging.Logger log = java.util.logging.Logger.getAnonymousLogger();
log.setUseParentHandlers(false);
log.addHandler(new Handler() {

View File

@ -153,7 +153,7 @@ public class SmartFallback implements ReconnectHandler {
}
if (valid) {
List<ServerInfo> servers = (score.keySet().contains(confidence))?score.get(confidence):new LinkedList<ServerInfo>();
List<ServerInfo> servers = (score.containsKey(confidence))?score.get(confidence):new LinkedList<ServerInfo>();
servers.add(server);
score.put(confidence, servers);
}

View File

@ -81,7 +81,7 @@ public class ExternalHost extends Host implements ClientHandler {
if (channel < 0) throw new IllegalArgumentException("Subchannel ID cannot be less than zero");
if (client == null && channel == 0) available = false;
if (client != null || channel == 0) {
if (!subdata.keySet().contains(channel) || (channel == 0 && (client == null || subdata.get(channel) == null))) {
if (!subdata.containsKey(channel) || (channel == 0 && (client == null || subdata.get(channel) == null))) {
subdata.put(channel, (SubDataClient) client);
if (client != null && (client.getHandler() == null || !equals(client.getHandler()))) ((SubDataClient) client).setHandler(this);
}

View File

@ -94,7 +94,7 @@ public class ExternalSubCreator extends SubCreator {
@Override
public boolean create(UUID player, String name, ServerTemplate template, Version version, Integer port, Consumer<SubServer> callback) {
Util.nullpo(name, template);
if (host.isAvailable() && host.isEnabled() && template.isEnabled() && !SubAPI.getInstance().getSubServers().keySet().contains(name.toLowerCase()) && !SubCreator.isReserved(name) && (version != null || !template.requiresVersion())) {
if (host.isAvailable() && host.isEnabled() && template.isEnabled() && !SubAPI.getInstance().getSubServers().containsKey(name.toLowerCase()) && !SubCreator.isReserved(name) && (version != null || !template.requiresVersion())) {
StackTraceElement[] origin = new Throwable().getStackTrace();
if (port == null) {
@ -174,7 +174,7 @@ public class ExternalSubCreator extends SubCreator {
Logger.get(prefix).info("Saving...");
SubServer subserver = update;
if (update == null || update.getTemplate() != template || template.getBuildOptions().getBoolean("Update-Settings", false)) {
if (host.plugin.exServers.keySet().contains(name.toLowerCase()))
if (host.plugin.exServers.containsKey(name.toLowerCase()))
host.plugin.exServers.remove(name.toLowerCase());
ObjectMap<String> server = new ObjectMap<String>();
@ -257,7 +257,7 @@ public class ExternalSubCreator extends SubCreator {
@Override
public void terminate(String name) {
if (this.thread.keySet().contains(name.toLowerCase())) {
if (this.thread.containsKey(name.toLowerCase())) {
((SubDataClient) host.getSubData()[0]).sendPacket(new PacketExCreateServer(name.toLowerCase()));
thread.remove(name.toLowerCase());
}
@ -274,7 +274,7 @@ public class ExternalSubCreator extends SubCreator {
@Override
public void waitFor(String name) throws InterruptedException {
while (this.thread.keySet().contains(name.toLowerCase()) && host.getSubData()[0] != null) {
while (this.thread.containsKey(name.toLowerCase()) && host.getSubData()[0] != null) {
Thread.sleep(250);
}
}

View File

@ -276,7 +276,7 @@ public class InternalSubCreator extends SubCreator {
Logger.get(prefix).info("Saving...");
SubServer subserver = update;
if (update == null || update.getTemplate() != template || template.getBuildOptions().getBoolean("Update-Settings", false)) {
if (host.plugin.exServers.keySet().contains(name.toLowerCase()))
if (host.plugin.exServers.containsKey(name.toLowerCase()))
host.plugin.exServers.remove(name.toLowerCase());
config = new ObjectMap<String>((Map<String, ?>) replacements.replace(config.get()));
@ -389,7 +389,7 @@ public class InternalSubCreator extends SubCreator {
@Override
public boolean create(UUID player, String name, ServerTemplate template, Version version, Integer port, Consumer<SubServer> callback) {
Util.nullpo(name, template);
if (host.isAvailable() && host.isEnabled() && template.isEnabled() && !SubAPI.getInstance().getSubServers().keySet().contains(name.toLowerCase()) && !SubCreator.isReserved(name) && (version != null || !template.requiresVersion())) {
if (host.isAvailable() && host.isEnabled() && template.isEnabled() && !SubAPI.getInstance().getSubServers().containsKey(name.toLowerCase()) && !SubCreator.isReserved(name) && (version != null || !template.requiresVersion())) {
StackTraceElement[] origin = new Throwable().getStackTrace();
if (port == null) {
@ -470,7 +470,7 @@ public class InternalSubCreator extends SubCreator {
@Override
public void terminate(String name) {
if (this.thread.keySet().contains(name.toLowerCase())) {
if (this.thread.containsKey(name.toLowerCase())) {
if (this.thread.get(name.toLowerCase()).process != null && this.thread.get(name.toLowerCase()).process.isAlive()) {
Executable.terminate(this.thread.get(name.toLowerCase()).process);
} else if (this.thread.get(name.toLowerCase()).isAlive()) {
@ -491,7 +491,7 @@ public class InternalSubCreator extends SubCreator {
@Override
public void waitFor(String name) throws InterruptedException {
while (this.thread.keySet().contains(name.toLowerCase()) && this.thread.get(name.toLowerCase()).isAlive()) {
while (this.thread.containsKey(name.toLowerCase()) && this.thread.get(name.toLowerCase()).isAlive()) {
Thread.sleep(250);
}
}

View File

@ -50,7 +50,7 @@ public class Proxy implements ClientHandler, ExtraDataHandler<String> {
boolean update = false;
if (channel < 0) throw new IllegalArgumentException("Subchannel ID cannot be less than zero");
if (client != null || channel == 0) {
if (!subdata.keySet().contains(channel) || (channel == 0 && (client == null || subdata.get(channel) == null))) {
if (!subdata.containsKey(channel) || (channel == 0 && (client == null || subdata.get(channel) == null))) {
update = true;
subdata.put(channel, client);
if (client != null && (client.getHandler() == null || !equals(client.getHandler()))) client.setHandler(this);

View File

@ -105,7 +105,7 @@ public class ServerImpl extends BungeeServerInfo implements Server {
boolean update = false;
if (channel < 0) throw new IllegalArgumentException("Subchannel ID cannot be less than zero");
if (client != null || channel == 0) {
if (!subdata.keySet().contains(channel) || (channel == 0 && (client == null || subdata.get(channel) == null))) {
if (!subdata.containsKey(channel) || (channel == 0 && (client == null || subdata.get(channel) == null))) {
update = true;
subdata.put(channel, (SubDataClient) client);
if (client != null && (client.getHandler() == null || !equals(client.getHandler()))) ((SubDataClient) client).setHandler(this);

View File

@ -114,7 +114,7 @@ public abstract class SubServerImpl extends ServerImpl implements SubServer {
public SubCreator.ServerTemplate getTemplate() {
if (templateV != null) {
return templateV;
} else if (templateS != null && getHost().getCreator().getTemplates().keySet().contains(templateS.toLowerCase())) {
} else if (templateS != null && getHost().getCreator().getTemplates().containsKey(templateS.toLowerCase())) {
return getHost().getCreator().getTemplate(templateS.toLowerCase());
} else {
return null;

View File

@ -324,9 +324,13 @@ public class ConfigUpdater {
existing = updated.clone();
i++;
} if (was.compareTo(new Version("22w10a")) <= 0) {
} if (was.compareTo(new Version("22w11a")) <= 0) {
if (existing.contains("Lang")) {
updated.getMap("Lang").remove("Command.Teleport");
LinkedList<String> keys = new LinkedList<>(existing.getMap("Lang").getKeys());
for (String key : keys) if (key.startsWith("Signs.")) {
updated.getMap("Lang").remove(key);
}
}
existing = updated.clone();
@ -363,11 +367,11 @@ public class ConfigUpdater {
def.put("Bungee.List.Total", "Total players online: $int$");
def.put("Signs.Create", "&aSubServers &2&l\\u00BB&a Server sign activated");
def.put("Signs.Delete", "&aSubServers &2&l\\u00BB&a Server sign removed");
def.put("Signs.Text.Error", "&f&oSubServers\\n&3$str$\\n&7Unknown Status\\n&8\\u2022 \\u2022 \\u2022 \\u2022 \\u2022 \\u2022 \\u2022");
def.put("Signs.Text.Offline", "&c&oSubServers\\n&3#subserver.displayname($str$)\\n&4Offline\\n&7Click to Start");
def.put("Signs.Text.Starting", "&e&oSubServers\\n&3#subserver.displayname($str$)\\n&6Starting\\n&8\\u2022 \\u2022 \\u2022 \\u2022 \\u2022 \\u2022 \\u2022");
def.put("Signs.Text.Online", "&a&oSubServers\\n&3#subserver.displayname($str$)\\n&2#subserver.players($str$) Online\\n&7Click to Join");
def.put("Signs.Text.Stopping", "&e&oSubServers\\n&3#subserver.displayname($str$)\\n&6Stopping\\n&8\\u2022 \\u2022 \\u2022 \\u2022 \\u2022 \\u2022 \\u2022");
def.put("Signs.Text.Unknown", "&f&oSubServers\\n&3$str$\\n&7Unknown Status\\n&8\\u2022 \\u2022 \\u2022 \\u2022 \\u2022 \\u2022 \\u2022");
def.put("Signs.Text.Offline", "&c&oSubServers\\n&3$str$\\n&4Offline\\n&7Click to Start");
def.put("Signs.Text.Starting", "&e&oSubServers\\n&3$str$\\n&6Starting\\n&8\\u2022 \\u2022 \\u2022 \\u2022 \\u2022 \\u2022 \\u2022");
def.put("Signs.Text.Online", "&a&oSubServers\\n&3$str$\\n&2$int$ Online\\n&7Click to Join");
def.put("Signs.Text.Stopping", "&e&oSubServers\\n&3$str$\\n&6Stopping\\n&8\\u2022 \\u2022 \\u2022 \\u2022 \\u2022 \\u2022 \\u2022");
def.put("Command.Generic.Player-Only", "&cSubServers &4&l\\u00BB&c The console cannot perform this command");
def.put("Command.Generic.Console-Only", "&cSubServers &4&l\\u00BB&c This command is for console use only");
def.put("Command.Generic.Usage", "&7SubServers &8&l\\u00BB&7 Usage: &f$str$");

View File

@ -15,7 +15,7 @@ public class ReplacementScanner extends FileScanner {
TreeMap<Integer, LinkedList<String>> order = new TreeMap<Integer, LinkedList<String>>(Comparator.reverseOrder());
for (String key : replacements.keySet()) {
int length = key.length();
if (!order.keySet().contains(length)) order.put(length, new LinkedList<>());
if (!order.containsKey(length)) order.put(length, new LinkedList<>());
order.get(length).add(key);
}

View File

@ -62,7 +62,7 @@ public class PacketAddServer implements PacketObjectIn<Integer>, PacketObjectOut
ObjectMap<String> opt = new ObjectMap<>((Map<String, ?>)data.getObject(0x0003));
UUID player = (data.contains(0x0004)?data.getUUID(0x0004):null);
if (plugin.api.getServers().keySet().contains(name.toLowerCase())) {
if (plugin.api.getServers().containsKey(name.toLowerCase())) {
client.sendPacket(new PacketAddServer(3, tracker));
} else {
if (!subserver) {
@ -72,7 +72,7 @@ public class PacketAddServer implements PacketObjectIn<Integer>, PacketObjectOut
} else {
client.sendPacket(new PacketAddServer(1, tracker));
}
} else if (!plugin.api.getHosts().keySet().contains(opt.getString("host").toLowerCase())) {
} else if (!plugin.api.getHosts().containsKey(opt.getString("host").toLowerCase())) {
client.sendPacket(new PacketAddServer(4, tracker));
} else {
if (plugin.api.getHost(opt.getString("host")).addSubServer(player, name, opt.getBoolean("enabled"), opt.getInt("port"), ChatColor.translateAlternateColorCodes('&', Util.unescapeJavaString(opt.getString("motd"))),

View File

@ -59,7 +59,7 @@ public class PacketCommandServer implements PacketObjectIn<Integer>, PacketObjec
UUID target = (data.contains(0x0004)?data.getUUID(0x0004):null);
Map<String, Server> servers = plugin.api.getServers();
if (!server.equals("*") && !servers.keySet().contains(server.toLowerCase())) {
if (!server.equals("*") && !servers.containsKey(server.toLowerCase())) {
client.sendPacket(new PacketCommandServer(3, tracker));
} else if (!server.equals("*") && !(target == null && servers.get(server.toLowerCase()) instanceof SubServer) && servers.get(server.toLowerCase()).getSubData()[0] == null) {
client.sendPacket(new PacketCommandServer(4, tracker));

View File

@ -60,15 +60,15 @@ public class PacketCreateServer implements PacketObjectIn<Integer>, PacketObject
if (name.contains(" ")) {
client.sendPacket(new PacketCreateServer(3, tracker));
} else if (plugin.api.getSubServers().keySet().contains(name.toLowerCase()) || SubCreator.isReserved(name)) {
} else if (plugin.api.getSubServers().containsKey(name.toLowerCase()) || SubCreator.isReserved(name)) {
client.sendPacket(new PacketCreateServer(4, tracker));
} else if (!plugin.hosts.keySet().contains(host.toLowerCase())) {
} else if (!plugin.hosts.containsKey(host.toLowerCase())) {
client.sendPacket(new PacketCreateServer(5, tracker));
} else if (!plugin.hosts.get(host.toLowerCase()).isAvailable()) {
client.sendPacket(new PacketCreateServer(6, tracker));
} else if (!plugin.hosts.get(host.toLowerCase()).isEnabled()) {
client.sendPacket(new PacketCreateServer(7, tracker));
} else if (!plugin.hosts.get(host.toLowerCase()).getCreator().getTemplates().keySet().contains(template.toLowerCase())) {
} else if (!plugin.hosts.get(host.toLowerCase()).getCreator().getTemplates().containsKey(template.toLowerCase())) {
client.sendPacket(new PacketCreateServer(8, tracker));
} else if (!plugin.hosts.get(host.toLowerCase()).getCreator().getTemplate(template).isEnabled()) {
client.sendPacket(new PacketCreateServer(9, tracker));

View File

@ -59,7 +59,7 @@ public class PacketDeleteServer implements PacketObjectIn<Integer>, PacketObject
UUID player = (data.contains(0x0004)?data.getUUID(0x0004):null);
Map<String, Server> servers = plugin.api.getServers();
if (!servers.keySet().contains(name.toLowerCase())) {
if (!servers.containsKey(name.toLowerCase())) {
client.sendPacket(new PacketDeleteServer(3, tracker));
} else if (!(servers.get(name.toLowerCase()) instanceof SubServer)) {
client.sendPacket(new PacketDeleteServer(4, tracker));

View File

@ -74,7 +74,7 @@ public class PacketEditServer implements PacketObjectIn<Integer>, PacketObjectOu
UUID player = (data.contains(0x0004)?data.getUUID(0x0004):null);
Map<String, Server> servers = plugin.api.getServers();
if (!servers.keySet().contains(name.toLowerCase())) {
if (!servers.containsKey(name.toLowerCase())) {
client.sendPacket(new PacketEditServer(3, tracker));
} else if (!(servers.get(name.toLowerCase()) instanceof SubServer)) {
client.sendPacket(new PacketEditServer(4, tracker));

View File

@ -59,12 +59,12 @@ public class PacketLinkExHost implements InitialPacket, PacketObjectIn<Integer>,
public void receive(SubDataClient client, ObjectMap<Integer> data) {
try {
Map<String, Host> hosts = plugin.api.getHosts();
if (hosts.keySet().contains(data.getString(0x0000).toLowerCase())) {
if (hosts.containsKey(data.getString(0x0000).toLowerCase())) {
Host host = hosts.get(data.getString(0x0000).toLowerCase());
if (host instanceof ExternalHost) {
Integer channel = data.getInt(0x0001);
HashMap<Integer, SubDataClient> subdata = Try.all.get(() -> Util.reflect(ExternalHost.class.getDeclaredField("subdata"), host));
if (!subdata.keySet().contains(channel) || (channel == 0 && subdata.get(0) == null)) {
if (!subdata.containsKey(channel) || (channel == 0 && subdata.get(0) == null)) {
((ExternalHost) host).setSubData(client, channel);
Logger.get("SubData").info(client.getAddress().toString() + " has been defined as Host: " + host.getName() + ((channel > 0)?" [+"+channel+"]":""));
queue(host.getName(), () -> client.sendPacket(new PacketLinkExHost(0, null)));

View File

@ -66,15 +66,15 @@ public class PacketLinkProxy implements InitialPacket, PacketObjectIn<Integer>,
boolean isnew = false;
Proxy proxy;
if (name != null && proxies.keySet().contains(name.toLowerCase())) {
if (name != null && proxies.containsKey(name.toLowerCase())) {
proxy = proxies.get(name.toLowerCase());
} else {
proxy = new Proxy((name != null && !proxies.keySet().contains(name.toLowerCase()))?name:null);
proxy = new Proxy((name != null && !proxies.containsKey(name.toLowerCase()))?name:null);
isnew = true;
plugin.proxies.put(proxy.getName().toLowerCase(), proxy);
}
HashMap<Integer, SubDataClient> subdata = Try.all.get(() -> Util.reflect(Proxy.class.getDeclaredField("subdata"), proxy));
if (!subdata.keySet().contains(channel) || (channel == 0 && subdata.get(0) == null)) {
if (!subdata.containsKey(channel) || (channel == 0 && subdata.get(0) == null)) {
proxy.setSubData(client, channel);
if (isnew) plugin.getPluginManager().callEvent(new SubAddProxyEvent(proxy));
Logger.get("SubData").info(client.getAddress().toString() + " has been defined as Proxy: " + proxy.getName() + ((channel > 0)?" [+"+channel+"]":""));

View File

@ -90,7 +90,7 @@ public class PacketLinkServer implements InitialPacket, PacketObjectIn<Integer>,
Server server;
Map<String, Server> servers = plugin.api.getServers();
if (name != null && servers.keySet().contains(name.toLowerCase())) {
if (name != null && servers.containsKey(name.toLowerCase())) {
link(client, servers.get(name.toLowerCase()), channel);
} else if (address != null) {
if ((server = search(address)) != null || (server = create(name, address)) != null) {
@ -139,7 +139,7 @@ public class PacketLinkServer implements InitialPacket, PacketObjectIn<Integer>,
static long last = Calendar.getInstance().getTime().getTime();
private void link(SubDataClient client, Server server, int channel) throws Throwable {
HashMap<Integer, SubDataClient> subdata = Try.all.get(() -> Util.reflect(ServerImpl.class.getDeclaredField("subdata"), server));
if (!subdata.keySet().contains(channel) || (channel == 0 && subdata.get(0) == null)) {
if (!subdata.containsKey(channel) || (channel == 0 && subdata.get(0) == null)) {
server.setSubData(client, channel);
Logger.get("SubData").info(client.getAddress().toString() + " has been defined as " + ((server instanceof SubServer) ? "SubServer" : "Server") + ": " + server.getName() + ((channel > 0)?" [+"+channel+"]":""));
Runnable register = () -> {

View File

@ -59,7 +59,7 @@ public class PacketRemoveServer implements PacketObjectIn<Integer>, PacketObject
UUID player = (data.contains(0x0003)?data.getUUID(0x0003):null);
Map<String, Server> servers = plugin.api.getServers();
if (!servers.keySet().contains(name.toLowerCase())) {
if (!servers.containsKey(name.toLowerCase())) {
client.sendPacket(new PacketRemoveServer(3, tracker));
} else if (!(servers.get(name.toLowerCase()) instanceof SubServer)) {
if (force) {

View File

@ -58,7 +58,7 @@ public class PacketRestartServer implements PacketObjectIn<Integer>, PacketObjec
Runnable starter = () -> {
Map<String, Server> servers = plugin.api.getServers();
if (!servers.keySet().contains(name.toLowerCase())) {
if (!servers.containsKey(name.toLowerCase())) {
} else if (!(servers.get(name.toLowerCase()) instanceof SubServer)) {
} else if (!((SubServer) servers.get(name.toLowerCase())).getHost().isAvailable()) {
} else if (!((SubServer) servers.get(name.toLowerCase())).getHost().isEnabled()) {
@ -72,7 +72,7 @@ public class PacketRestartServer implements PacketObjectIn<Integer>, PacketObjec
};
Map<String, Server> servers = plugin.api.getServers();
if (!servers.keySet().contains(name.toLowerCase())) {
if (!servers.containsKey(name.toLowerCase())) {
client.sendPacket(new PacketRestartServer(3, tracker));
} else if (!(servers.get(name.toLowerCase()) instanceof SubServer)) {
client.sendPacket(new PacketRestartServer(4, tracker));

View File

@ -70,7 +70,7 @@ public class PacketStartServer implements PacketObjectIn<Integer>, PacketObjectO
UUID player = (data.contains(0x0002)?data.getUUID(0x0002):null);
Map<String, Server> servers = plugin.api.getServers();
if (!servers.keySet().contains(name.toLowerCase())) {
if (!servers.containsKey(name.toLowerCase())) {
client.sendPacket(new PacketStartServer(3, tracker));
} else if (!(servers.get(name.toLowerCase()) instanceof SubServer)) {
client.sendPacket(new PacketStartServer(4, tracker));

View File

@ -58,7 +58,7 @@ public class PacketStopServer implements PacketObjectIn<Integer>, PacketObjectOu
UUID player = (data.contains(0x0003)?data.getUUID(0x0003):null);
Map<String, Server> servers = plugin.api.getServers();
if (!name.equals("*") && !servers.keySet().contains(name.toLowerCase())) {
if (!name.equals("*") && !servers.containsKey(name.toLowerCase())) {
client.sendPacket(new PacketStopServer(3, tracker));
} else if (!name.equals("*") && !(servers.get(name.toLowerCase()) instanceof SubServer)) {
client.sendPacket(new PacketStopServer(4, tracker));

View File

@ -60,7 +60,7 @@ public class PacketUpdateServer implements PacketObjectIn<Integer>, PacketObject
boolean waitfor = (data.contains(0x0005)?data.getBoolean(0x0005):false);
Map<String, Server> servers = plugin.api.getServers();
if (!servers.keySet().contains(name.toLowerCase())) {
if (!servers.containsKey(name.toLowerCase())) {
client.sendPacket(new PacketUpdateServer(3, tracker));
} else if (!(servers.get(name.toLowerCase()) instanceof SubServer)) {
client.sendPacket(new PacketUpdateServer(4, tracker));

View File

@ -95,7 +95,7 @@ public final class SubAPI implements BungeeAPI {
*/
public void addHostDriver(Class<? extends Host> driver, String handle) {
Util.nullpo(driver, handle);
if (plugin.hostDrivers.keySet().contains(handle.toUpperCase().replace('-', '_').replace(' ', '_'))) throw new IllegalStateException("Driver already exists: " + handle);
if (plugin.hostDrivers.containsKey(handle.toUpperCase().replace('-', '_').replace(' ', '_'))) throw new IllegalStateException("Driver already exists: " + handle);
plugin.hostDrivers.put(handle.toUpperCase().replace('-', '_').replace(' ', '_'), driver);
}
@ -317,12 +317,12 @@ public final class SubAPI implements BungeeAPI {
for (Server server : getServers().values()) {
for (String name : server.getGroups()) {
String group = name;
if (conflitresolver.keySet().contains(name.toLowerCase())) {
if (conflitresolver.containsKey(name.toLowerCase())) {
group = conflitresolver.get(name.toLowerCase());
} else {
conflitresolver.put(name.toLowerCase(), name);
}
List<Server> list = (groups.keySet().contains(group))?groups.get(group):new LinkedList<Server>();
List<Server> list = (groups.containsKey(group))?groups.get(group):new LinkedList<Server>();
list.add(server);
groups.put(group, list);
}
@ -435,7 +435,7 @@ public final class SubAPI implements BungeeAPI {
* @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!");
if (getServers().containsKey(server.getName().toLowerCase())) throw new InvalidServerException("A Server already exists with this name!");
SubAddServerEvent event = new SubAddServerEvent(player, null, server);
plugin.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
@ -586,7 +586,7 @@ public final class SubAPI implements BungeeAPI {
players.put(id, plugin.rPlayers.get(id));
return players;
} else {
return new HashMap<>();
return Collections.emptyMap();
}
}

View File

@ -438,7 +438,7 @@ public final class SubCommand extends Command implements TabExecutor {
if (select.subservers.length > 0) {
Consumer<SubServer> starter = server -> {
Map<String, Server> servers = plugin.api.getServers();
if (!servers.keySet().contains(server.getName().toLowerCase()) || !(servers.get(server.getName().toLowerCase()) instanceof SubServer)) {
if (!servers.containsKey(server.getName().toLowerCase()) || !(servers.get(server.getName().toLowerCase()) instanceof SubServer)) {
sender.sendMessage("SubServers > Could not restart server: Subserver " + server.getName() + " has disappeared");
} else if (!(server = (SubServer) servers.get(server.getName().toLowerCase())).isRunning()) {
if (!server.getHost().isAvailable()) {
@ -565,7 +565,7 @@ public final class SubCommand extends Command implements TabExecutor {
if (plugin.canSudo) {
if (args.length > 1) {
Map<String, Server> servers = plugin.api.getServers();
if (!servers.keySet().contains(args[1].toLowerCase()) || !(servers.get(args[1].toLowerCase()) instanceof SubServer)) {
if (!servers.containsKey(args[1].toLowerCase()) || !(servers.get(args[1].toLowerCase()) instanceof SubServer)) {
sender.sendMessage("SubServers > There is no subserver with that name");
} else if (!((SubServer) servers.get(args[1].toLowerCase())).isRunning()) {
sender.sendMessage("SubServers > That subserver is not running");
@ -581,15 +581,15 @@ public final class SubCommand extends Command implements TabExecutor {
}
} else if (args[0].equalsIgnoreCase("create")) {
if (args.length > 3) {
if (plugin.api.getSubServers().keySet().contains(args[1].toLowerCase()) || SubCreator.isReserved(args[1])) {
if (plugin.api.getSubServers().containsKey(args[1].toLowerCase()) || SubCreator.isReserved(args[1])) {
sender.sendMessage("SubServers > There is already a subserver with that name");
} else if (!plugin.hosts.keySet().contains(args[2].toLowerCase())) {
} else if (!plugin.hosts.containsKey(args[2].toLowerCase())) {
sender.sendMessage("SubServers > There is no host with that name");
} else if (!plugin.hosts.get(args[2].toLowerCase()).isAvailable()) {
sender.sendMessage("SubServers > That host is not available");
} else if (!plugin.hosts.get(args[2].toLowerCase()).isEnabled()) {
sender.sendMessage("SubServers > That host is not enabled");
} else if (!plugin.hosts.get(args[2].toLowerCase()).getCreator().getTemplates().keySet().contains(args[3].toLowerCase())) {
} else if (!plugin.hosts.get(args[2].toLowerCase()).getCreator().getTemplates().containsKey(args[3].toLowerCase())) {
sender.sendMessage("SubServers > There is no template with that name");
} else if (!plugin.hosts.get(args[2].toLowerCase()).getCreator().getTemplate(args[3].toLowerCase()).isEnabled()) {
sender.sendMessage("SubServers > That template is not enabled");
@ -857,19 +857,19 @@ public final class SubCommand extends Command implements TabExecutor {
String Last = (args.length > 0)?args[args.length - 1]:"";
String last = Last.toLowerCase();
if (sender instanceof ProxiedPlayer && (!players.keySet().contains(((ProxiedPlayer) sender).getUniqueId()) || !players.get(((ProxiedPlayer) sender).getUniqueId()).keySet().contains(((ProxiedPlayer) sender).getServer().getInfo())
if (sender instanceof ProxiedPlayer && (!players.containsKey(((ProxiedPlayer) sender).getUniqueId()) || !players.get(((ProxiedPlayer) sender).getUniqueId()).containsKey(((ProxiedPlayer) sender).getServer().getInfo())
|| !players.get(((ProxiedPlayer) sender).getUniqueId()).get(((ProxiedPlayer) sender).getServer().getInfo()).value())) {
if (players.keySet().contains(((ProxiedPlayer) sender).getUniqueId()) && players.get(((ProxiedPlayer) sender).getUniqueId()).keySet().contains(((ProxiedPlayer) sender).getServer().getInfo())
if (players.containsKey(((ProxiedPlayer) sender).getUniqueId()) && players.get(((ProxiedPlayer) sender).getUniqueId()).containsKey(((ProxiedPlayer) sender).getServer().getInfo())
&& players.get(((ProxiedPlayer) sender).getUniqueId()).get(((ProxiedPlayer) sender).getServer().getInfo()).key() == null) {
// do nothing
} else if (!players.keySet().contains(((ProxiedPlayer) sender).getUniqueId()) || !players.get(((ProxiedPlayer) sender).getUniqueId()).keySet().contains(((ProxiedPlayer) sender).getServer().getInfo())
} else if (!players.containsKey(((ProxiedPlayer) sender).getUniqueId()) || !players.get(((ProxiedPlayer) sender).getUniqueId()).containsKey(((ProxiedPlayer) sender).getServer().getInfo())
|| Calendar.getInstance().getTime().getTime() - players.get(((ProxiedPlayer) sender).getUniqueId()).get(((ProxiedPlayer) sender).getServer().getInfo()).key() >= TimeUnit.MINUTES.toMillis(1)) {
if (!(((ProxiedPlayer) sender).getServer().getInfo() instanceof Server) || ((Server) ((ProxiedPlayer) sender).getServer().getInfo()).getSubData()[0] == null) {
HashMap<ServerInfo, Pair<Long, Boolean>> map = (players.keySet().contains(((ProxiedPlayer) sender).getUniqueId()))?players.get(((ProxiedPlayer) sender).getUniqueId()):new HashMap<ServerInfo, Pair<Long, Boolean>>();
HashMap<ServerInfo, Pair<Long, Boolean>> map = (players.containsKey(((ProxiedPlayer) sender).getUniqueId()))?players.get(((ProxiedPlayer) sender).getUniqueId()):new HashMap<ServerInfo, Pair<Long, Boolean>>();
map.put(((ProxiedPlayer) sender).getServer().getInfo(), new ContainedPair<>(Calendar.getInstance().getTime().getTime(), false));
players.put(((ProxiedPlayer) sender).getUniqueId(), map);
} else {
HashMap<ServerInfo, Pair<Long, Boolean>> map = (players.keySet().contains(((ProxiedPlayer) sender).getUniqueId()))?players.get(((ProxiedPlayer) sender).getUniqueId()):new HashMap<ServerInfo, Pair<Long, Boolean>>();
HashMap<ServerInfo, Pair<Long, Boolean>> map = (players.containsKey(((ProxiedPlayer) sender).getUniqueId()))?players.get(((ProxiedPlayer) sender).getUniqueId()):new HashMap<ServerInfo, Pair<Long, Boolean>>();
map.put(((ProxiedPlayer) sender).getServer().getInfo(), new ContainedPair<>(null, false));
players.put(((ProxiedPlayer) sender).getUniqueId(), map);
((SubDataClient) ((Server) ((ProxiedPlayer) sender).getServer().getInfo()).getSubData()[0]).sendPacket(new PacketCheckPermission(((ProxiedPlayer) sender).getUniqueId(), "subservers.command", result -> {
@ -1075,7 +1075,7 @@ public final class SubCommand extends Command implements TabExecutor {
} else if (args.length == 4) {
List<String> list = new ArrayList<String>();
Map<String, Host> hosts = plugin.api.getHosts();
if (!hosts.keySet().contains(args[2].toLowerCase())) {
if (!hosts.containsKey(args[2].toLowerCase())) {
list.add("<Template>");
} else {
for (SubCreator.ServerTemplate template : hosts.get(args[2].toLowerCase()).getCreator().getTemplates().values()) {
@ -1160,7 +1160,7 @@ public final class SubCommand extends Command implements TabExecutor {
if (sender instanceof ProxiedPlayer) {
if (args.length > 0) {
Map<String, Server> servers = plugin.api.getServers();
if (servers.keySet().contains(args[0].toLowerCase())) {
if (servers.containsKey(args[0].toLowerCase())) {
((ProxiedPlayer) sender).connect(servers.get(args[0].toLowerCase()));
} else {
sender.sendMessage(plugin.api.getLang("SubServers", "Bungee.Server.Invalid"));

View File

@ -455,8 +455,8 @@ public final class SubProxy extends BungeeCommon implements Listener {
autorun = new LinkedList<String>();
for (String name : this.servers.get().getMap("Servers").getKeys()) {
if (!ukeys.contains(name.toLowerCase())) try {
if (!this.hosts.keySet().contains(this.servers.get().getMap("Servers").getMap(name).getString("Host").toLowerCase())) throw new InvalidServerException("There is no host with this name: " + this.servers.get().getMap("Servers").getMap(name).getString("Host"));
if (exServers.keySet().contains(name.toLowerCase())) {
if (!this.hosts.containsKey(this.servers.get().getMap("Servers").getMap(name).getString("Host").toLowerCase())) throw new InvalidServerException("There is no host with this name: " + this.servers.get().getMap("Servers").getMap(name).getString("Host"));
if (exServers.containsKey(name.toLowerCase())) {
exServers.remove(name.toLowerCase());
servers--;
}
@ -1001,11 +1001,11 @@ public final class SubProxy extends BungeeCommon implements Listener {
public void validate(ServerConnectEvent e) {
if (e.getPlayer().isConnected()) {
Map<String, ServerInfo> servers = new TreeMap<String, ServerInfo>(api.getServers());
if (servers.keySet().contains(e.getTarget().getName().toLowerCase()) && e.getTarget() != servers.get(e.getTarget().getName().toLowerCase())) {
if (servers.containsKey(e.getTarget().getName().toLowerCase()) && e.getTarget() != servers.get(e.getTarget().getName().toLowerCase())) {
e.setTarget(servers.get(e.getTarget().getName().toLowerCase()));
} else {
servers = getServersCopy();
if (servers.keySet().contains(e.getTarget().getName()) && e.getTarget() != servers.get(e.getTarget().getName())) {
if (servers.containsKey(e.getTarget().getName()) && e.getTarget() != servers.get(e.getTarget().getName())) {
e.setTarget(servers.get(e.getTarget().getName()));
}
}

View File

@ -497,7 +497,7 @@ public class DefaultUIHandler implements UIHandler, Listener {
*/
@EventHandler
public void close(InventoryCloseEvent event) {
if (gui.keySet().contains(event.getPlayer().getUniqueId())) gui.get(event.getPlayer().getUniqueId()).open = false;
if (gui.containsKey(event.getPlayer().getUniqueId())) gui.get(event.getPlayer().getUniqueId()).open = false;
}
/**
@ -507,7 +507,7 @@ public class DefaultUIHandler implements UIHandler, Listener {
*/
@EventHandler
public void clean(PlayerQuitEvent event) {
if (gui.keySet().contains(event.getPlayer().getUniqueId())) {
if (gui.containsKey(event.getPlayer().getUniqueId())) {
gui.get(event.getPlayer().getUniqueId()).setDownloading(null);
gui.remove(event.getPlayer().getUniqueId());
input.remove(event.getPlayer().getUniqueId());

View File

@ -713,12 +713,12 @@ public class DefaultUIRenderer extends UIRenderer {
} else {
for (String name : sgl) {
String group = name;
if (conflitresolver.keySet().contains(name.toLowerCase())) {
if (conflitresolver.containsKey(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<Server> list = (groups.containsKey(group))? groups.get(group) : new ArrayList<Server>();
list.add(server);
groups.put(group, list);
}

View File

@ -3,6 +3,7 @@ package net.ME1312.SubServers.Client.Bukkit.Library;
import net.ME1312.Galaxi.Library.Access;
import net.ME1312.Galaxi.Library.AsyncConsolidator;
import net.ME1312.Galaxi.Library.Container.ContainedPair;
import net.ME1312.Galaxi.Library.Container.Container;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Try;
@ -16,6 +17,7 @@ import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.scheduler.BukkitTask;
@ -589,9 +591,9 @@ public final class Placeholders {
}
public final class Cache {
private HashMap<String, Proxy> proxies = new HashMap<String, Proxy>();
private HashMap<String, Host> hosts = new HashMap<String, Host>();
private HashMap<String, Server> servers = new HashMap<String, Server>();
private Map<String, Proxy> proxies = Collections.emptyMap();
private Map<String, Host> hosts = Collections.emptyMap();
private Map<String, Server> servers = Collections.emptyMap();
private Proxy master = null;
private Listener events = new Events();
@ -604,10 +606,29 @@ public final class Placeholders {
private void refresh(Runnable callback) {
if (SubAPI.getInstance().getSubDataNetwork()[0] != null) {
AsyncConsolidator async = new AsyncConsolidator(callback);
Container<Boolean> order = new Container<>(null);
AsyncConsolidator async = new AsyncConsolidator(() -> {
try {
Map<String, SubServer> servers;
for (Host host : hosts.values()) {
servers = Util.reflect(Host.class.getDeclaredField("servers"), host);
if (order.value) {
this.servers.putAll(servers);
} else {
servers.replaceAll((name, existing) -> {
Server server = this.servers.getOrDefault(name, null);
return (server instanceof SubServer)? (SubServer) server : existing;
});
}
}
} catch (Throwable e) {
e.printStackTrace();
}
callback.run();
});
async.reserve(4);
SubAPI.getInstance().getProxies(proxies -> {
this.proxies = new HashMap<>(proxies);
this.proxies = proxies;
async.release();
});
SubAPI.getInstance().getMasterProxy(master -> {
@ -615,11 +636,13 @@ public final class Placeholders {
async.release();
});
SubAPI.getInstance().getHosts(hosts -> {
this.hosts = new HashMap<>(hosts);
order.value = true;
this.hosts = hosts;
async.release();
});
SubAPI.getInstance().getServers(servers -> {
this.servers = new HashMap<>(servers);
order.value = false;
this.servers = servers;
async.release();
});
}
@ -628,66 +651,65 @@ public final class Placeholders {
private final class Events implements Listener {
private HashMap<String, BukkitTask> edits = new HashMap<String, BukkitTask>();
@EventHandler
@EventHandler(priority = EventPriority.LOWEST)
public void add(SubAddProxyEvent e) {
SubAPI.getInstance().getProxy(e.getProxy(), proxy -> {
if (proxy != null) proxies.put(proxy.getName().toLowerCase(), proxy);
});
}
@EventHandler
@EventHandler(priority = EventPriority.LOWEST)
public void add(SubAddHostEvent e) {
SubAPI.getInstance().getHost(e.getHost(), host -> {
if (host != null) hosts.put(host.getName().toLowerCase(), host);
});
}
@EventHandler
@EventHandler(priority = EventPriority.LOWEST)
public void add(SubAddServerEvent e) {
add(e.getServer());
}
public void add(String s) {
SubAPI.getInstance().getServer(s, server -> {
if (server != null) servers.put(server.getName().toLowerCase(), server);
});
}
@EventHandler
@EventHandler(priority = EventPriority.LOWEST)
public void edit(SubEditServerEvent e) {
String s = e.getServer().toLowerCase();
if (edits.keySet().contains(s)) edits.get(s).cancel();
edits.put(s, Bukkit.getScheduler().runTaskLater(plugin, () -> add(s), 120L));
if (edits.containsKey(s)) edits.get(s).cancel();
edits.put(s, Bukkit.getScheduler().runTaskLater(plugin, servers.containsKey(s)? servers.get(s)::refresh : () -> add(s), 120L));
}
@EventHandler
@EventHandler(priority = EventPriority.LOWEST)
public void start(SubStartEvent e) {
Server server = getServer(e.getServer());
if (server != null) {
Try.all.run(() -> Util.<ObjectMap<String>>reflect(Server.class.getDeclaredField("raw"), server).set("running", true));
add(e.getServer());
}
server.refresh();
} else add(e.getServer());
}
@EventHandler
@EventHandler(priority = EventPriority.LOWEST)
public void started(SubStartedEvent e) {
Server server = getServer(e.getServer());
if (server != null) {
Try.all.run(() -> Util.<ObjectMap<String>>reflect(Server.class.getDeclaredField("raw"), server).set("online", true));
add(e.getServer());
}
server.refresh();
} else add(e.getServer());
}
@EventHandler
@EventHandler(priority = EventPriority.LOWEST)
public void stopping(SubStopEvent e) {
Server server = getServer(e.getServer());
if (server != null) {
Try.all.run(() -> Util.<ObjectMap<String>>reflect(Server.class.getDeclaredField("raw"), server).set("stopping", true));
add(e.getServer());
}
server.refresh();
} else add(e.getServer());
}
@EventHandler
@EventHandler(priority = EventPriority.LOWEST)
public void stopped(SubStoppedEvent e) {
Server server = getServer(e.getServer());
if (server != null) Try.all.run(() -> {
@ -695,8 +717,8 @@ public final class Placeholders {
raw.set("online", false);
raw.set("running", false);
raw.set("stopping", false);
add(e.getServer());
});
server.refresh();
}); else add(e.getServer());
}
}
@ -715,13 +737,13 @@ public final class Placeholders {
return master;
}
private Map<String, Host> getHosts() {
public Map<String, Host> getHosts() {
return hosts;
}
private Host getHost(String name) {
public Host getHost(String name) {
Util.nullpo(name);
return getHosts().get(name.toLowerCase());
return getHosts().getOrDefault(name.toLowerCase(), null);
}
public Map<String, List<Server>> getGroups() {
@ -730,12 +752,12 @@ public final class Placeholders {
for (Server server : getServers().values()) {
for (String name : server.getGroups()) {
String group = name;
if (conflitresolver.keySet().contains(name.toLowerCase())) {
if (conflitresolver.containsKey(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<Server> list = (groups.containsKey(group))?groups.get(group):new ArrayList<Server>();
list.add(server);
groups.put(group, list);
}
@ -766,7 +788,7 @@ public final class Placeholders {
public Server getServer(String name) {
Util.nullpo(name);
return getServers().get(name.toLowerCase());
return getServers().getOrDefault(name.toLowerCase(), null);
}
public Map<String, SubServer> getSubServers() {
@ -779,7 +801,7 @@ public final class Placeholders {
public SubServer getSubServer(String name) {
Util.nullpo(name);
return getSubServers().get(name.toLowerCase());
return getSubServers().getOrDefault(name.toLowerCase(), null);
}
}
}

View File

@ -159,7 +159,7 @@ public class PacketInExRunEvent implements PacketObjectIn<Integer> {
@SuppressWarnings("unchecked")
@Override
public void receive(SubDataSender client, ObjectMap<Integer> data) {
if (callbacks.keySet().contains(data.getString(0x0000))) {
if (callbacks.containsKey(data.getString(0x0000))) {
for (Consumer<ObjectMap<String>> callback : PacketInExRunEvent.callbacks.remove(data.getString(0x0000))) {
callback.accept(new ObjectMap<>((Map<String, ?>) data.getObject(0x0001)));
}
@ -167,7 +167,7 @@ public class PacketInExRunEvent implements PacketObjectIn<Integer> {
}
public static void callback(String event, Consumer<ObjectMap<String>> callback) {
List<Consumer<ObjectMap<String>>> callbacks = (PacketInExRunEvent.callbacks.keySet().contains(event))? PacketInExRunEvent.callbacks.get(event):new ArrayList<Consumer<ObjectMap<String>>>();
List<Consumer<ObjectMap<String>>> callbacks = (PacketInExRunEvent.callbacks.containsKey(event))? PacketInExRunEvent.callbacks.get(event):new ArrayList<Consumer<ObjectMap<String>>>();
callbacks.add(callback);
PacketInExRunEvent.callbacks.put(event, callbacks);
}

View File

@ -155,7 +155,7 @@ public class SubProtocol extends SubDataProtocol {
HashMap<Integer, SubDataClient> map = Try.all.get(() -> Util.reflect(SubPlugin.class.getDeclaredField("subdata"), plugin));
int channel = 1;
while (map.keySet().contains(channel)) channel++;
while (map.containsKey(channel)) channel++;
final int fc = channel;
SubDataClient subdata = super.open(scheduler, getLogger(fc), address, port, login);

View File

@ -435,7 +435,7 @@ public final class SubCommand extends Command {
if (listening.size() > 0) {
PacketInExRunEvent.callback("SubStoppedEvent", this);
String name = json.getString("server").toLowerCase();
if (listening.keySet().contains(name)) {
if (listening.containsKey(name)) {
Bukkit.getScheduler().runTaskLater(plugin, () -> {
starter.accept(listening.get(name));
listening.remove(name);

View File

@ -1,11 +1,14 @@
package net.ME1312.SubServers.Client.Bukkit;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.SubData.Client.Library.EscapedOutputStream;
import net.ME1312.SubServers.Client.Bukkit.Event.SubStartEvent;
import net.ME1312.SubServers.Client.Bukkit.Event.SubStartedEvent;
import net.ME1312.SubServers.Client.Bukkit.Event.SubStopEvent;
import net.ME1312.SubServers.Client.Bukkit.Event.SubStoppedEvent;
import net.ME1312.SubServers.Client.Bukkit.Library.Compatibility.OfflineBlock;
import net.ME1312.SubServers.Client.Common.Network.API.Host;
import net.ME1312.SubServers.Client.Common.Network.API.Server;
import net.ME1312.SubServers.Client.Common.Network.API.SubServer;
import org.bukkit.Bukkit;
@ -26,10 +29,9 @@ import java.io.*;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.text.NumberFormat;
import java.util.*;
import java.util.Map.Entry;
import java.util.UUID;
/**
* SubServers Signs Class
@ -85,16 +87,16 @@ public class SubSigns implements Listener {
break;
case '\u0003': // [ETX] (End of String character)
magic.position(0);
String server = string.toString(StandardCharsets.UTF_8.name());
String object = string.toString(StandardCharsets.UTF_8.name());
OfflineBlock location = new OfflineBlock(new UUID(magic.getLong(), magic.getLong()), magic.getInt(), magic.getInt(), magic.getInt());
Location loaded = location.load();
if (loaded == null) {
data.put(location, server);
data.put(location, object);
} else if (loaded.getBlock().getState() instanceof Sign) {
data.put(location, server);
signs.put(loaded, server);
data.put(location, object);
signs.put(loaded, object);
} else {
Bukkit.getLogger().warning("SubServers > Removed invalid sign data: [\"" + loaded.getWorld().getName() + "\", " + location.x + ", " + location.y + ", " + location.z + "] -> \"" + server + '\"');
Bukkit.getLogger().warning("SubServers > Removed invalid sign data: [\"" + loaded.getWorld().getName() + "\", " + location.x + ", " + location.y + ", " + location.z + "] -> \"" + object + '\"');
}
magic.clear();
string.reset();
@ -143,24 +145,34 @@ public class SubSigns implements Listener {
public void create(SignChangeEvent e) {
if (!e.isCancelled() && plugin.lang != null && e.getLine(0).trim().equalsIgnoreCase("[SubServers]")) {
Player player = e.getPlayer();
String server = e.getLine(1).trim();
if (server.length() > 0 && player.hasPermission("subservers.signs")) {
String object = e.getLine(1).trim();
if (object.length() > 0 && player.hasPermission("subservers.signs")) {
Location pos = e.getBlock().getLocation();
if (pos.getBlock().getState() instanceof Sign) {
HashMap<Location, String> signs = new HashMap<Location, String>(SubSigns.signs);
signs.put(pos, server);
signs.put(pos, object);
SubSigns.signs = signs;
data.put(new OfflineBlock(pos), server);
data.put(new OfflineBlock(pos), object);
listen();
refresh(e.getBlock(), server, null);
Bukkit.getLogger().info("SubServers > Server sign created: [\"" + pos.getWorld().getName() + "\", " + pos.getBlockX() + ", " + pos.getBlockY() + ", " + pos.getBlockZ() + "] -> \"" + server + '\"');
refresh(e.getBlock(), object);
Bukkit.getLogger().info("SubServers > Server sign created: [\"" + pos.getWorld().getName() + "\", " + pos.getBlockX() + ", " + pos.getBlockY() + ", " + pos.getBlockZ() + "] -> \"" + object + '\"');
player.sendMessage(plugin.api.getLang("SubServers", "Signs.Create"));
}
}
}
}
private Object translate(String name) {
if (name.startsWith("::")) {
return plugin.phi.cache.getHost(name.substring(2));
} else if (name.startsWith(":")) {
return plugin.phi.cache.getGroup(name.substring(1));
} else {
return plugin.phi.cache.getServer(name);
}
}
private void listen() {
if (!active && !signs.isEmpty()) {
active = true;
@ -172,37 +184,113 @@ public class SubSigns implements Listener {
private void refresh() {
if (plugin.lang != null) {
for (Entry<Location, String> pos : signs.entrySet()) {
refresh(pos.getKey().getBlock(), pos.getValue(), null);
refresh(pos.getKey().getBlock(), pos.getValue());
}
}
}
private void refresh(String name, String lang) {
private void refresh(SubServer server) {
if (plugin.lang != null) {
String name;
for (Entry<Location, String> pos : signs.entrySet()) {
if (pos.getValue().equalsIgnoreCase(name)) refresh(pos.getKey().getBlock(), pos.getValue(), lang);
}
}
}
private void refresh(Block block, String name, String lang) {
if (block.getState() instanceof Sign) {
Sign sign = (Sign) block.getState();
SubServer server = plugin.phi.cache.getSubServer(name);
if (lang == null) {
if (server == null) {
lang = "Signs.Text.Error";
} else if (server.isStopping()) {
lang = "Signs.Text.Stopping";
} else if (server.isOnline()) {
lang = "Signs.Text.Online";
} else if (server.isRunning()) {
lang = "Signs.Text.Starting";
if ((name = pos.getValue()).equalsIgnoreCase(server.getName())) {
refresh(pos.getKey().getBlock(), server);
} else if (name.equalsIgnoreCase("::" + server.getHost())) {
refresh(pos.getKey().getBlock(), plugin.phi.cache.getHost(server.getHost()));
} else {
lang = "Signs.Text.Offline";
for (String group : server.getGroups()) {
if (name.equalsIgnoreCase(':' + group)) {
refresh(pos.getKey().getBlock(), plugin.phi.cache.getGroup(group));
break;
}
}
}
}
String[] text = plugin.phi.replace(null, plugin.api.getLang("SubServers", lang).replace("$str$", name)).split("\n", 4);
}
}
private enum Text {
UNKNOWN(0, "Signs.Text.Unknown"),
OFFLINE(1, "Signs.Text.Offline"),
STARTING(3, "Signs.Text.Starting"),
ONLINE(4, "Signs.Text.Online"),
STOPPING(2, "Signs.Text.Stopping"),
;
private final byte priority;
private final String text;
Text(int priority, String text) {
this.priority = (byte) priority;
this.text = text;
}
private static Text determine(SubServer server) {
if (!server.isRunning()) {
return Text.OFFLINE;
} else if (server.isStopping()) {
return Text.STOPPING;
} else if (server.isOnline()) {
return Text.ONLINE;
} else {
return Text.STARTING;
}
}
private static Text determine(Server server) {
if (server instanceof SubServer) {
return determine((SubServer) server);
} else if (server.getSubData()[0] == null) {
return Text.UNKNOWN;
} else {
return Text.ONLINE;
}
}
}
@SuppressWarnings("unchecked")
private void refresh(Block block, Object object) {
if (block.getState() instanceof Sign) {
Sign sign = (Sign) block.getState();
Text state = Text.UNKNOWN;
String name = "null";
int players = 0;
// re-define the object
if (object instanceof String) {
object = translate(name = (String) object);
}
// read the object
if (object instanceof Host) {
Host host = (Host) object;
name = host.getDisplayName();
Text incoming;
for (SubServer server : ((Host) object).getSubServers().values()) {
players += server.getRemotePlayers().size();
incoming = Text.determine(server);
if (incoming.priority > state.priority)
state = incoming;
}
} else if (object instanceof Pair) {
Pair<String, List<Server>> group = (Pair<String, List<Server>>) object;
name = group.key();
Text incoming;
for (Server server : group.value()) {
players += server.getRemotePlayers().size();
incoming = Text.determine(server);
if (incoming.priority > state.priority)
state = incoming;
}
} else if (object instanceof Server) {
Server server = (Server) object;
state = Text.determine(server);
name = server.getDisplayName();
players = server.getRemotePlayers().size();
}
// update the sign
String[] text = plugin.phi.replace(null, plugin.api.getLang("SubServers", state.text).replace("$str$", name).replace("$int$", NumberFormat.getInstance().format(players))).split("\n", 4);
for (int i = 0; i < 4; ++i) if (i < text.length) {
sign.setLine(i, text[i]);
} else {
@ -212,16 +300,48 @@ public class SubSigns implements Listener {
}
}
@SuppressWarnings("unchecked")
@EventHandler(priority = EventPriority.MONITOR)
public void interact(PlayerInteractEvent e) {
if (!e.isCancelled() && e.getClickedBlock() != null && plugin.lang != null && plugin.api.getSubDataNetwork()[0] != null && !plugin.api.getSubDataNetwork()[0].isClosed() && signs.containsKey(e.getClickedBlock().getLocation())) {
Player player = e.getPlayer();
if ((e.getAction() == Action.RIGHT_CLICK_BLOCK || !player.hasPermission("subservers.signs")) && player.hasPermission("subservers.teleport")) {
SubServer server = plugin.phi.cache.getSubServer(signs.get(e.getClickedBlock().getLocation()));
if (server != null) {
if (!server.isRunning()) {
if (server.isEnabled() && server.isAvailable() && server.getCurrentIncompatibilities().size() == 0) server.start();
} else if (!server.isStopping()) {
Object object = translate(signs.get(e.getClickedBlock().getLocation()));
Collection<? extends Server> servers;
if (object instanceof Host) {
servers = ((Host) object).getSubServers().values();
} else if (object instanceof Pair) {
servers = ((Pair<String, List<Server>>) object).value();
} else if (object instanceof Server) {
servers = Collections.singleton((Server) object);
} else {
return;
}
Text incoming, state = Text.UNKNOWN;
List<Server> selected = new ArrayList<>();
for (Server server : servers) {
incoming = Text.determine(server);
if (incoming.priority > state.priority) {
selected.clear();
state = incoming;
}
if (incoming == state) {
if (state == Text.OFFLINE) {
SubServer subserver = (SubServer) server;
if (!(subserver.isEnabled() && subserver.isAvailable() && subserver.getCurrentIncompatibilities().size() == 0)) continue;
}
selected.add(server);
}
}
if (selected.size() > 0) {
Server server = selected.get(new Random().nextInt(selected.size()));
if (state == Text.OFFLINE) {
((SubServer) server).start();
} else {
player.sendMessage(plugin.api.getLang("SubServers", "Command.Teleport").replace("$name$", player.getName()).replace("$str$", server.getDisplayName()));
plugin.pmc(player, "Connect", server.getName());
}
@ -249,23 +369,23 @@ public class SubSigns implements Listener {
}
}
@EventHandler
@EventHandler(priority = EventPriority.MONITOR)
public void start(SubStartEvent e) {
refresh(e.getServer(), "Signs.Text.Starting");
refresh(plugin.phi.cache.getSubServer(e.getServer()));
}
@EventHandler
@EventHandler(priority = EventPriority.MONITOR)
public void started(SubStartedEvent e) {
refresh(e.getServer(), "Signs.Text.Online");
refresh(plugin.phi.cache.getSubServer(e.getServer()));
}
@EventHandler
@EventHandler(priority = EventPriority.MONITOR)
public void stopping(SubStopEvent e) {
refresh(e.getServer(), "Signs.Text.Stopping");
refresh(plugin.phi.cache.getSubServer(e.getServer()));
}
@EventHandler
@EventHandler(priority = EventPriority.MONITOR)
public void stopped(SubStoppedEvent e) {
refresh(e.getServer(), "Signs.Text.Offline");
refresh(plugin.phi.cache.getSubServer(e.getServer()));
}
}

View File

@ -131,7 +131,7 @@ public class PacketInExRunEvent implements PacketObjectIn<Integer> {
@SuppressWarnings("unchecked")
@Override
public void receive(SubDataSender client, ObjectMap<Integer> data) {
if (callbacks.keySet().contains(data.getString(0x0000))) {
if (callbacks.containsKey(data.getString(0x0000))) {
for (Consumer<ObjectMap<String>> callback : PacketInExRunEvent.callbacks.remove(data.getString(0x0000))) {
callback.accept(new ObjectMap<>((Map<String, ?>) data.getObject(0x0001)));
}
@ -139,7 +139,7 @@ public class PacketInExRunEvent implements PacketObjectIn<Integer> {
}
public static void callback(String event, Consumer<ObjectMap<String>> callback) {
List<Consumer<ObjectMap<String>>> callbacks = (PacketInExRunEvent.callbacks.keySet().contains(event))? PacketInExRunEvent.callbacks.get(event):new ArrayList<Consumer<ObjectMap<String>>>();
List<Consumer<ObjectMap<String>>> callbacks = (PacketInExRunEvent.callbacks.containsKey(event))? PacketInExRunEvent.callbacks.get(event):new ArrayList<Consumer<ObjectMap<String>>>();
callbacks.add(callback);
PacketInExRunEvent.callbacks.put(event, callbacks);
}

View File

@ -162,7 +162,7 @@ public class SubProtocol extends SubDataProtocol {
HashMap<Integer, SubDataClient> map = Try.all.get(() -> Util.reflect(SubPlugin.class.getDeclaredField("subdata"), plugin));
int channel = 1;
while (map.keySet().contains(channel)) channel++;
while (map.containsKey(channel)) channel++;
final int fc = channel;
SubDataClient subdata = super.open(scheduler, getLogger(fc), address, port, login);

View File

@ -766,7 +766,7 @@ public final class SubCommand implements CommandExecutor {
if (listening.size() > 0) {
PacketInExRunEvent.callback("SubStoppedEvent", this);
String name = json.getString("server").toLowerCase();
if (listening.keySet().contains(name)) {
if (listening.containsKey(name)) {
plugin.game.getScheduler().createTaskBuilder().execute(() -> {
starter.accept(listening.get(name));
listening.remove(name);

View File

@ -40,7 +40,7 @@ public final class ConsoleCommand {
if (server != null) {
if (server.isRunning()) {
Logger.get("SubConsole").info("Opening console window...");
if (!plugin.sCurrent.keySet().contains(name.toLowerCase())) {
if (!plugin.sCurrent.containsKey(name.toLowerCase())) {
ConsoleWindow window = new ConsoleWindow(plugin, server.getLogger());
plugin.sCurrent.put(name.toLowerCase(), window);
window.open();
@ -67,7 +67,7 @@ public final class ConsoleCommand {
if (host.getCreator().getReservedNames().size() > 0) {
sender.sendMessage("SubConsole > Opening console window" + ((host.getCreator().getReservedNames().size() == 1)?"":"s") + "...");
for (String reserved : host.getCreator().getReservedNames()) {
if (!plugin.cCurrent.keySet().contains(reserved.toLowerCase())) {
if (!plugin.cCurrent.containsKey(reserved.toLowerCase())) {
ConsoleWindow window = new ConsoleWindow(plugin, host.getCreator().getLogger(reserved));
plugin.cCurrent.put(reserved.toLowerCase(), window);
window.open();

View File

@ -76,7 +76,7 @@ public final class ConsolePlugin extends Plugin implements Listener {
@EventHandler(priority = EventPriority.HIGHEST)
public void onServerCreate(SubCreateEvent event) {
if (!event.isCancelled()) {
if (!cCurrent.keySet().contains(event.getHost().getName().toLowerCase())) {
if (!cCurrent.containsKey(event.getHost().getName().toLowerCase())) {
cCurrent.put(event.getName().toLowerCase(), new ConsoleWindow(this, event.getHost().getCreator().getLogger(event.getName().toLowerCase())));
} else {
cCurrent.get(event.getName().toLowerCase()).clear();
@ -90,7 +90,7 @@ public final class ConsolePlugin extends Plugin implements Listener {
@EventHandler(priority = EventPriority.HIGHEST)
public void onServerStart(SubStartEvent event) {
if (!event.isCancelled()) {
if (!sCurrent.keySet().contains(event.getServer().getName().toLowerCase())) {
if (!sCurrent.containsKey(event.getServer().getName().toLowerCase())) {
sCurrent.put(event.getServer().getName().toLowerCase(), new ConsoleWindow(this, event.getServer().getLogger()));
} else {
sCurrent.get(event.getServer().getName().toLowerCase()).clear();
@ -103,7 +103,7 @@ public final class ConsolePlugin extends Plugin implements Listener {
@EventHandler(priority = EventPriority.HIGHEST)
public void onServerCommand(SubSendCommandEvent event) {
if (!event.isCancelled() && sCurrent.keySet().contains(event.getServer().getName().toLowerCase())) {
if (!event.isCancelled() && sCurrent.containsKey(event.getServer().getName().toLowerCase())) {
RemotePlayer player = (event.getPlayer() == null)? null : SubAPI.getInstance().getRemotePlayer(event.getPlayer());
sCurrent.get(event.getServer().getName().toLowerCase()).log(((player == null)? "CONSOLE" : player.getName()) + "> /" + event.getCommand());
}

View File

@ -505,7 +505,7 @@ public class SubCreatorImpl {
}
public void terminate(String name) {
if (this.thread.keySet().contains(name.toLowerCase())) {
if (this.thread.containsKey(name.toLowerCase())) {
if (this.thread.get(name.toLowerCase()).process != null && this.thread.get(name.toLowerCase()).process.isAlive()) {
Executable.terminate(this.thread.get(name.toLowerCase()).process);
} else if (this.thread.get(name.toLowerCase()).isAlive()) {
@ -524,7 +524,7 @@ public class SubCreatorImpl {
}
public void waitFor(String name) throws InterruptedException {
while (this.thread.keySet().contains(name.toLowerCase()) && this.thread.get(name.toLowerCase()).isAlive()) {
while (this.thread.containsKey(name.toLowerCase()) && this.thread.get(name.toLowerCase()).isAlive()) {
Thread.sleep(250);
}
}

View File

@ -15,7 +15,7 @@ public class ReplacementScanner extends FileScanner {
TreeMap<Integer, LinkedList<String>> order = new TreeMap<Integer, LinkedList<String>>(Comparator.reverseOrder());
for (String key : replacements.keySet()) {
int length = key.length();
if (!order.keySet().contains(length)) order.put(length, new LinkedList<>());
if (!order.containsKey(length)) order.put(length, new LinkedList<>());
order.get(length).add(key);
}

View File

@ -80,7 +80,7 @@ public class PacketExAddServer implements PacketObjectIn<Integer>, PacketObjectO
String stopcmd = data.getString(0x0007);
UUID running = data.contains(0x0008)?data.getUUID(0x0008):null;
if (host.servers.keySet().contains(name.toLowerCase())) {
if (host.servers.containsKey(name.toLowerCase())) {
SubServerImpl server = host.servers.get(name.toLowerCase());
if (server.getPort() == port && server.getExecutable().equals(exec) && server.getPath().equals(dir)) {
if (server.isEnabled() != enabled || server.getLogger().isLogging() != log || !server.getStopCommand().equals(stopcmd)) {

View File

@ -70,7 +70,7 @@ public class PacketExDeleteServer implements PacketObjectIn<Integer>, PacketObje
YAMLSection info = new YAMLSection((Map<String, ?>) data.getObject(0x0002));
boolean recycle = data.getBoolean(0x0003, false);
if (!host.servers.keySet().contains(name.toLowerCase())) {
if (!host.servers.containsKey(name.toLowerCase())) {
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketExDeleteServer(1, tracker));
} else if (host.servers.get(name.toLowerCase()).isRunning()) {
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketExDeleteServer(3, tracker));

View File

@ -60,7 +60,7 @@ public class PacketExRemoveServer implements PacketObjectIn<Integer>, PacketObje
UUID tracker = (data.contains(0x0000)?data.getUUID(0x0000):null);
try {
String name = data.getString(0x0001);
if (!host.servers.keySet().contains(name.toLowerCase())) {
if (!host.servers.containsKey(name.toLowerCase())) {
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketExRemoveServer(1, tracker));
} else if (host.servers.get(name.toLowerCase()).isRunning()) {
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketExRemoveServer(3, tracker));

View File

@ -128,7 +128,7 @@ public class PacketInExRunEvent implements PacketObjectIn<Integer> {
@SuppressWarnings("unchecked")
@Override
public void receive(SubDataSender client, ObjectMap<Integer> data) {
if (callbacks.keySet().contains(data.getString(0x0000))) {
if (callbacks.containsKey(data.getString(0x0000))) {
for (Consumer<ObjectMap<String>> callback : PacketInExRunEvent.callbacks.remove(data.getString(0x0000))) {
callback.accept(new ObjectMap<>((Map<String, ?>) data.getObject(0x0001)));
}
@ -136,7 +136,7 @@ public class PacketInExRunEvent implements PacketObjectIn<Integer> {
}
public static void callback(String event, Consumer<ObjectMap<String>> callback) {
List<Consumer<ObjectMap<String>>> callbacks = (PacketInExRunEvent.callbacks.keySet().contains(event))? PacketInExRunEvent.callbacks.get(event):new ArrayList<Consumer<ObjectMap<String>>>();
List<Consumer<ObjectMap<String>>> callbacks = (PacketInExRunEvent.callbacks.containsKey(event))? PacketInExRunEvent.callbacks.get(event):new ArrayList<Consumer<ObjectMap<String>>>();
callbacks.add(callback);
PacketInExRunEvent.callbacks.put(event, callbacks);
}

View File

@ -144,7 +144,7 @@ public class SubProtocol extends SubDataProtocol {
HashMap<Integer, SubDataClient> map = Try.all.get(() -> Util.reflect(ExHost.class.getDeclaredField("subdata"), host));
int channel = 1;
while (map.keySet().contains(channel)) channel++;
while (map.containsKey(channel)) channel++;
final int fc = channel;
SubDataClient subdata = super.open(scheduler, getLogger(fc), address, port, login);

View File

@ -30,10 +30,10 @@ import java.util.function.Supplier;
* Command Class
*/
public class SubCommand {
private static TreeMap<String, Proxy> proxyCache = new TreeMap<String, Proxy>();
private static TreeMap<String, Host> hostCache = new TreeMap<String, Host>();
private static TreeMap<String, List<Server>> groupCache = new TreeMap<String, List<Server>>();
private static TreeMap<String, Server> serverCache = new TreeMap<String, Server>();
private static Map<String, Proxy> proxyCache = Collections.emptyMap();
private static Map<String, Host> hostCache = Collections.emptyMap();
private static Map<String, List<Server>> groupCache = Collections.emptyMap();
private static Map<String, Server> serverCache = Collections.emptyMap();
private static Proxy proxyMasterCache = null;
private static long cacheDate = 0;
private final ExHost host;
@ -554,7 +554,7 @@ public class SubCommand {
if (listening.size() > 0) {
PacketInExRunEvent.callback("SubStoppedEvent", this);
String name = json.getString("server").toLowerCase();
if (listening.keySet().contains(name)) {
if (listening.containsKey(name)) {
Timer timer = new Timer("SubServers.Host::Server_Restart_Command_Handler(" + name + ")");
timer.schedule(new TimerTask() {
@Override
@ -817,7 +817,7 @@ public class SubCommand {
} else if (args.length == 3) {
List<String> list = new ArrayList<String>();
Map<String, Host> hosts = hostCache;
if (hosts.keySet().contains(args[1].toLowerCase())) {
if (hosts.containsKey(args[1].toLowerCase())) {
for (SubCreator.ServerTemplate template : hosts.get(args[1].toLowerCase()).getCreator().getTemplates().values()) {
if (template.getName().toLowerCase().startsWith(last)) list.add(Last + template.getName().substring(last.length()));
}
@ -1355,7 +1355,7 @@ public class SubCommand {
if (Calendar.getInstance().getTime().getTime() - cacheDate >= TimeUnit.MINUTES.toMillis(1)) {
cacheDate = Calendar.getInstance().getTime().getTime();
SubAPI.getInstance().getProxies(proxies -> {
proxyCache = new TreeMap<>(proxies);
proxyCache = proxies;
cacheDate = Calendar.getInstance().getTime().getTime();
});
SubAPI.getInstance().getMasterProxy(master -> {
@ -1363,15 +1363,15 @@ public class SubCommand {
cacheDate = Calendar.getInstance().getTime().getTime();
});
SubAPI.getInstance().getHosts(hosts -> {
hostCache = new TreeMap<>(hosts);
hostCache = hosts;
cacheDate = Calendar.getInstance().getTime().getTime();
});
SubAPI.getInstance().getGroups(groups -> {
groupCache = new TreeMap<>(groups);
groupCache = groups;
cacheDate = Calendar.getInstance().getTime().getTime();
});
SubAPI.getInstance().getServers(servers -> {
serverCache = new TreeMap<>(servers);
serverCache = servers;
cacheDate = Calendar.getInstance().getTime().getTime();
});
}

View File

@ -499,11 +499,11 @@ public final class ExProxy extends BungeeCommon implements Listener {
public void validate(ServerConnectEvent e) {
if (e.getPlayer().isConnected()) {
Map<String, ServerInfo> servers = new TreeMap<String, ServerInfo>(this.servers);
if (servers.keySet().contains(e.getTarget().getName().toLowerCase()) && e.getTarget() != servers.get(e.getTarget().getName().toLowerCase())) {
if (servers.containsKey(e.getTarget().getName().toLowerCase()) && e.getTarget() != servers.get(e.getTarget().getName().toLowerCase())) {
e.setTarget(servers.get(e.getTarget().getName().toLowerCase()));
} else {
servers = getServers();
if (servers.keySet().contains(e.getTarget().getName()) && e.getTarget() != servers.get(e.getTarget().getName())) {
if (servers.containsKey(e.getTarget().getName()) && e.getTarget() != servers.get(e.getTarget().getName())) {
e.setTarget(servers.get(e.getTarget().getName()));
}
}
@ -678,13 +678,13 @@ public final class ExProxy extends BungeeCommon implements Listener {
@EventHandler(priority = Byte.MIN_VALUE)
public void start(SubStartEvent e) {
if (servers.keySet().contains(e.getServer().toLowerCase()) && servers.get(e.getServer().toLowerCase()) instanceof SubServerImpl)
if (servers.containsKey(e.getServer().toLowerCase()) && servers.get(e.getServer().toLowerCase()) instanceof SubServerImpl)
((SubServerImpl) servers.get(e.getServer().toLowerCase())).setRunning(true);
}
@EventHandler(priority = Byte.MIN_VALUE)
public void stop(SubStoppedEvent e) {
if (servers.keySet().contains(e.getServer().toLowerCase()) && servers.get(e.getServer().toLowerCase()) instanceof SubServerImpl)
if (servers.containsKey(e.getServer().toLowerCase()) && servers.get(e.getServer().toLowerCase()) instanceof SubServerImpl)
((SubServerImpl) servers.get(e.getServer().toLowerCase())).setRunning(false);
}

View File

@ -130,7 +130,7 @@ public class PacketInExRunEvent implements PacketObjectIn<Integer> {
@SuppressWarnings("unchecked")
@Override
public void receive(SubDataSender client, ObjectMap<Integer> data) {
if (callbacks.keySet().contains(data.getString(0x0000))) {
if (callbacks.containsKey(data.getString(0x0000))) {
for (Consumer<ObjectMap<String>> callback : PacketInExRunEvent.callbacks.remove(data.getString(0x0000))) {
callback.accept(new ObjectMap<>((Map<String, ?>) data.getObject(0x0001)));
}
@ -138,7 +138,7 @@ public class PacketInExRunEvent implements PacketObjectIn<Integer> {
}
public static void callback(String event, Consumer<ObjectMap<String>> callback) {
List<Consumer<ObjectMap<String>>> callbacks = (PacketInExRunEvent.callbacks.keySet().contains(event))? PacketInExRunEvent.callbacks.get(event):new ArrayList<Consumer<ObjectMap<String>>>();
List<Consumer<ObjectMap<String>>> callbacks = (PacketInExRunEvent.callbacks.containsKey(event))? PacketInExRunEvent.callbacks.get(event):new ArrayList<Consumer<ObjectMap<String>>>();
callbacks.add(callback);
PacketInExRunEvent.callbacks.put(event, callbacks);
}

View File

@ -139,7 +139,7 @@ public class SubProtocol extends SubDataProtocol {
HashMap<Integer, SubDataClient> map = Try.all.get(() -> Util.reflect(ExProxy.class.getDeclaredField("subdata"), plugin));
int channel = 1;
while (map.keySet().contains(channel)) channel++;
while (map.containsKey(channel)) channel++;
final int fc = channel;
SubDataClient subdata = super.open(scheduler, getLogger(fc), address, port, login);

View File

@ -82,7 +82,7 @@ public class ServerImpl extends BungeeServerInfo {
public void setSubData(UUID client, int channel) {
if (channel < 0) throw new IllegalArgumentException("Subchannel ID cannot be less than zero");
if (client != null || channel == 0) {
if (!subdata.keySet().contains(channel) || (channel == 0 && (client == null || subdata.get(channel) == null))) {
if (!subdata.containsKey(channel) || (channel == 0 && (client == null || subdata.get(channel) == null))) {
subdata.put(channel, client);
}
} else {

View File

@ -82,7 +82,7 @@ public final class SubAPI extends ClientAPI implements BungeeAPI {
players.put(id, plugin.rPlayers.get(id));
return players;
} else {
return new HashMap<>();
return Collections.emptyMap();
}
}

View File

@ -46,9 +46,9 @@ import java.util.function.Supplier;
@SuppressWarnings("deprecation")
public final class SubCommand extends Command implements TabExecutor {
static HashMap<UUID, HashMap<ServerInfo, Pair<Long, Boolean>>> permitted = new HashMap<UUID, HashMap<ServerInfo, Pair<Long, Boolean>>>();
private TreeMap<String, Proxy> proxyCache = new TreeMap<String, Proxy>();
private TreeMap<String, Host> hostCache = new TreeMap<String, Host>();
private TreeMap<String, List<Server>> groupCache = new TreeMap<String, List<Server>>();
private Map<String, Proxy> proxyCache = Collections.emptyMap();
private Map<String, Host> hostCache = Collections.emptyMap();
private Map<String, List<Server>> groupCache = Collections.emptyMap();
private Proxy proxyMasterCache = null;
private long cacheDate = 0;
private ExProxy plugin;
@ -428,7 +428,7 @@ public final class SubCommand extends Command implements TabExecutor {
if (listening.size() > 0) {
PacketInExRunEvent.callback("SubStoppedEvent", this);
String name = json.getString("server").toLowerCase();
if (listening.keySet().contains(name)) {
if (listening.containsKey(name)) {
Timer timer = new Timer("SubServers.Sync::Server_Restart_Command_Handler(" + name + ")");
timer.schedule(new TimerTask() {
@Override
@ -948,19 +948,19 @@ public final class SubCommand extends Command implements TabExecutor {
if (sender instanceof ConsoleCommandSender)
new IllegalStateException("SubData is not connected").printStackTrace();
return Collections.emptyList();
} else if (sender instanceof ProxiedPlayer && (!permitted.keySet().contains(((ProxiedPlayer) sender).getUniqueId()) || !permitted.get(((ProxiedPlayer) sender).getUniqueId()).keySet().contains(((ProxiedPlayer) sender).getServer().getInfo())
} else if (sender instanceof ProxiedPlayer && (!permitted.containsKey(((ProxiedPlayer) sender).getUniqueId()) || !permitted.get(((ProxiedPlayer) sender).getUniqueId()).containsKey(((ProxiedPlayer) sender).getServer().getInfo())
|| !permitted.get(((ProxiedPlayer) sender).getUniqueId()).get(((ProxiedPlayer) sender).getServer().getInfo()).value())) {
if (permitted.keySet().contains(((ProxiedPlayer) sender).getUniqueId()) && permitted.get(((ProxiedPlayer) sender).getUniqueId()).keySet().contains(((ProxiedPlayer) sender).getServer().getInfo())
if (permitted.containsKey(((ProxiedPlayer) sender).getUniqueId()) && permitted.get(((ProxiedPlayer) sender).getUniqueId()).containsKey(((ProxiedPlayer) sender).getServer().getInfo())
&& permitted.get(((ProxiedPlayer) sender).getUniqueId()).get(((ProxiedPlayer) sender).getServer().getInfo()).key() == null) {
// do nothing
} else if (!permitted.keySet().contains(((ProxiedPlayer) sender).getUniqueId()) || !permitted.get(((ProxiedPlayer) sender).getUniqueId()).keySet().contains(((ProxiedPlayer) sender).getServer().getInfo())
} else if (!permitted.containsKey(((ProxiedPlayer) sender).getUniqueId()) || !permitted.get(((ProxiedPlayer) sender).getUniqueId()).containsKey(((ProxiedPlayer) sender).getServer().getInfo())
|| Calendar.getInstance().getTime().getTime() - permitted.get(((ProxiedPlayer) sender).getUniqueId()).get(((ProxiedPlayer) sender).getServer().getInfo()).key() >= TimeUnit.MINUTES.toMillis(1)) {
if (!(((ProxiedPlayer) sender).getServer().getInfo() instanceof ServerImpl) || ((ServerImpl) ((ProxiedPlayer) sender).getServer().getInfo()).getSubData()[0] == null) {
HashMap<ServerInfo, Pair<Long, Boolean>> map = (permitted.keySet().contains(((ProxiedPlayer) sender).getUniqueId()))? permitted.get(((ProxiedPlayer) sender).getUniqueId()):new HashMap<ServerInfo, Pair<Long, Boolean>>();
HashMap<ServerInfo, Pair<Long, Boolean>> map = (permitted.containsKey(((ProxiedPlayer) sender).getUniqueId()))? permitted.get(((ProxiedPlayer) sender).getUniqueId()):new HashMap<ServerInfo, Pair<Long, Boolean>>();
map.put(((ProxiedPlayer) sender).getServer().getInfo(), new ContainedPair<>(Calendar.getInstance().getTime().getTime(), false));
permitted.put(((ProxiedPlayer) sender).getUniqueId(), map);
} else {
HashMap<ServerInfo, Pair<Long, Boolean>> map = (permitted.keySet().contains(((ProxiedPlayer) sender).getUniqueId()))? permitted.get(((ProxiedPlayer) sender).getUniqueId()):new HashMap<ServerInfo, Pair<Long, Boolean>>();
HashMap<ServerInfo, Pair<Long, Boolean>> map = (permitted.containsKey(((ProxiedPlayer) sender).getUniqueId()))? permitted.get(((ProxiedPlayer) sender).getUniqueId()):new HashMap<ServerInfo, Pair<Long, Boolean>>();
map.put(((ProxiedPlayer) sender).getServer().getInfo(), new ContainedPair<>(null, false));
permitted.put(((ProxiedPlayer) sender).getUniqueId(), map);
((SubDataSender) ((ServerImpl) ((ProxiedPlayer) sender).getServer().getInfo()).getSubData()[0]).sendPacket(new PacketCheckPermission(((ProxiedPlayer) sender).getUniqueId(), "subservers.command", result -> {
@ -1150,7 +1150,7 @@ public final class SubCommand extends Command implements TabExecutor {
} else if (args.length == 4) {
List<String> list = new ArrayList<String>();
Map<String, Host> hosts = hostCache;
if (!hosts.keySet().contains(args[2].toLowerCase())) {
if (!hosts.containsKey(args[2].toLowerCase())) {
list.add("<Template>");
} else {
for (SubCreator.ServerTemplate template : hosts.get(args[2].toLowerCase()).getCreator().getTemplates().values()) {
@ -1376,7 +1376,7 @@ public final class SubCommand extends Command implements TabExecutor {
if (Calendar.getInstance().getTime().getTime() - cacheDate >= TimeUnit.MINUTES.toMillis(1)) {
cacheDate = Calendar.getInstance().getTime().getTime();
plugin.api.getProxies(proxies -> {
proxyCache = new TreeMap<>(proxies);
proxyCache = proxies;
cacheDate = Calendar.getInstance().getTime().getTime();
});
plugin.api.getMasterProxy(master -> {
@ -1384,11 +1384,11 @@ public final class SubCommand extends Command implements TabExecutor {
cacheDate = Calendar.getInstance().getTime().getTime();
});
plugin.api.getHosts(hosts -> {
hostCache = new TreeMap<>(hosts);
hostCache = hosts;
cacheDate = Calendar.getInstance().getTime().getTime();
});
plugin.api.getGroups(groups -> {
groupCache = new TreeMap<>(groups);
groupCache = groups;
cacheDate = Calendar.getInstance().getTime().getTime();
});
}
@ -1420,7 +1420,7 @@ public final class SubCommand extends Command implements TabExecutor {
if (sender instanceof ProxiedPlayer) {
if (args.length > 0) {
Map<String, ServerImpl> servers = plugin.servers;
if (servers.keySet().contains(args[0].toLowerCase())) {
if (servers.containsKey(args[0].toLowerCase())) {
((ProxiedPlayer) sender).connect(servers.get(args[0].toLowerCase()));
} else {
sender.sendMessage(plugin.api.getLang("SubServers", "Bungee.Server.Invalid"));

View File

@ -19,7 +19,7 @@ public class Logger {
* @return Logger
*/
public static java.util.logging.Logger get(String prefix) {
if (!existing.keySet().contains(prefix)) {
if (!existing.containsKey(prefix)) {
java.util.logging.Logger log = java.util.logging.Logger.getAnonymousLogger();
log.setUseParentHandlers(false);
log.addHandler(new Handler() {

View File

@ -143,7 +143,7 @@ public class SmartFallback {
}
if (valid) {
List<RegisteredServer> servers = (score.keySet().contains(confidence))?score.get(confidence):new LinkedList<RegisteredServer>();
List<RegisteredServer> servers = (score.containsKey(confidence))?score.get(confidence):new LinkedList<RegisteredServer>();
servers.add(server);
score.put(confidence, servers);
}

View File

@ -128,7 +128,7 @@ public class PacketInExRunEvent implements PacketObjectIn<Integer> {
@SuppressWarnings("unchecked")
@Override
public void receive(SubDataSender client, ObjectMap<Integer> data) {
if (callbacks.keySet().contains(data.getString(0x0000))) {
if (callbacks.containsKey(data.getString(0x0000))) {
for (Consumer<ObjectMap<String>> callback : PacketInExRunEvent.callbacks.remove(data.getString(0x0000))) {
callback.accept(new ObjectMap<>((Map<String, ?>) data.getObject(0x0001)));
}
@ -136,7 +136,7 @@ public class PacketInExRunEvent implements PacketObjectIn<Integer> {
}
public static void callback(String event, Consumer<ObjectMap<String>> callback) {
List<Consumer<ObjectMap<String>>> callbacks = (PacketInExRunEvent.callbacks.keySet().contains(event))? PacketInExRunEvent.callbacks.get(event):new ArrayList<Consumer<ObjectMap<String>>>();
List<Consumer<ObjectMap<String>>> callbacks = (PacketInExRunEvent.callbacks.containsKey(event))? PacketInExRunEvent.callbacks.get(event):new ArrayList<Consumer<ObjectMap<String>>>();
callbacks.add(callback);
PacketInExRunEvent.callbacks.put(event, callbacks);
}

View File

@ -136,7 +136,7 @@ public class SubProtocol extends SubDataProtocol {
HashMap<Integer, SubDataClient> map = Try.all.get(() -> Util.reflect(ExProxy.class.getDeclaredField("subdata"), plugin), null);
int channel = 1;
while (map.keySet().contains(channel)) channel++;
while (map.containsKey(channel)) channel++;
final int fc = channel;
SubDataClient subdata = super.open(scheduler, getLogger(fc), address, port, login);

View File

@ -61,7 +61,7 @@ public class ServerData {
public void setSubData(UUID client, int channel) {
if (channel < 0) throw new IllegalArgumentException("Subchannel ID cannot be less than zero");
if (client != null || channel == 0) {
if (!subdata.keySet().contains(channel) || (channel == 0 && (client == null || subdata.get(channel) == null))) {
if (!subdata.containsKey(channel) || (channel == 0 && (client == null || subdata.get(channel) == null))) {
subdata.put(channel, client);
}
} else {

View File

@ -83,7 +83,7 @@ public final class SubAPI extends ClientAPI {
players.put(id, plugin.rPlayers.get(id));
return players;
} else {
return new HashMap<>();
return Collections.emptyMap();
}
}

View File

@ -50,9 +50,9 @@ import java.util.function.Supplier;
@SuppressWarnings("deprecation")
public final class SubCommand implements SimpleCommand {
static HashMap<UUID, HashMap<ServerInfo, Pair<Long, Boolean>>> permitted = new HashMap<UUID, HashMap<ServerInfo, Pair<Long, Boolean>>>();
private TreeMap<String, Proxy> proxyCache = new TreeMap<String, Proxy>();
private TreeMap<String, Host> hostCache = new TreeMap<String, Host>();
private TreeMap<String, List<Server>> groupCache = new TreeMap<String, List<Server>>();
private Map<String, Proxy> proxyCache = Collections.emptyMap();
private Map<String, Host> hostCache = Collections.emptyMap();
private Map<String, List<Server>> groupCache = Collections.emptyMap();
private Proxy proxyMasterCache = null;
private long cacheDate = 0;
private ExProxy plugin;
@ -433,7 +433,7 @@ public final class SubCommand implements SimpleCommand {
if (listening.size() > 0) {
PacketInExRunEvent.callback("SubStoppedEvent", this);
String name = json.getString("server").toLowerCase();
if (listening.keySet().contains(name)) {
if (listening.containsKey(name)) {
Timer timer = new Timer("SubServers.Sync::Server_Restart_Command_Handler(" + name + ")");
timer.schedule(new TimerTask() {
@Override
@ -1159,7 +1159,7 @@ public final class SubCommand implements SimpleCommand {
} else if (args.length == 4) {
List<String> list = new ArrayList<String>();
Map<String, Host> hosts = hostCache;
if (!hosts.keySet().contains(args[2].toLowerCase())) {
if (!hosts.containsKey(args[2].toLowerCase())) {
list.add("<Template>");
} else {
for (SubCreator.ServerTemplate template : hosts.get(args[2].toLowerCase()).getCreator().getTemplates().values()) {
@ -1382,7 +1382,7 @@ public final class SubCommand implements SimpleCommand {
if (Calendar.getInstance().getTime().getTime() - cacheDate >= TimeUnit.MINUTES.toMillis(1)) {
cacheDate = Calendar.getInstance().getTime().getTime();
plugin.api.getProxies(proxies -> {
proxyCache = new TreeMap<>(proxies);
proxyCache = proxies;
cacheDate = Calendar.getInstance().getTime().getTime();
});
plugin.api.getMasterProxy(master -> {
@ -1390,11 +1390,11 @@ public final class SubCommand implements SimpleCommand {
cacheDate = Calendar.getInstance().getTime().getTime();
});
plugin.api.getHosts(hosts -> {
hostCache = new TreeMap<>(hosts);
hostCache = hosts;
cacheDate = Calendar.getInstance().getTime().getTime();
});
plugin.api.getGroups(groups -> {
groupCache = new TreeMap<>(groups);
groupCache = groups;
cacheDate = Calendar.getInstance().getTime().getTime();
});
}