From f8e23ce5b46e780d5cc5c9df74c136f445bf3f11 Mon Sep 17 00:00:00 2001 From: EpiCanard Date: Sun, 9 Jul 2023 20:02:34 +0200 Subject: [PATCH] Fix exception while trying to get player for console command (fix #196) With Bukkit MC 1.20 call to CraftServer.getPlayer with null uuid generate the following exception : java.lang.IllegalArgumentException: UUID id cannot be null --- .../tools/caller/bukkit/BukkitPlayerCaller.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/greatmancode/craftconomy3/tools/caller/bukkit/BukkitPlayerCaller.java b/src/main/java/com/greatmancode/craftconomy3/tools/caller/bukkit/BukkitPlayerCaller.java index 8f69e1d7..e0021ac4 100644 --- a/src/main/java/com/greatmancode/craftconomy3/tools/caller/bukkit/BukkitPlayerCaller.java +++ b/src/main/java/com/greatmancode/craftconomy3/tools/caller/bukkit/BukkitPlayerCaller.java @@ -40,6 +40,8 @@ public BukkitPlayerCaller(ServerCaller caller) { private Player getBukkitPlayer(UUID uuid) { + if (uuid == null) + return null; return ((BukkitLoader) getCaller().getLoader()).getServer().getPlayer(uuid); } @@ -139,7 +141,7 @@ public String getPlayerWorld(String playerName) { @Override public String getPlayerWorld(UUID uuid) { - Player p = ((BukkitLoader) getCaller().getLoader()).getServer().getPlayer(uuid); + Player p = getBukkitPlayer(uuid); return (p != null) ? p.getWorld().getName() : ""; } @@ -151,7 +153,7 @@ public boolean isOnline(String playerName) { @Override public boolean isOnline(UUID uuid) { - return ((BukkitLoader) getCaller().getLoader()).getServer().getPlayer(uuid) != null; + return getBukkitPlayer(uuid) != null; } @Override @@ -209,7 +211,7 @@ public String getPlayerName(UUID uuid) { @Override public com.greatmancode.craftconomy3.tools.entities.Player getPlayer(UUID uuid) { - Player player = ((BukkitLoader) getCaller().getLoader()).getServer().getPlayer(uuid); + Player player = getBukkitPlayer(uuid); if (player == null) return null; CommandSender sender = new PlayerCommandSender<>(player.getDisplayName(), player.getUniqueId(), player); return new com.greatmancode.craftconomy3.tools.entities.Player(player.getName(), @@ -231,7 +233,7 @@ public com.greatmancode.craftconomy3.tools.entities.Player getOnlinePlayer(Strin @Override public com.greatmancode.craftconomy3.tools.entities.Player getOnlinePlayer(UUID uuid) { - Player player = ((BukkitLoader) getCaller().getLoader()).getServer().getPlayer(uuid); + Player player = getBukkitPlayer(uuid); if (player == null) return null; if (player.isOnline()) { CommandSender sender = new PlayerCommandSender<>(player.getDisplayName(), player.getUniqueId(), player);