From 2bc6c2c8257cbbe370174b47f70a30555aff7a0a Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Sun, 9 Jul 2023 18:52:27 +0200 Subject: [PATCH] Fixes reward messages --- .../minigames/arena/reward/CommandReward.java | 6 +++-- .../minigames/arena/reward/EconomyReward.java | 6 +++-- .../minigames/arena/reward/ItemReward.java | 11 ++++---- .../arena/reward/PermissionReward.java | 13 +++++----- .../minigames/config/MiniGameMessage.java | 25 +++++++++++++++++++ src/main/resources/strings.yml | 7 +++++- 6 files changed, 51 insertions(+), 17 deletions(-) diff --git a/src/main/java/net/knarcraft/minigames/arena/reward/CommandReward.java b/src/main/java/net/knarcraft/minigames/arena/reward/CommandReward.java index 4e2a91b..c246dda 100644 --- a/src/main/java/net/knarcraft/minigames/arena/reward/CommandReward.java +++ b/src/main/java/net/knarcraft/minigames/arena/reward/CommandReward.java @@ -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 diff --git a/src/main/java/net/knarcraft/minigames/arena/reward/EconomyReward.java b/src/main/java/net/knarcraft/minigames/arena/reward/EconomyReward.java index 2f80cbd..f1dbd6f 100644 --- a/src/main/java/net/knarcraft/minigames/arena/reward/EconomyReward.java +++ b/src/main/java/net/knarcraft/minigames/arena/reward/EconomyReward.java @@ -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 diff --git a/src/main/java/net/knarcraft/minigames/arena/reward/ItemReward.java b/src/main/java/net/knarcraft/minigames/arena/reward/ItemReward.java index dd1c40e..2247fc9 100644 --- a/src/main/java/net/knarcraft/minigames/arena/reward/ItemReward.java +++ b/src/main/java/net/knarcraft/minigames/arena/reward/ItemReward.java @@ -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 diff --git a/src/main/java/net/knarcraft/minigames/arena/reward/PermissionReward.java b/src/main/java/net/knarcraft/minigames/arena/reward/PermissionReward.java index 4ff0a2d..2bc5927 100644 --- a/src/main/java/net/knarcraft/minigames/arena/reward/PermissionReward.java +++ b/src/main/java/net/knarcraft/minigames/arena/reward/PermissionReward.java @@ -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()}); } } diff --git a/src/main/java/net/knarcraft/minigames/config/MiniGameMessage.java b/src/main/java/net/knarcraft/minigames/config/MiniGameMessage.java index 4fb9d62..dfcea44 100644 --- a/src/main/java/net/knarcraft/minigames/config/MiniGameMessage.java +++ b/src/main/java/net/knarcraft/minigames/config/MiniGameMessage.java @@ -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 diff --git a/src/main/resources/strings.yml b/src/main/resources/strings.yml index cf2062a..5613195 100644 --- a/src/main/resources/strings.yml +++ b/src/main/resources/strings.yml @@ -40,4 +40,9 @@ en: SUCCESS_RECORD_ACHIEVED: "You just set a {recordInfo} on the {gameMode} game-mode!" RECORD_ACHIEVED_GLOBAL: "new {recordType} record" RECORD_ACHIEVED_PERSONAL: "personal {recordType} record" - SUCCESS_ARENA_JOINED: "You joined the arena." \ No newline at end of file + 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}" \ No newline at end of file