package net.knarcraft.minigames.arena.reward; import net.knarcraft.minigames.MiniGames; import net.knarcraft.minigames.config.MiniGameMessage; import net.knarcraft.minigames.manager.EconomyManager; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import java.util.HashMap; import java.util.Map; import java.util.logging.Level; /** * A reward that gives an amount of currency when it's granted */ public class EconomyReward implements Reward { private final double amount; /** * Instantiates a new economy reward * * @param amount

The amount of currency granted

*/ public EconomyReward(double amount) { this.amount = amount; } @Override public boolean grant(@NotNull Player player) { if (!EconomyManager.isInitialized()) { MiniGames.log(Level.SEVERE, "An economy reward has been set, but no Vault-compatible economy" + " plugin has been initialized."); return false; } EconomyManager.deposit(player, amount); return true; } @Override public @NotNull String getGrantMessage() { return MiniGames.getInstance().getStringFormatter().replacePlaceholder(MiniGameMessage.SUCCESS_ECONOMY_REWARDED, "{currency}", EconomyManager.format(amount)); } @NotNull @Override public Map serialize() { Map data = new HashMap<>(); data.put("amount", amount); return data; } /** * Deserializes the economy reward defined in the given data * * @param data

The data to deserialize from

* @return

The deserialized data

*/ @SuppressWarnings("unused") public static EconomyReward deserialize(Map data) { return new EconomyReward((Double) data.get("amount")); } }