From 8f4507c28a9cec3025a7ba65c0186e5647c22c41 Mon Sep 17 00:00:00 2001 From: rbluer <665978+rbluer@users.noreply.github.com> Date: Tue, 24 Sep 2024 04:44:20 -0400 Subject: [PATCH] Player: the code that gets a player object based upon a name has been altered to address a few issues. --- docs/changelog_v3.3.x.md | 7 +++- .../prison/commands/BaseCommands.java | 36 +++++++++++++++---- .../prison/spigot/SpigotPlatform.java | 19 +++++++--- 3 files changed, 49 insertions(+), 13 deletions(-) diff --git a/docs/changelog_v3.3.x.md b/docs/changelog_v3.3.x.md index 04acb748b..3cfb7cdeb 100644 --- a/docs/changelog_v3.3.x.md +++ b/docs/changelog_v3.3.x.md @@ -14,7 +14,12 @@ These change logs represent the work that has been going on within prison. -# 3.3.0-alpha.19c 2024-09-22 +# 3.3.0-alpha.19c 2024-09-24 + + + + +* **Player: the code that gets a player object based upon a name has been altered to address a few issues.** * **WorldGuard Regions: Updated the configs to include placeholders for the world, and updated the code to support it too.** diff --git a/prison-core/src/main/java/tech/mcprison/prison/commands/BaseCommands.java b/prison-core/src/main/java/tech/mcprison/prison/commands/BaseCommands.java index 48de15a3e..fd5ced701 100644 --- a/prison-core/src/main/java/tech/mcprison/prison/commands/BaseCommands.java +++ b/prison-core/src/main/java/tech/mcprison/prison/commands/BaseCommands.java @@ -50,24 +50,46 @@ public Player getPlayer( CommandSender sender, String playerName ) { public Player getPlayer( CommandSender sender, String playerName, UUID uuid ) { Player result = null; - playerName = playerName != null && !playerName.trim().isEmpty() ? - playerName : sender != null ? sender.getName() : null; - - //Output.get().logInfo("RanksCommands.getPlayer :: playerName = " + playerName ); + boolean console = "CONSOLE".equalsIgnoreCase( sender.getName() ); + if ( !console ) { + playerName = sender.getName(); + } if ( playerName != null ) { Optional opt = Prison.get().getPlatform().getPlayer( playerName ); if ( !opt.isPresent() ) { opt = Prison.get().getPlatform().getOfflinePlayer( playerName ); } - if ( !opt.isPresent() ) { - opt = Prison.get().getPlatform().getOfflinePlayer( uuid ); + if ( opt.isPresent() ) { + result = opt.get(); } + } + if ( result == null && uuid != null ) { + Optional opt = Prison.get().getPlatform().getOfflinePlayer( uuid ); if ( opt.isPresent() ) { result = opt.get(); } - } + +// playerName = playerName != null && !playerName.trim().isEmpty() ? +// playerName : sender != null ? sender.getName() : null; +// +// //Output.get().logInfo("RanksCommands.getPlayer :: playerName = " + playerName ); +// +// // Do not try to get the player name if +// if ( playerName != null ) { +// Optional opt = Prison.get().getPlatform().getPlayer( playerName ); +// if ( !opt.isPresent() ) { +// opt = Prison.get().getPlatform().getOfflinePlayer( playerName ); +// } +// if ( !opt.isPresent() ) { +// opt = Prison.get().getPlatform().getOfflinePlayer( uuid ); +// } +// if ( opt.isPresent() ) { +// result = opt.get(); +// } +// +// } return result; } diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotPlatform.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotPlatform.java index b4d3b033e..d22c14ccd 100644 --- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotPlatform.java +++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotPlatform.java @@ -304,14 +304,23 @@ public boolean saveRankPlayer( RankPlayer rPlayer ) { @Override public Optional getPlayer(String name) { + SpigotPlayer player = null; - org.bukkit.entity.Player playerBukkit = Bukkit.getPlayer(name); - - if ( name != null && playerBukkit != null && !playerBukkit.getName().equalsIgnoreCase( name ) ) { - playerBukkit = null; + if ( !"CONSOLE".equalsIgnoreCase( name ) ) { + + org.bukkit.entity.Player playerBukkit = Bukkit.getPlayer(name); + + if ( name != null && playerBukkit != null && !playerBukkit.getName().equalsIgnoreCase( name ) ) { + playerBukkit = null; + } + + if ( playerBukkit != null ) { + player = new SpigotPlayer( playerBukkit ); + } } - return Optional.ofNullable( playerBukkit == null ? null : new SpigotPlayer(playerBukkit) ); + return Optional.ofNullable( player ); +// return Optional.ofNullable( playerBukkit == null ? null : new SpigotPlayer(playerBukkit) ); // return Optional.ofNullable( // players.stream().filter(player -> player.getName().equalsIgnoreCase( name)).findFirst()