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
*

View File

@@ -45,7 +45,7 @@ public class ItemReward implements Reward {
public @NotNull String getGrantMessage() {
return MiniGames.getInstance().getStringFormatter().replacePlaceholders(MiniGameMessage.SUCCESS_ITEM_REWARDED,
new String[]{"{amount}", "{item}"}, new String[]{String.valueOf(item.getAmount()),
item.getType().getKey().getKey()});
item.getType().getKey().getKey().replace("_", " ")});
}
@NotNull

View File

@@ -1,7 +1,6 @@
package net.knarcraft.minigames.arena.reward;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* The type of a specific reward
@@ -11,46 +10,24 @@ public enum RewardType {
/**
* A command reward
*/
COMMAND(CommandReward.class),
COMMAND,
/**
* An economy reward
*/
ECONOMY(EconomyReward.class),
ECONOMY,
/**
* An item reward
*/
ITEM(ItemReward.class),
ITEM,
/**
* A permission reward
*/
PERMISSION(PermissionReward.class),
PERMISSION,
;
private final Class<?> classType;
RewardType(Class<?> classType) {
this.classType = classType;
}
/**
* Gets the type of reward the given object represents
*
* @param object <p>A reward object</p>
* @return <p>The reward type of the given object, or null if not recognized</p>
*/
public static <K extends Reward> @Nullable RewardType getFromObject(@NotNull K object) {
for (RewardType rewardType : RewardType.values()) {
if (object.getClass() == rewardType.classType) {
return rewardType;
}
}
return null;
}
/**
* Gets a reward type from the given string
*