From a992ec7c52189a63b5e4250c4007c19816e77792 Mon Sep 17 00:00:00 2001 From: ME1312 Date: Sat, 13 Mar 2021 11:51:32 -0500 Subject: [PATCH] Better legacy API emulation --- .../Compatibility/LegacyServerMap.java | 68 +++---------------- .../ME1312/SubServers/Bungee/SubProxy.java | 3 +- .../net/ME1312/SubServers/Sync/ExProxy.java | 3 +- 3 files changed, 12 insertions(+), 62 deletions(-) diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Library/Compatibility/LegacyServerMap.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Library/Compatibility/LegacyServerMap.java index 9e8be9d2..446941d9 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Library/Compatibility/LegacyServerMap.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Library/Compatibility/LegacyServerMap.java @@ -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 { - private final Map m; +public class LegacyServerMap extends CaseInsensitiveMap { + public LegacyServerMap() { - /** - * Translate Legacy Server Map Modifications - * - * @param map Legacy Server Map - */ - public LegacyServerMap(Map map) { - this.m = map; } - @Override - public ServerInfo get(Object key) { - return m.get(key); + public LegacyServerMap(Map map) { + for (Entry e : map.entrySet()) super.put(e.getKey(), e.getValue()); } @SuppressWarnings("deprecation") @@ -36,7 +30,7 @@ public class LegacyServerMap implements Map { 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 { 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 m) { - if (m.size() > 0) { - for (Map.Entry 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 keySet() { - return m.keySet(); - } - - @Override - public Collection values() { - return m.values(); - } - - @Override - public Set> entrySet() { - return m.entrySet(); - } - - } diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubProxy.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubProxy.java index b3e96647..c7ee8a12 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubProxy.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubProxy.java @@ -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 getServersCopy() { - HashMap servers = new HashMap(); + Map servers = new CaseInsensitiveMap(); if (!running) { servers.putAll(super.getServers()); servers.putAll(legServers); diff --git a/SubServers.Sync/src/net/ME1312/SubServers/Sync/ExProxy.java b/SubServers.Sync/src/net/ME1312/SubServers/Sync/ExProxy.java index d5e94ca5..0add2e57 100644 --- a/SubServers.Sync/src/net/ME1312/SubServers/Sync/ExProxy.java +++ b/SubServers.Sync/src/net/ME1312/SubServers/Sync/ExProxy.java @@ -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 getServers() { if (servers.size() > 0) { - HashMap servers = new HashMap(); + Map servers = new CaseInsensitiveMap(); for (ServerInfo server : this.servers.values()) servers.put(server.getName(), server); return servers; } else {