|
1 | 1 | package com.kamesuta.bungeeviaproxy; |
2 | 2 |
|
| 3 | +import net.md_5.bungee.BungeeServerInfo; |
3 | 4 | import net.md_5.bungee.api.ProxyServer; |
4 | 5 | import net.md_5.bungee.api.config.ServerInfo; |
5 | 6 | import net.md_5.bungee.api.connection.PendingConnection; |
@@ -28,19 +29,18 @@ public void onEnable() { |
28 | 29 | // In Bungeecord, even if the hostnames are different, the equals method returns true if the resolved IP addresses are the same. |
29 | 30 | // This results in the error "You are already connected to this server!". |
30 | 31 | // To avoid this, we use unresolved InetSocketAddress objects so that different hostnames are treated as distinct servers. |
31 | | - ProxyServer.getInstance().getServers().values().forEach(serverInfo -> { |
32 | | - // Convert address to unresolved address |
33 | | - SocketAddress socketAddress = serverInfo.getSocketAddress(); |
34 | | - if (socketAddress instanceof InetSocketAddress) { |
35 | | - InetSocketAddress inetSocketAddress = (InetSocketAddress) socketAddress; |
36 | | - // Only convert if the address is a ViaProxy address |
37 | | - if (inetSocketAddress.getHostString().contains(IDENTIFIER) && ReflectionUtil.isBungeeSeverInfo(serverInfo)) { |
38 | | - ReflectionUtil.setBungeeServerInfoSocketAddress( |
39 | | - serverInfo, |
40 | | - InetSocketAddress.createUnresolved(inetSocketAddress.getHostString(), inetSocketAddress.getPort()) |
41 | | - ); |
42 | | - } |
43 | | - } |
| 32 | + ProxyServer.getInstance().getServers().replaceAll((name, serverInfo) -> { |
| 33 | + // if the serverInfo is already a HostnameBungeeServerInfo, return it as is |
| 34 | + if (serverInfo instanceof HostnameBungeeServerInfo) return serverInfo; |
| 35 | + // if the serverInfo is not a BungeeServerInfo, return it as is |
| 36 | + if (!(serverInfo instanceof BungeeServerInfo)) return serverInfo; |
| 37 | + // wrap the BungeeServerInfo to HostnameBungeeServerInfo |
| 38 | + return new HostnameBungeeServerInfo( |
| 39 | + serverInfo.getName(), |
| 40 | + serverInfo.getSocketAddress(), |
| 41 | + serverInfo.getMotd(), |
| 42 | + serverInfo.isRestricted() |
| 43 | + ); |
44 | 44 | }); |
45 | 45 | } |
46 | 46 |
|
|
0 commit comments