mirror of
https://github.com/ME1312/SubServers-2.git
synced 2024-11-22 10:15:52 +01:00
Better legacy API emulation
This commit is contained in:
parent
620db38e9b
commit
a992ec7c52
@ -3,29 +3,23 @@ package net.ME1312.SubServers.Bungee.Library.Compatibility;
|
|||||||
import net.ME1312.SubServers.Bungee.SubAPI;
|
import net.ME1312.SubServers.Bungee.SubAPI;
|
||||||
|
|
||||||
import net.md_5.bungee.api.config.ServerInfo;
|
import net.md_5.bungee.api.config.ServerInfo;
|
||||||
|
import net.md_5.bungee.util.CaseInsensitiveMap;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Legacy Server Map Translation Class
|
* Legacy Server Map Translation Class
|
||||||
*/
|
*/
|
||||||
public class LegacyServerMap implements Map<String, ServerInfo> {
|
public class LegacyServerMap extends CaseInsensitiveMap<ServerInfo> {
|
||||||
private final Map<String, ServerInfo> m;
|
public LegacyServerMap() {
|
||||||
|
|
||||||
/**
|
|
||||||
* Translate Legacy Server Map Modifications
|
|
||||||
*
|
|
||||||
* @param map Legacy Server Map
|
|
||||||
*/
|
|
||||||
public LegacyServerMap(Map<String, ServerInfo> map) {
|
|
||||||
this.m = map;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public LegacyServerMap(Map<String, ServerInfo> map) {
|
||||||
public ServerInfo get(Object key) {
|
for (Entry<String, ServerInfo> e : map.entrySet()) super.put(e.getKey(), e.getValue());
|
||||||
return m.get(key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@ -36,7 +30,7 @@ public class LegacyServerMap implements Map<String, ServerInfo> {
|
|||||||
s = getOrDefault(key, null);
|
s = getOrDefault(key, null);
|
||||||
|
|
||||||
if (n != null)
|
if (n != null)
|
||||||
m.put(n.getName(), n);
|
super.put(n.getName(), n);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,60 +40,14 @@ public class LegacyServerMap implements Map<String, ServerInfo> {
|
|||||||
ServerInfo s = getOrDefault(key, null);
|
ServerInfo s = getOrDefault(key, null);
|
||||||
if (s != null) {
|
if (s != null) {
|
||||||
if (SubAPI.getInstance().removeServer((String) key))
|
if (SubAPI.getInstance().removeServer((String) key))
|
||||||
m.remove(key);
|
super.remove(key);
|
||||||
return s;
|
return s;
|
||||||
} else return null;
|
} else return null;
|
||||||
} 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
|
@Override
|
||||||
public void clear() {
|
public void clear() {
|
||||||
// Disallow removing all servers
|
// 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();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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.api.plugin.PluginManager;
|
||||||
import net.md_5.bungee.connection.InitialHandler;
|
import net.md_5.bungee.connection.InitialHandler;
|
||||||
import net.md_5.bungee.event.EventHandler;
|
import net.md_5.bungee.event.EventHandler;
|
||||||
|
import net.md_5.bungee.util.CaseInsensitiveMap;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
@ -876,7 +877,7 @@ public final class SubProxy extends BungeeCommon implements Listener {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Map<String, ServerInfo> getServersCopy() {
|
public Map<String, ServerInfo> getServersCopy() {
|
||||||
HashMap<String, ServerInfo> servers = new HashMap<String, ServerInfo>();
|
Map<String, ServerInfo> servers = new CaseInsensitiveMap<ServerInfo>();
|
||||||
if (!running) {
|
if (!running) {
|
||||||
servers.putAll(super.getServers());
|
servers.putAll(super.getServers());
|
||||||
servers.putAll(legServers);
|
servers.putAll(legServers);
|
||||||
|
@ -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.api.plugin.PluginDescription;
|
||||||
import net.md_5.bungee.connection.InitialHandler;
|
import net.md_5.bungee.connection.InitialHandler;
|
||||||
import net.md_5.bungee.event.EventHandler;
|
import net.md_5.bungee.event.EventHandler;
|
||||||
|
import net.md_5.bungee.util.CaseInsensitiveMap;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
@ -364,7 +365,7 @@ public final class ExProxy extends BungeeCommon implements Listener {
|
|||||||
@Override
|
@Override
|
||||||
public Map<String, ServerInfo> getServers() {
|
public Map<String, ServerInfo> getServers() {
|
||||||
if (servers.size() > 0) {
|
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);
|
for (ServerInfo server : this.servers.values()) servers.put(server.getName(), server);
|
||||||
return servers;
|
return servers;
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user