feat: 优化结构

This commit is contained in:
2023-11-12 17:45:45 +08:00
parent b52685e94c
commit 4d4413811e
2 changed files with 13 additions and 15 deletions

View File

@@ -38,11 +38,11 @@ public class PlaceholderHook extends PlaceholderExpansion {
return BallAPI.getInstance().getLocalServerInfo().getName(); return BallAPI.getInstance().getLocalServerInfo().getName();
} }
case "proxy_id": { case "proxy_id": {
return BallAPI.getInstance().getAllPlayerInfo(player.getUniqueId()).getProxyServer(); return BallAPI.getInstance().getPlayerInfo(player.getUniqueId()).getProxyServer();
} }
case "proxy_name": { case "proxy_name": {
String id = BallAPI.getInstance().getAllPlayerInfo(player.getUniqueId()).getProxyServer(); String id = BallAPI.getInstance().getPlayerInfo(player.getUniqueId()).getProxyServer();
return BallAPI.getInstance().getAllServerInfo(id).getName(); return BallAPI.getInstance().getServerInfo(id).getName();
} }
} }
return null; return null;

View File

@@ -29,8 +29,8 @@ import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger; import java.util.logging.Logger;
@SuppressWarnings("unused")
@Getter @Getter
@SuppressWarnings("unused")
public abstract class BallAPI { public abstract class BallAPI {
/** /**
* API 使用的通信频道 * API 使用的通信频道
@@ -140,7 +140,6 @@ public abstract class BallAPI {
} }
} }
} }
RedisClient client = getRedisClient();
subConnection.addListener(BallRedisListener.INSTANCE); subConnection.addListener(BallRedisListener.INSTANCE);
subscribe(BALL_CHANNEL); subscribe(BALL_CHANNEL);
} }
@@ -164,7 +163,7 @@ public abstract class BallAPI {
} }
} }
getLogger().info("正在关闭 redission"); getLogger().info("正在关闭 redission");
getRedisClient().close(); redisClient.close();
getLogger().info("已关闭 redission"); getLogger().info("已关闭 redission");
} }
@@ -293,7 +292,7 @@ public abstract class BallAPI {
public void sendMessageToPlayer(@NotNull Collection<UUID> receivers, @NotNull DisplayMessage message, boolean cache) { public void sendMessageToPlayer(@NotNull Collection<UUID> receivers, @NotNull DisplayMessage message, boolean cache) {
if (cache) { if (cache) {
for (UUID receiver : receivers) { for (UUID receiver : receivers) {
BallPlayerInfo info = getAllPlayerInfo(receiver); BallPlayerInfo info = getPlayerInfo(receiver);
if (info != null && info.isOnline()) { if (info != null && info.isOnline()) {
continue; continue;
} }
@@ -419,7 +418,6 @@ public abstract class BallAPI {
* @param block 是否阻塞(设置为 true 则必须等待消息写入网络的操作完成后,该方法才会退出) * @param block 是否阻塞(设置为 true 则必须等待消息写入网络的操作完成后,该方法才会退出)
*/ */
public void sendBallMessage(@NotNull String channel, @NotNull BallMessage message, boolean block) { public void sendBallMessage(@NotNull String channel, @NotNull BallMessage message, boolean block) {
String string = CoreAPI.getInstance().getGson().toJson(message);
if (block) { if (block) {
pubConnection.sync().publish(BALL_CHANNEL, message); pubConnection.sync().publish(BALL_CHANNEL, message);
eventBus.post(new MessageSentEvent(channel, message)); eventBus.post(new MessageSentEvent(channel, message));
@@ -470,7 +468,7 @@ public abstract class BallAPI {
* @param serverID 服务器ID * @param serverID 服务器ID
* @return 可能为 null * @return 可能为 null
*/ */
public BallServerInfo getAllServerInfo(@NotNull String serverID) { public BallServerInfo getServerInfo(@NotNull String serverID) {
return allServerInfo.get(serverID); return allServerInfo.get(serverID);
} }
@@ -480,7 +478,7 @@ public abstract class BallAPI {
* @param uuid 玩家的 UUID * @param uuid 玩家的 UUID
* @return 玩家信息 * @return 玩家信息
*/ */
public BallPlayerInfo getAllPlayerInfo(@NotNull UUID uuid) { public BallPlayerInfo getPlayerInfo(@NotNull UUID uuid) {
return allPlayerInfo.get(uuid); return allPlayerInfo.get(uuid);
} }
@@ -490,7 +488,7 @@ public abstract class BallAPI {
* @param playerName 玩家名称 * @param playerName 玩家名称
* @return 玩家信息 * @return 玩家信息
*/ */
public BallPlayerInfo getAllPlayerInfo(@NotNull String playerName) { public BallPlayerInfo getPlayerInfo(@NotNull String playerName) {
for (BallPlayerInfo info : allPlayerInfo.values()) { for (BallPlayerInfo info : allPlayerInfo.values()) {
if (info.getName().equalsIgnoreCase(playerName)) { if (info.getName().equalsIgnoreCase(playerName)) {
return info; return info;
@@ -522,7 +520,7 @@ public abstract class BallAPI {
*/ */
@Nullable @Nullable
public UUID getPlayerUUID(String playerName) { public UUID getPlayerUUID(String playerName) {
BallPlayerInfo info = getAllPlayerInfo(playerName); BallPlayerInfo info = getPlayerInfo(playerName);
if (info == null) { if (info == null) {
return null; return null;
} }
@@ -538,7 +536,7 @@ public abstract class BallAPI {
*/ */
@NotNull @NotNull
public UUID getPlayerUUID(String playerName, @NotNull UUID defaultValue) { public UUID getPlayerUUID(String playerName, @NotNull UUID defaultValue) {
BallPlayerInfo info = getAllPlayerInfo(playerName); BallPlayerInfo info = getPlayerInfo(playerName);
if (info == null) { if (info == null) {
return defaultValue; return defaultValue;
} }
@@ -553,7 +551,7 @@ public abstract class BallAPI {
*/ */
@Nullable @Nullable
public String getPlayerName(@NotNull UUID uuid) { public String getPlayerName(@NotNull UUID uuid) {
BallPlayerInfo info = getAllPlayerInfo(uuid); BallPlayerInfo info = getPlayerInfo(uuid);
if (info == null) { if (info == null) {
return null; return null;
} }
@@ -569,7 +567,7 @@ public abstract class BallAPI {
*/ */
@NotNull @NotNull
public String getPlayerName(@NotNull UUID uuid, @NotNull String defaultValue) { public String getPlayerName(@NotNull UUID uuid, @NotNull String defaultValue) {
BallPlayerInfo info = getAllPlayerInfo(uuid); BallPlayerInfo info = getPlayerInfo(uuid);
if (info == null) { if (info == null) {
return defaultValue; return defaultValue;
} }