Better legacy API emulation

This commit is contained in:
ME1312 2021-03-13 11:51:32 -05:00
parent 620db38e9b
commit a992ec7c52
No known key found for this signature in database
GPG Key ID: FEFFE2F698E88FA8
3 changed files with 12 additions and 62 deletions

View File

@ -3,29 +3,23 @@ package net.ME1312.SubServers.Bungee.Library.Compatibility;
import net.ME1312.SubServers.Bungee.SubAPI;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.util.CaseInsensitiveMap;
import java.util.Collection;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
/**
* Legacy Server Map Translation Class
*/
public class LegacyServerMap implements Map<String, ServerInfo> {
private final Map<String, ServerInfo> m;
public class LegacyServerMap extends CaseInsensitiveMap<ServerInfo> {
public LegacyServerMap() {
/**
* Translate Legacy Server Map Modifications
*
* @param map Legacy Server Map
*/
public LegacyServerMap(Map<String, ServerInfo> map) {
this.m = map;
}
@Override
public ServerInfo get(Object key) {
return m.get(key);
public LegacyServerMap(Map<String, ServerInfo> map) {
for (Entry<String, ServerInfo> e : map.entrySet()) super.put(e.getKey(), e.getValue());
}
@SuppressWarnings("deprecation")
@ -36,7 +30,7 @@ public class LegacyServerMap implements Map<String, ServerInfo> {
s = getOrDefault(key, null);
if (n != null)
m.put(n.getName(), n);
super.put(n.getName(), n);
return s;
}
@ -46,60 +40,14 @@ public class LegacyServerMap implements Map<String, ServerInfo> {
ServerInfo s = getOrDefault(key, null);
if (s != null) {
if (SubAPI.getInstance().removeServer((String) key))
m.remove(key);
super.remove(key);
return s;
} else return null;
} else return null;
}
@Override
public void putAll(Map<? extends String, ? extends ServerInfo> m) {
if (m.size() > 0) {
for (Map.Entry<? extends String, ? extends ServerInfo> e : m.entrySet()) {
put(e.getKey(), e.getValue());
}
}
}
@Override
public void clear() {
// Disallow removing all servers
}
@Override
public int size() {
return m.size();
}
@Override
public boolean isEmpty() {
return m.isEmpty();
}
@Override
public boolean containsKey(Object key) {
return m.containsKey(key);
}
@Override
public boolean containsValue(Object value) {
return m.containsValue(value);
}
@Override
public Set<String> keySet() {
return m.keySet();
}
@Override
public Collection<ServerInfo> values() {
return m.values();
}
@Override
public Set<Entry<String, ServerInfo>> entrySet() {
return m.entrySet();
}
}

View File

@ -51,6 +51,7 @@ import net.md_5.bungee.api.plugin.PluginDescription;
import net.md_5.bungee.api.plugin.PluginManager;
import net.md_5.bungee.connection.InitialHandler;
import net.md_5.bungee.event.EventHandler;
import net.md_5.bungee.util.CaseInsensitiveMap;
import java.io.*;
import java.lang.reflect.InvocationTargetException;
@ -876,7 +877,7 @@ public final class SubProxy extends BungeeCommon implements Listener {
*/
@Override
public Map<String, ServerInfo> getServersCopy() {
HashMap<String, ServerInfo> servers = new HashMap<String, ServerInfo>();
Map<String, ServerInfo> servers = new CaseInsensitiveMap<ServerInfo>();
if (!running) {
servers.putAll(super.getServers());
servers.putAll(legServers);

View File

@ -46,6 +46,7 @@ import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.api.plugin.PluginDescription;
import net.md_5.bungee.connection.InitialHandler;
import net.md_5.bungee.event.EventHandler;
import net.md_5.bungee.util.CaseInsensitiveMap;
import java.io.*;
import java.net.InetAddress;
@ -364,7 +365,7 @@ public final class ExProxy extends BungeeCommon implements Listener {
@Override
public Map<String, ServerInfo> getServers() {
if (servers.size() > 0) {
HashMap<String, ServerInfo> servers = new HashMap<String, ServerInfo>();
Map<String, ServerInfo> servers = new CaseInsensitiveMap<ServerInfo>();
for (ServerInfo server : this.servers.values()) servers.put(server.getName(), server);
return servers;
} else {