Add extra parameters for completion commands. (#309)

The 2 new parameters are:
   - [owner] - the owner of island.
   - [name] - the name of the island.

Fixes #304
This commit is contained in:
BONNe 2022-11-21 08:16:42 +02:00 committed by GitHub
parent 57a4c08c0c
commit cfabb28daf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 4 deletions

View File

@ -791,17 +791,25 @@ public class TryToComplete
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))
@ -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);
}

View File

@ -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]