Skip to content

Commit

Permalink
Prison commands: Added two new command placeholders that are globally…
Browse files Browse the repository at this point in the history
… available to allow control of commands based upon player perms.

The new placeholders are '{ifPerm:<perm>}' and '{ifNotPerm:<perm>}' and this will control the execution of all commands that follows those placeholders.
  • Loading branch information
rbluer committed Jul 11, 2024
1 parent 06c5d08 commit 59b3369
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
7 changes: 7 additions & 0 deletions docs/changelog_v3.3.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ These change logs represent the work that has been going on within prison.
# 3.3.0-alpha.18b 2024-07-08


* **Prison commands: Added two new command placeholders that are globally available to allow control of commands based upon player perms.**
The new placeholders are '{ifPerm:<perm>}' and '{ifNotPerm:<perm>}' and this will control the execution of all commands that follows those placeholders.


* **Disabled the system settings component.** It posed too much risk for something to go wrong, especially if the config file that it was using was eliminated. Now the server is able to more intelligently deal with file names, and how to auto upgrade them. This makes it easier on the server, and it helps transition over to the new format for the file names.


* **RankPlayer files: minor change to how the permission snap shots are handled to fix a problem where it was not working correctly.**
When a player was online, it would properly populate the permsSnapShot array with the player's current perm list. But when they logged off, then it would be cleared.
This fix ensures that the perms updated and saved, so they can be properly loaded when they are not online.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ public enum CustomPlaceholders {
"{syncPlayer} runs the command as the payer in a new sync task."),


ifPerm(CommandEnvironment.all_commands,
"{ifPerm:<perm>} Continues executing commands in the chain if "
+ "the player has the perm '<perm>'."),
ifNotPerm(CommandEnvironment.all_commands,
"{ifNotPerm:<perm>} Stops executing commands in the chain if "
+ "the player has the perm '<perm>'."),


firstJoin(CommandEnvironment.rank_commands,
"{firstJoin} runs the command on first join events for new players"),
promote(CommandEnvironment.rank_commands,
Expand Down Expand Up @@ -432,6 +440,28 @@ public void runTask( Player player ) {

// was failing with leading spaces after spliting after a ";" so trim to fix it:
task = task == null ? "" : task.trim();


// If the task is '{ifPerm:<perm>}' then the player must have the perm to
// continue:
if ( task.toLowerCase().startsWith( "{ifperm:" ) ) {
String perm = task.substring( 7, task.length() - 1 );

boolean hasPerm = player.hasPermission( perm );

if ( !hasPerm ) {
break;
}
}
if ( task.toLowerCase().startsWith( "{ifnotperm:" ) ) {
String perm = task.substring( 10, task.length() - 1 );

boolean hasPerm = player.hasPermission( perm );

if ( hasPerm ) {
break;
}
}


// Apply the custom placeholders:
Expand Down

0 comments on commit 59b3369

Please sign in to comment.