Skip to content

Commit

Permalink
Ranks: Some rank commands were failing to work properly because they …
Browse files Browse the repository at this point in the history
…were not getting the correct player. Instead of getting the play by name, it was using the sender, which would have been the player issuing the command.

This was an issue with '/ranks promote' and '/ranks demote' when issued in game.
This was fixed by only allowing the named player to be resolved, without giving the sender an option to be used.  This was changed in a number of areas to help protect form possible errors.
  • Loading branch information
rbluer committed Jan 18, 2025
1 parent c2de65a commit 24fad02
Show file tree
Hide file tree
Showing 6 changed files with 290 additions and 109 deletions.
8 changes: 7 additions & 1 deletion docs/changelog_v3.3.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@
These change logs represent the work that has been going on within prison.


# 3.3.0-alpha.19e 2024-12-22
# 3.3.0-alpha.19e 2025-01-18


* **Ranks: Some rank commands were failing to work properly because they were not getting the correct player.**
Instead of getting the play by name, it was using the sender, which would have been the player issuing the command.
This was an issue with '/ranks promote' and '/ranks demote' when issued in game.
This was fixed by only allowing the named player to be resolved, without giving the sender an option to be used. This was changed in a number of areas to help protect form possible errors.


* **PrisonBlock: Add isSellallOnly to prevent blocks added through sellall from being used in mines.**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,50 @@ public void setCmdGroup( String cmdGroup ) {
* ensure a player is always returned, if its a valid player.
* </p>
*
* <p>Never should this function return a Player based upon sender.
* </p>
*
* @param sender
* @param playerName is optional, if not supplied, then sender will be used
* @return Player if found, or null.
*/
public Player getPlayer( CommandSender sender, String playerName ) {
return getPlayer( sender, playerName, null );
public Player getPlayerByName( // CommandSender sender,
String playerName ) {
return getPlayerByName( // sender,
playerName, null );
}
// public Player getPlayer( CommandSender sender ) {
// return getPlayer( sender, null, null );
// }
public Player getPlayer( CommandSender sender, String playerName, UUID uuid ) {

/**
* <p>This function should only return a Player based upon either the player's name
* or their UUID. It should never return a Player based upon sender.
* </p>
*
* <p>Gets a player by name. If the player is not online, then try to get them from
* the offline player list. If not one is found, then return a null.
* </p>
*
* <p>The getOfflinePlayer() will now include RankPlayer as a fall back to help
* ensure a player is always returned, if its a valid player.
* </p>
*
*
* @param sender
* @param playerName
* @param uuid
* @return
*/
public Player getPlayerByName( // CommandSender sender,
String playerName, UUID uuid ) {
Player result = null;

boolean console = sender == null ? true : "CONSOLE".equalsIgnoreCase( sender.getName() );

if ( !console ) {
playerName = sender.getName();
}
// boolean console = sender == null ? true : "CONSOLE".equalsIgnoreCase( sender.getName() );
//
// if ( !console ) {
// playerName = sender.getName();
// }

result = Prison.get().getPlatform().getRankPlayer( uuid, playerName );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
Expand All @@ -41,9 +40,7 @@
import tech.mcprison.prison.internal.World;
import tech.mcprison.prison.internal.block.Block;
import tech.mcprison.prison.internal.block.MineResetType;
import tech.mcprison.prison.internal.block.MineTargetPrisonBlock;
import tech.mcprison.prison.internal.block.PrisonBlock;
import tech.mcprison.prison.internal.block.PrisonBlockStatusData;
import tech.mcprison.prison.mines.PrisonMines;
import tech.mcprison.prison.mines.data.Mine;
import tech.mcprison.prison.mines.data.Mine.MineNotificationMode;
Expand Down Expand Up @@ -3357,7 +3354,9 @@ public void mineTp(CommandSender sender,
if ( mineName != null &&
"list".equals( mineName )) {

Player player = getPlayer( sender, playerName );
Player player = playerName != null && playerName.trim().length() > 0 ?
getPlayerByName( playerName ) :
sender.getRankPlayer();

// Player playerAlt = getPlayer( playerName );
//
Expand Down Expand Up @@ -5728,7 +5727,12 @@ else if ( world == null ) {
player = sender.getPlatformPlayer();
}
else {
player = getPlayer( sender, playerName );

// Get a Bukkit online player, which is needed to run the WorldGuard commands through:
Prison.get().getPlatform().getPlayer(playerName);

// player = getPlayerByName( playerName );
// player = getPlayer( sender, playerName );
}


Expand Down
Loading

0 comments on commit 24fad02

Please sign in to comment.