|
1 | 1 | package com.kamesuta.bungeeviaproxy; |
2 | 2 |
|
3 | | -import net.md_5.bungee.BungeeServerInfo; |
4 | 3 | import net.md_5.bungee.api.ProxyServer; |
5 | 4 | import net.md_5.bungee.api.config.ServerInfo; |
6 | 5 | import net.md_5.bungee.api.connection.PendingConnection; |
@@ -30,20 +29,22 @@ public void onEnable() { |
30 | 29 | // This results in the error "You are already connected to this server!". |
31 | 30 | // To avoid this, we use unresolved InetSocketAddress objects so that different hostnames are treated as distinct servers. |
32 | 31 | 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; |
| 32 | + // only address containing ".viaproxy." |
| 33 | + if (!serverInfo.getSocketAddress().toString().contains(IDENTIFIER)) return serverInfo; |
37 | 34 | // wrap the BungeeServerInfo to HostnameBungeeServerInfo |
38 | | - return new HostnameBungeeServerInfo( |
39 | | - serverInfo.getName(), |
40 | | - serverInfo.getSocketAddress(), |
41 | | - serverInfo.getMotd(), |
42 | | - serverInfo.isRestricted() |
43 | | - ); |
| 35 | + return HostnameBungeeServerInfo.wrap(serverInfo); |
44 | 36 | }); |
45 | 37 | } |
46 | 38 |
|
| 39 | + @Override |
| 40 | + public void onDisable() { |
| 41 | + // Plugin shutdown logic |
| 42 | + ProxyServer.getInstance().getPluginManager().unregisterListener(this); |
| 43 | + |
| 44 | + // Restore the original BungeeServerInfo |
| 45 | + ProxyServer.getInstance().getServers().replaceAll((name, serverInfo) -> HostnameBungeeServerInfo.unwrap(serverInfo)); |
| 46 | + } |
| 47 | + |
47 | 48 | @EventHandler |
48 | 49 | public void onServerConnect(ServerConnectEvent event) { |
49 | 50 | // Get the target server address |
|
0 commit comments