Finishes the reward tab completer

This commit is contained in:
2023-07-11 16:36:19 +02:00
parent 9dff407713
commit 003c9e8367
17 changed files with 247 additions and 60 deletions

View File

@@ -27,8 +27,7 @@ public class CommandReward implements Reward {
@Override
public boolean grant(@NotNull Player player) {
return Bukkit.dispatchCommand(Bukkit.getServer().getConsoleSender(),
command.replaceAll("[<%(\\[]player(_|-name)?[>%)\\]]", player.getName()));
return Bukkit.dispatchCommand(Bukkit.getServer().getConsoleSender(), replaceNamePlaceholder(player, command));
}
@Override
@@ -45,6 +44,17 @@ public class CommandReward implements Reward {
return data;
}
/**
* Replaces the name placeholder in the given input with the given player's name
*
* @param player <p>The player whose name should be used</p>
* @param input <p>The input containing a name placeholder</p>
* @return <p>The input with the placeholder replaced</p>
*/
private String replaceNamePlaceholder(@NotNull Player player, @NotNull String input) {
return input.replaceAll("[<%(\\[{]player[_\\-]?(name)?[>%)\\]}]", player.getName());
}
/**
* Deserializes the command reward defined in the given data
*