Skip to content

Commit

Permalink
Player: the code that gets a player object based upon a name has been…
Browse files Browse the repository at this point in the history
… altered to address a few issues.
  • Loading branch information
rbluer committed Sep 24, 2024
1 parent d48cf39 commit 8f4507c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 13 deletions.
7 changes: 6 additions & 1 deletion docs/changelog_v3.3.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Player> 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<Player> 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<Player> 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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,14 +304,23 @@ public boolean saveRankPlayer( RankPlayer rPlayer ) {

@Override
public Optional<Player> 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()
Expand Down

0 comments on commit 8f4507c

Please sign in to comment.