Skip to content

Commit

Permalink
Fixes a regex bug that replaced every [player] char instead of whole …
Browse files Browse the repository at this point in the history
…word.
  • Loading branch information
BONNe committed Jan 30, 2023
1 parent 0d69459 commit 468232c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/main/java/world/bentobox/challenges/tasks/TryToComplete.java
Original file line number Diff line number Diff line change
Expand Up @@ -806,9 +806,9 @@ private void runCommands(List<String> commands)
String alert = "Running command '" + cmd + "' as " + this.user.getName();
this.addon.getLogger().info(alert);
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()).
replaceAll(Constants.ESC + Constants.PARAMETER_PLAYER, this.user.getName()).
replaceAll(Constants.ESC + Constants.PARAMETER_OWNER, owner).
replaceAll(Constants.ESC + Constants.PARAMETER_NAME, island == null || island.getName() == null ? "" : island.getName()).
trim();
try
{
Expand All @@ -829,9 +829,9 @@ private void runCommands(List<String> commands)

try
{
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()).
cmd = cmd.replaceAll(Constants.ESC + Constants.PARAMETER_PLAYER, this.user.getName()).
replaceAll(Constants.ESC + Constants.PARAMETER_OWNER, owner).
replaceAll(Constants.ESC + Constants.PARAMETER_NAME, island == null || island.getName() == null ? "" : island.getName()).
trim();

if (!this.addon.getServer().dispatchCommand(this.addon.getServer().getConsoleSender(), cmd))
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/world/bentobox/challenges/utils/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,9 @@ public class Constants
* Reference string to challenge parameter in translations.
*/
public static final String PARAMETER_CHALLENGE = "[challenge]";

/**
* Regex escape chars.
*/
public static final String ESC = "\\";
}

0 comments on commit 468232c

Please sign in to comment.