From e55503a9cfdc3c7e4ed81acd996ecdf2c5811533 Mon Sep 17 00:00:00 2001 From: BONNe Date: Mon, 21 Nov 2022 08:15:38 +0200 Subject: [PATCH] Add extra parameters for completion commands. The 2 new parameters are: - [owner] - the owner of island. - [name] - the name of the island. Fixes #304 --- .../challenges/tasks/TryToComplete.java | 22 +++++++++--- src/main/resources/template.yml | 36 +++++++++++++++++++ 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/tasks/TryToComplete.java b/src/main/java/world/bentobox/challenges/tasks/TryToComplete.java index ad534e5..169af48 100644 --- a/src/main/java/world/bentobox/challenges/tasks/TryToComplete.java +++ b/src/main/java/world/bentobox/challenges/tasks/TryToComplete.java @@ -791,17 +791,25 @@ public class TryToComplete private void runCommands(List 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)) @@ -816,11 +824,17 @@ public class TryToComplete 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); } diff --git a/src/main/resources/template.yml b/src/main/resources/template.yml index f0f0910..4c2f85f 100644 --- a/src/main/resources/template.yml +++ b/src/main/resources/template.yml @@ -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] @@ -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] @@ -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] @@ -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] @@ -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] @@ -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] @@ -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] @@ -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] @@ -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]