Skip to content

Commit

Permalink
Fix exception while trying to get player for console command (fix pav…
Browse files Browse the repository at this point in the history
…og#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
  • Loading branch information
EpiCanard committed Jul 9, 2023
1 parent 3a88d3e commit f8e23ce
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
Expand Down Expand Up @@ -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() : "";
}

Expand All @@ -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
Expand Down Expand Up @@ -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(),
Expand All @@ -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);
Expand Down

0 comments on commit f8e23ce

Please sign in to comment.