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; 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.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -32,7 +33,8 @@ public class CommandReward implements Reward {
@Override @Override
public @NotNull String getGrantMessage() { public @NotNull String getGrantMessage() {
return Message.SUCCESS_COMMAND_REWARDED.getMessage("{command}", command); return MiniGames.getInstance().getStringFormatter().replacePlaceholder(
MiniGameMessage.SUCCESS_COMMAND_REWARDED, "{command}", command);
} }
@NotNull @NotNull

View File

@ -1,6 +1,7 @@
package net.knarcraft.minigames.arena.reward; 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.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -32,7 +33,8 @@ public class EconomyReward implements Reward {
@Override @Override
public @NotNull String getGrantMessage() { public @NotNull String getGrantMessage() {
//TODO: Print formatted currency amount and currency unit //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 @NotNull

View File

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

View File

@ -1,7 +1,7 @@
package net.knarcraft.minigames.arena.reward; package net.knarcraft.minigames.arena.reward;
import net.knarcraft.minigames.config.Message; import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.container.PlaceholderContainer; import net.knarcraft.minigames.config.MiniGameMessage;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -38,11 +38,12 @@ public class PermissionReward implements Reward {
@Override @Override
public @NotNull String getGrantMessage() { public @NotNull String getGrantMessage() {
if (world == null) { if (world == null) {
return Message.SUCCESS_PERMISSION_REWARDED.getMessage("{permission}", permission); return MiniGames.getInstance().getStringFormatter().replacePlaceholder(
MiniGameMessage.SUCCESS_PERMISSION_REWARDED, "{permission}", permission);
} else { } else {
PlaceholderContainer placeholderContainer = new PlaceholderContainer(); return MiniGames.getInstance().getStringFormatter().replacePlaceholders(
placeholderContainer.add("{permission}", permission).add("{world}", world.getName()); MiniGameMessage.SUCCESS_PERMISSION_REWARDED_WORLD, new String[]{"{permission}", "{world}"},
return Message.SUCCESS_PERMISSION_REWARDED_WORLD.getMessage(placeholderContainer); 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 * The message displayed when a player joins an arena
*/ */
SUCCESS_ARENA_JOINED, 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 @Override

View File

@ -40,4 +40,9 @@ en:
SUCCESS_RECORD_ACHIEVED: "You just set a {recordInfo} on the {gameMode} game-mode!" SUCCESS_RECORD_ACHIEVED: "You just set a {recordInfo} on the {gameMode} game-mode!"
RECORD_ACHIEVED_GLOBAL: "new {recordType} record" RECORD_ACHIEVED_GLOBAL: "new {recordType} record"
RECORD_ACHIEVED_PERSONAL: "personal {recordType} record" RECORD_ACHIEVED_PERSONAL: "personal {recordType} record"
SUCCESS_ARENA_JOINED: "You joined the arena." 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}"