feat: 优化结构
This commit is contained in:
@@ -38,11 +38,11 @@ public class PlaceholderHook extends PlaceholderExpansion {
|
||||
return BallAPI.getInstance().getLocalServerInfo().getName();
|
||||
}
|
||||
case "proxy_id": {
|
||||
return BallAPI.getInstance().getPlayerInfo(player.getUniqueId()).getProxyServer();
|
||||
return BallAPI.getInstance().getAllPlayerInfo(player.getUniqueId()).getProxyServer();
|
||||
}
|
||||
case "proxy_name": {
|
||||
String id = BallAPI.getInstance().getPlayerInfo(player.getUniqueId()).getProxyServer();
|
||||
return BallAPI.getInstance().getServerInfo(id).getName();
|
||||
String id = BallAPI.getInstance().getAllPlayerInfo(player.getUniqueId()).getProxyServer();
|
||||
return BallAPI.getInstance().getAllServerInfo(id).getName();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@@ -56,7 +56,7 @@ public class HamsterBallPlugin extends Plugin {
|
||||
new ServerOnlineEvent(BallAPI.getInstance().getLocalServerInfo())
|
||||
);
|
||||
// 移除失效的在线玩家
|
||||
BallAPI.getInstance().getPlayerInfo().values()
|
||||
BallAPI.getInstance().getAllPlayerInfo().values()
|
||||
.stream()
|
||||
.filter(BallPlayerInfo::isOnline)
|
||||
.filter(o -> BallAPI.getInstance().isLocalServer(o.getProxyServer()))
|
||||
|
@@ -42,9 +42,9 @@ public abstract class BallAPI {
|
||||
@Getter
|
||||
protected static BallAPI instance;
|
||||
@NotNull
|
||||
protected final Map<String, BallServerInfo> serverInfo;
|
||||
protected final Map<String, BallServerInfo> allServerInfo;
|
||||
@NotNull
|
||||
protected final Map<UUID, BallPlayerInfo> playerInfo;
|
||||
protected final Map<UUID, BallPlayerInfo> allPlayerInfo;
|
||||
@NotNull
|
||||
private final BallServerInfo localServerInfo;
|
||||
@Nullable
|
||||
@@ -64,8 +64,8 @@ public abstract class BallAPI {
|
||||
this.redisClient = redisClient;
|
||||
subConnection = redisClient.connectPubSub(BallMessage.CODEC);
|
||||
pubConnection = redisClient.connectPubSub(BallMessage.CODEC);
|
||||
serverInfo = new ConcurrentHashMap<>();
|
||||
playerInfo = new ConcurrentHashMap<>();
|
||||
allServerInfo = new ConcurrentHashMap<>();
|
||||
allPlayerInfo = new ConcurrentHashMap<>();
|
||||
eventBus = new AsyncEventBus("HamsterBall - EventBus", CoreAPI.getInstance().getExecutorService());
|
||||
eventBus.register(BallCommonListener.INSTANCE);
|
||||
if (debug) {
|
||||
@@ -114,7 +114,7 @@ public abstract class BallAPI {
|
||||
try (ResultSet set = statement.executeQuery()) {
|
||||
while (set.next()) {
|
||||
String serverID = set.getString("id");
|
||||
serverInfo.put(serverID, new BallServerInfo(
|
||||
allServerInfo.put(serverID, new BallServerInfo(
|
||||
serverID,
|
||||
set.getString("name"),
|
||||
BallServerType.valueOf(set.getString("type")),
|
||||
@@ -130,7 +130,7 @@ public abstract class BallAPI {
|
||||
try (ResultSet set = statement.executeQuery()) {
|
||||
while (set.next()) {
|
||||
UUID uuid = UUID.fromString(set.getString("uuid"));
|
||||
playerInfo.put(uuid, new BallPlayerInfo(uuid,
|
||||
allPlayerInfo.put(uuid, new BallPlayerInfo(uuid,
|
||||
set.getString("name"),
|
||||
set.getString("game_server"),
|
||||
set.getString("proxy_server"),
|
||||
@@ -293,7 +293,7 @@ public abstract class BallAPI {
|
||||
public void sendMessageToPlayer(@NotNull Collection<UUID> receivers, @NotNull DisplayMessage message, boolean cache) {
|
||||
if (cache) {
|
||||
for (UUID receiver : receivers) {
|
||||
BallPlayerInfo info = getPlayerInfo(receiver);
|
||||
BallPlayerInfo info = getAllPlayerInfo(receiver);
|
||||
if (info != null && info.isOnline()) {
|
||||
continue;
|
||||
}
|
||||
@@ -470,8 +470,8 @@ public abstract class BallAPI {
|
||||
* @param serverID 服务器ID
|
||||
* @return 可能为 null
|
||||
*/
|
||||
public BallServerInfo getServerInfo(@NotNull String serverID) {
|
||||
return serverInfo.get(serverID);
|
||||
public BallServerInfo getAllServerInfo(@NotNull String serverID) {
|
||||
return allServerInfo.get(serverID);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -480,8 +480,8 @@ public abstract class BallAPI {
|
||||
* @param uuid 玩家的 UUID
|
||||
* @return 玩家信息
|
||||
*/
|
||||
public BallPlayerInfo getPlayerInfo(@NotNull UUID uuid) {
|
||||
return playerInfo.get(uuid);
|
||||
public BallPlayerInfo getAllPlayerInfo(@NotNull UUID uuid) {
|
||||
return allPlayerInfo.get(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -490,8 +490,8 @@ public abstract class BallAPI {
|
||||
* @param playerName 玩家名称
|
||||
* @return 玩家信息
|
||||
*/
|
||||
public BallPlayerInfo getPlayerInfo(@NotNull String playerName) {
|
||||
for (BallPlayerInfo info : playerInfo.values()) {
|
||||
public BallPlayerInfo getAllPlayerInfo(@NotNull String playerName) {
|
||||
for (BallPlayerInfo info : allPlayerInfo.values()) {
|
||||
if (info.getName().equalsIgnoreCase(playerName)) {
|
||||
return info;
|
||||
}
|
||||
@@ -506,7 +506,7 @@ public abstract class BallAPI {
|
||||
* @return 玩家信息
|
||||
*/
|
||||
public BallPlayerInfo getPlayerInfoExact(@NotNull String playerName) {
|
||||
for (BallPlayerInfo info : playerInfo.values()) {
|
||||
for (BallPlayerInfo info : allPlayerInfo.values()) {
|
||||
if (info.getName().equals(playerName)) {
|
||||
return info;
|
||||
}
|
||||
@@ -522,7 +522,7 @@ public abstract class BallAPI {
|
||||
*/
|
||||
@Nullable
|
||||
public UUID getPlayerUUID(String playerName) {
|
||||
BallPlayerInfo info = getPlayerInfo(playerName);
|
||||
BallPlayerInfo info = getAllPlayerInfo(playerName);
|
||||
if (info == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -538,7 +538,7 @@ public abstract class BallAPI {
|
||||
*/
|
||||
@NotNull
|
||||
public UUID getPlayerUUID(String playerName, @NotNull UUID defaultValue) {
|
||||
BallPlayerInfo info = getPlayerInfo(playerName);
|
||||
BallPlayerInfo info = getAllPlayerInfo(playerName);
|
||||
if (info == null) {
|
||||
return defaultValue;
|
||||
}
|
||||
@@ -553,7 +553,7 @@ public abstract class BallAPI {
|
||||
*/
|
||||
@Nullable
|
||||
public String getPlayerName(@NotNull UUID uuid) {
|
||||
BallPlayerInfo info = getPlayerInfo(uuid);
|
||||
BallPlayerInfo info = getAllPlayerInfo(uuid);
|
||||
if (info == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -569,7 +569,7 @@ public abstract class BallAPI {
|
||||
*/
|
||||
@NotNull
|
||||
public String getPlayerName(@NotNull UUID uuid, @NotNull String defaultValue) {
|
||||
BallPlayerInfo info = getPlayerInfo(uuid);
|
||||
BallPlayerInfo info = getAllPlayerInfo(uuid);
|
||||
if (info == null) {
|
||||
return defaultValue;
|
||||
}
|
||||
|
@@ -19,22 +19,22 @@ public class BallCommonListener {
|
||||
@Subscribe
|
||||
public void onBallPlayerConnectServer(@NotNull BallPlayerConnectServerEvent event) {
|
||||
BallPlayerInfo info = event.getPlayerInfo();
|
||||
BallAPI.getInstance().getPlayerInfo().put(info.getUuid(), info);
|
||||
BallAPI.getInstance().getAllPlayerInfo().put(info.getUuid(), info);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onBallPlayerInfoUpdate(@NotNull BallPlayerInfoUpdateEvent event) {
|
||||
BallPlayerInfo info = event.getPlayerInfo();
|
||||
BallAPI.getInstance().getPlayerInfo().put(info.getUuid(), info);
|
||||
BallAPI.getInstance().getAllPlayerInfo().put(info.getUuid(), info);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onServerOnline(@NotNull ServerOnlineEvent event) {
|
||||
BallServerInfo info = event.getServerInfo();
|
||||
BallAPI.getInstance().getServerInfo().put(info.getId(), info);
|
||||
BallAPI.getInstance().getAllServerInfo().put(info.getId(), info);
|
||||
switch (info.getType()) {
|
||||
case GAME: {
|
||||
BallAPI.getInstance().getPlayerInfo().forEach((uuid, playerInfo) -> {
|
||||
BallAPI.getInstance().getAllPlayerInfo().forEach((uuid, playerInfo) -> {
|
||||
if (playerInfo.getGameServer().equals(info.getId())) {
|
||||
playerInfo.setOnline(false);
|
||||
}
|
||||
@@ -42,7 +42,7 @@ public class BallCommonListener {
|
||||
break;
|
||||
}
|
||||
case PROXY: {
|
||||
BallAPI.getInstance().getPlayerInfo().forEach((uuid, playerInfo) -> {
|
||||
BallAPI.getInstance().getAllPlayerInfo().forEach((uuid, playerInfo) -> {
|
||||
if (playerInfo.getProxyServer().equals(info.getId())) {
|
||||
playerInfo.setOnline(false);
|
||||
}
|
||||
@@ -55,13 +55,13 @@ public class BallCommonListener {
|
||||
@Subscribe
|
||||
public void onServerOffline(@NotNull ServerOfflineEvent event) {
|
||||
String serverID = event.getServerID();
|
||||
BallServerInfo info = BallAPI.getInstance().getServerInfo().remove(serverID);
|
||||
BallServerInfo info = BallAPI.getInstance().getAllServerInfo().remove(serverID);
|
||||
if (info == null) {
|
||||
return;
|
||||
}
|
||||
switch (info.getType()) {
|
||||
case GAME: {
|
||||
BallAPI.getInstance().getPlayerInfo().forEach((uuid, playerInfo) -> {
|
||||
BallAPI.getInstance().getAllPlayerInfo().forEach((uuid, playerInfo) -> {
|
||||
if (playerInfo.getGameServer().equals(info.getId())) {
|
||||
playerInfo.setOnline(false);
|
||||
}
|
||||
@@ -69,7 +69,7 @@ public class BallCommonListener {
|
||||
break;
|
||||
}
|
||||
case PROXY: {
|
||||
BallAPI.getInstance().getPlayerInfo().forEach((uuid, playerInfo) -> {
|
||||
BallAPI.getInstance().getAllPlayerInfo().forEach((uuid, playerInfo) -> {
|
||||
if (playerInfo.getProxyServer().equals(info.getId())) {
|
||||
playerInfo.setOnline(false);
|
||||
}
|
||||
|
Reference in New Issue
Block a user