Fixes reward messages

This commit is contained in:
Kristian Knarvik 2023-07-09 18:52:27 +02:00
parent f24959c8d1
commit 2bc6c2c825
6 changed files with 51 additions and 17 deletions

View File

@ -1,6 +1,7 @@
package net.knarcraft.minigames.arena.reward;
import net.knarcraft.minigames.config.Message;
import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.config.MiniGameMessage;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
@ -32,7 +33,8 @@ public class CommandReward implements Reward {
@Override
public @NotNull String getGrantMessage() {
return Message.SUCCESS_COMMAND_REWARDED.getMessage("{command}", command);
return MiniGames.getInstance().getStringFormatter().replacePlaceholder(
MiniGameMessage.SUCCESS_COMMAND_REWARDED, "{command}", command);
}
@NotNull

View File

@ -1,6 +1,7 @@
package net.knarcraft.minigames.arena.reward;
import net.knarcraft.minigames.config.Message;
import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.config.MiniGameMessage;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
@ -32,7 +33,8 @@ public class EconomyReward implements Reward {
@Override
public @NotNull String getGrantMessage() {
//TODO: Print formatted currency amount and currency unit
return Message.SUCCESS_ECONOMY_REWARDED.getMessage("{currency}", String.valueOf(amount));
return MiniGames.getInstance().getStringFormatter().replacePlaceholder(MiniGameMessage.SUCCESS_ECONOMY_REWARDED,
"{currency}", String.valueOf(amount));
}
@NotNull

View File

@ -1,7 +1,7 @@
package net.knarcraft.minigames.arena.reward;
import net.knarcraft.minigames.config.Message;
import net.knarcraft.minigames.container.PlaceholderContainer;
import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.config.MiniGameMessage;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
@ -43,10 +43,9 @@ public class ItemReward implements Reward {
@Override
public @NotNull String getGrantMessage() {
PlaceholderContainer placeholderContainer = new PlaceholderContainer();
placeholderContainer.add("{amount}", String.valueOf(item.getAmount())).add("{item}",
item.getType().getKey().getKey());
return Message.SUCCESS_ITEM_REWARDED.getMessage();
return MiniGames.getInstance().getStringFormatter().replacePlaceholders(MiniGameMessage.SUCCESS_ITEM_REWARDED,
new String[]{"{amount}", "{item}"}, new String[]{String.valueOf(item.getAmount()),
item.getType().getKey().getKey()});
}
@NotNull

View File

@ -1,7 +1,7 @@
package net.knarcraft.minigames.arena.reward;
import net.knarcraft.minigames.config.Message;
import net.knarcraft.minigames.container.PlaceholderContainer;
import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.config.MiniGameMessage;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
@ -38,11 +38,12 @@ public class PermissionReward implements Reward {
@Override
public @NotNull String getGrantMessage() {
if (world == null) {
return Message.SUCCESS_PERMISSION_REWARDED.getMessage("{permission}", permission);
return MiniGames.getInstance().getStringFormatter().replacePlaceholder(
MiniGameMessage.SUCCESS_PERMISSION_REWARDED, "{permission}", permission);
} else {
PlaceholderContainer placeholderContainer = new PlaceholderContainer();
placeholderContainer.add("{permission}", permission).add("{world}", world.getName());
return Message.SUCCESS_PERMISSION_REWARDED_WORLD.getMessage(placeholderContainer);
return MiniGames.getInstance().getStringFormatter().replacePlaceholders(
MiniGameMessage.SUCCESS_PERMISSION_REWARDED_WORLD, new String[]{"{permission}", "{world}"},
new String[]{permission, world.getName()});
}
}

View File

@ -228,6 +228,31 @@ public enum MiniGameMessage implements TranslatableMessage {
* The message displayed when a player joins an arena
*/
SUCCESS_ARENA_JOINED,
/**
* The message displayed when a player is rewarded with an item
*/
SUCCESS_ITEM_REWARDED,
/**
* The message displayed when a player is rewarded with a permission
*/
SUCCESS_PERMISSION_REWARDED,
/**
* The message displayed when a player is rewarded with a permission, for a specific world
*/
SUCCESS_PERMISSION_REWARDED_WORLD,
/**
* The message displayed when a player is rewarded by a command being run
*/
SUCCESS_COMMAND_REWARDED,
/**
* The message displayed when a player is rewarded with an amount of currency
*/
SUCCESS_ECONOMY_REWARDED,
;
@Override

View File

@ -41,3 +41,8 @@ en:
RECORD_ACHIEVED_GLOBAL: "new {recordType} record"
RECORD_ACHIEVED_PERSONAL: "personal {recordType} record"
SUCCESS_ARENA_JOINED: "You joined the arena."
SUCCESS_ITEM_REWARDED: "You have been rewarded {amount} {item}(s)"
SUCCESS_PERMISSION_REWARDED: "You have been granted the permission: {permission}"
SUCCESS_PERMISSION_REWARDED_WORLD: "You have been granted the permission: {permission} in world: {world}"
SUCCESS_COMMAND_REWARDED: "The command `{command}` has been run as your reward."
SUCCESS_ECONOMY_REWARDED: "You have been granted {currency}"