diff --git a/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/api/BallAPI.java b/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/api/BallAPI.java index 09f228f..309a24e 100644 --- a/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/api/BallAPI.java +++ b/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/api/BallAPI.java @@ -47,9 +47,9 @@ public abstract class BallAPI { */ protected static BallAPI instance; @NotNull - protected final ConcurrentHashMap serverInfo; + protected final Map serverInfo; @NotNull - protected final ConcurrentHashMap playerInfo; + protected final Map playerInfo; @NotNull private final BallConfig config; @@ -99,28 +99,51 @@ public abstract class BallAPI { public void onServerOnline(@NotNull ServerOnlineEvent event) { BallServerInfo info = event.getServerInfo(); serverInfo.put(info.getId(), info); - playerInfo.forEachValue(1, playerInfo -> { - if (playerInfo.getGameServer().equals(info.getId())) { - playerInfo.setOnline(false); + switch (info.getType()) { + case GAME: { + playerInfo.forEach((uuid, playerInfo) -> { + if (playerInfo.getGameServer().equals(info.getId())) { + playerInfo.setOnline(false); + } + }); + break; } - if (playerInfo.getProxyServer().equals(info.getId())) { - playerInfo.setOnline(false); + case PROXY: { + playerInfo.forEach((uuid, playerInfo) -> { + if (playerInfo.getProxyServer().equals(info.getId())) { + playerInfo.setOnline(false); + } + }); + break; } - }); + } } @Override public void onServerOffline(@NotNull ServerOfflineEvent event) { String serverID = event.getServerID(); - serverInfo.remove(serverID); - playerInfo.forEachValue(1, playerInfo -> { - if (playerInfo.getGameServer().equals(serverID)) { - playerInfo.setOnline(false); + BallServerInfo info = serverInfo.remove(serverID); + if (info == null) { + return; + } + switch (info.getType()) { + case GAME: { + playerInfo.forEach((uuid, playerInfo) -> { + if (playerInfo.getGameServer().equals(info.getId())) { + playerInfo.setOnline(false); + } + }); + break; } - if (playerInfo.getProxyServer().equals(serverID)) { - playerInfo.setOnline(false); + case PROXY: { + playerInfo.forEach((uuid, playerInfo) -> { + if (playerInfo.getProxyServer().equals(info.getId())) { + playerInfo.setOnline(false); + } + }); + break; } - }); + } } }); } @@ -706,12 +729,12 @@ public abstract class BallAPI { * @return 玩家信息 */ public BallPlayerInfo getPlayerInfo(@NotNull String playerName) { - return playerInfo.searchValues(Long.MAX_VALUE, info -> { + for (BallPlayerInfo info : playerInfo.values()) { if (info.getName().equalsIgnoreCase(playerName)) { return info; } - return null; - }); + } + return null; } /** @@ -730,12 +753,12 @@ public abstract class BallAPI { } @NotNull - public ConcurrentHashMap getAllServerInfo() { + public Map getAllServerInfo() { return serverInfo; } @NotNull - public ConcurrentHashMap getAllPlayerInfo() { + public Map getAllPlayerInfo() { return playerInfo; }