perf(common): 优化代码

This commit is contained in:
2023-01-30 08:21:04 +08:00
parent 3beff09536
commit d2d2e648fe

View File

@@ -47,9 +47,9 @@ public abstract class BallAPI {
*/
protected static BallAPI instance;
@NotNull
protected final ConcurrentHashMap<String, BallServerInfo> serverInfo;
protected final Map<String, BallServerInfo> serverInfo;
@NotNull
protected final ConcurrentHashMap<UUID, BallPlayerInfo> playerInfo;
protected final Map<UUID, BallPlayerInfo> 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<String, BallServerInfo> getAllServerInfo() {
public Map<String, BallServerInfo> getAllServerInfo() {
return serverInfo;
}
@NotNull
public ConcurrentHashMap<UUID, BallPlayerInfo> getAllPlayerInfo() {
public Map<UUID, BallPlayerInfo> getAllPlayerInfo() {
return playerInfo;
}