Skip to content

Commit

Permalink
Add extra parameters for completion commands. (#309)
Browse files Browse the repository at this point in the history
The 2 new parameters are:
   - [owner] - the owner of island.
   - [name] - the name of the island.

Fixes #304
  • Loading branch information
BONNe committed Nov 21, 2022
1 parent 57a4c08 commit cfabb28
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/main/java/world/bentobox/challenges/tasks/TryToComplete.java
Original file line number Diff line number Diff line change
Expand Up @@ -791,17 +791,25 @@ else if (this.challenge.getMaxTimes() > 0)
private void runCommands(List<String> commands)
{
// Ignore commands with this perm
if (user.hasPermission(this.permissionPrefix + "command.challengeexempt") && !user.isOp())
if (this.user.hasPermission(this.permissionPrefix + "command.challengeexempt") && !this.user.isOp())
{
return;
}

final Island island = this.addon.getIslandsManager().getIsland(this.world, this.user);
final String owner = island == null ? "" : this.addon.getPlayers().getName(island.getOwner());

for (String cmd : commands)
{
if (cmd.startsWith("[SELF]"))
{
String alert = "Running command '" + cmd + "' as " + this.user.getName();
this.addon.getLogger().info(alert);
cmd = cmd.substring(6).replace(Constants.PARAMETER_PLAYER, this.user.getName()).trim();
cmd = cmd.substring(6).
replaceAll(Constants.PARAMETER_PLAYER, this.user.getName()).
replaceAll(Constants.PARAMETER_OWNER, owner).
replaceAll(Constants.PARAMETER_NAME, island == null || island.getName() == null ? "" : island.getName()).
trim();
try
{
if (!user.performCommand(cmd))
Expand All @@ -816,11 +824,17 @@ private void runCommands(List<String> commands)

continue;
}

// Substitute in any references to player

try
{
if (!this.addon.getServer().dispatchCommand(this.addon.getServer().getConsoleSender(),
cmd.replace(Constants.PARAMETER_PLAYER, this.user.getName())))
cmd = cmd.replaceAll(Constants.PARAMETER_PLAYER, this.user.getName()).
replaceAll(Constants.PARAMETER_OWNER, owner).
replaceAll(Constants.PARAMETER_NAME, island == null || island.getName() == null ? "" : island.getName()).
trim();

if (!this.addon.getServer().dispatchCommand(this.addon.getServer().getConsoleSender(), cmd))
{
this.showError(cmd);
}
Expand Down
36 changes: 36 additions & 0 deletions src/main/resources/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ challenges:
# It is not necessary to writhe `/`.
# This examples first command will force player to execute `/island` command,
# While second command will run `/kill [player]` from the server console.
# There are 3 available parameters for commands:
# - [player] - player who completed the challenge
# - [owner] - the island owner
# - [name] - the name of the island.
commands:
- island
- kill [player]
Expand Down Expand Up @@ -122,6 +126,10 @@ challenges:
# It is not necessary to writhe `/`.
# This examples first command will force player to execute `/island` command,
# While second command will run `/kill [player]` from the server console.
# There are 3 available parameters for commands:
# - [player] - player who completed the challenge
# - [owner] - the island owner
# - [name] - the name of the island.
commands:
- island
- kill [player]
Expand Down Expand Up @@ -220,6 +228,10 @@ challenges:
# It is not necessary to writhe `/`.
# This examples first command will force player to execute `/island` command,
# While second command will run `/kill [player]` from the server console.
# There are 3 available parameters for commands:
# - [player] - player who completed the challenge
# - [owner] - the island owner
# - [name] - the name of the island.
commands:
- island
- kill [player]
Expand Down Expand Up @@ -254,6 +266,10 @@ challenges:
# It is not necessary to writhe `/`.
# This examples first command will force player to execute `/island` command,
# While second command will run `/kill [player]` from the server console.
# There are 3 available parameters for commands:
# - [player] - player who completed the challenge
# - [owner] - the island owner
# - [name] - the name of the island.
commands:
- island
- kill [player]
Expand Down Expand Up @@ -339,6 +355,10 @@ challenges:
# It is not necessary to writhe `/`.
# This examples first command will force player to execute `/island` command,
# While second command will run `/kill [player]` from the server console.
# There are 3 available parameters for commands:
# - [player] - player who completed the challenge
# - [owner] - the island owner
# - [name] - the name of the island.
commands:
- island
- kill [player]
Expand Down Expand Up @@ -373,6 +393,10 @@ challenges:
# It is not necessary to writhe `/`.
# This examples first command will force player to execute `/island` command,
# While second command will run `/kill [player]` from the server console.
# There are 3 available parameters for commands:
# - [player] - player who completed the challenge
# - [owner] - the island owner
# - [name] - the name of the island.
commands:
- island
- kill [player]
Expand Down Expand Up @@ -464,6 +488,10 @@ challenges:
# It is not necessary to writhe `/`.
# This examples first command will force player to execute `/island` command,
# While second command will run `/kill [player]` from the server console.
# There are 3 available parameters for commands:
# - [player] - player who completed the challenge
# - [owner] - the island owner
# - [name] - the name of the island.
commands:
- island
- kill [player]
Expand Down Expand Up @@ -498,6 +526,10 @@ challenges:
# It is not necessary to writhe `/`.
# This examples first command will force player to execute `/island` command,
# While second command will run `/kill [player]` from the server console.
# There are 3 available parameters for commands:
# - [player] - player who completed the challenge
# - [owner] - the island owner
# - [name] - the name of the island.
commands:
- island
- kill [player]
Expand Down Expand Up @@ -551,6 +583,10 @@ levels:
# It is not necessary to writhe `/`.
# This examples first command will force player to execute `/island` command,
# While second command will run `/kill [player]` from the server console.
# There are 3 available parameters for commands:
# - [player] - player who completed the challenge
# - [owner] - the island owner
# - [name] - the name of the island.
commands:
- island
- kill [player]
Expand Down

0 comments on commit cfabb28

Please sign in to comment.