From d037cb7e913706fbe7e7a1f45670af87b39ab79e Mon Sep 17 00:00:00 2001 From: MiniDay <372403923@qq.com> Date: Thu, 27 Apr 2023 07:37:49 +0800 Subject: [PATCH] =?UTF-8?q?feat(common):=20=E6=B7=BB=E5=8A=A0=E6=96=B0?= =?UTF-8?q?=E7=9A=84API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mc/plugin/ball/common/api/BallAPI.java | 39 +++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) 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 81af746..a5a3520 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 @@ -740,9 +740,10 @@ public abstract class BallAPI { /** * 获取玩家的UUID * - * @param playerName 玩家名次 + * @param playerName 玩家名称 * @return 玩家的UUID */ + @Nullable public UUID getPlayerUUID(String playerName) { BallPlayerInfo info = getPlayerInfo(playerName); if (info == null) { @@ -751,17 +752,49 @@ public abstract class BallAPI { return info.getUuid(); } + /** + * 获取玩家的UUID + * + * @param playerName 玩家名称 + * @param defaultValue 如果未找到玩家信息则返回该值 + * @return 玩家的UUID + */ + @NotNull + public UUID getPlayerUUID(String playerName, @NotNull UUID defaultValue) { + BallPlayerInfo info = getPlayerInfo(playerName); + if (info == null) { + return defaultValue; + } + return info.getUuid(); + } + /** * 获取玩家名称 * * @param uuid 玩家的 UUID * @return 如果数据不存在,则返回字符串形式的 "null" */ - @NotNull + @Nullable public String getPlayerName(@NotNull UUID uuid) { BallPlayerInfo info = getPlayerInfo(uuid); if (info == null) { - return "null"; + return null; + } + return info.getName(); + } + + /** + * 获取玩家名称 + * + * @param uuid 玩家的 UUID + * @param defaultValue 如果未找到玩家信息则返回该值 + * @return 玩家名称 + */ + @NotNull + public String getPlayerName(@NotNull UUID uuid, @NotNull String defaultValue) { + BallPlayerInfo info = getPlayerInfo(uuid); + if (info == null) { + return defaultValue; } return info.getName(); }