From f96e8ed2da8b46f170e9a282e886ec7797fa8cc8 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Mon, 18 Oct 2021 03:36:56 +0200 Subject: [PATCH] Adds a method for checking if a player can afford a given fee --- .../knarcraft/stargate/utility/EconomyHandler.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/knarcraft/stargate/utility/EconomyHandler.java b/src/main/java/net/knarcraft/stargate/utility/EconomyHandler.java index 66cc35e..ff6be4b 100644 --- a/src/main/java/net/knarcraft/stargate/utility/EconomyHandler.java +++ b/src/main/java/net/knarcraft/stargate/utility/EconomyHandler.java @@ -103,6 +103,17 @@ public final class EconomyHandler { return EconomyHandler.chargePlayer(player, cost); } + /** + * Checks whether the given player can afford the given fee + * + * @param player

The player to check

+ * @param cost

The fee to pay

+ * @return

True if the player can afford to pay the fee

+ */ + public static boolean canAffordFee(Player player, int cost) { + return economy.getBalance(player) > cost; + } + /** * Charges the player for an action, if required * @@ -188,7 +199,7 @@ public final class EconomyHandler { * @param destination

The destination portal

* @return

The cost of using the portal

*/ - public static int getDefaultUseCost(Player player, Portal source, Portal destination) { + public static int getUseCost(Player player, Portal source, Portal destination) { //No payment required if (!EconomyHandler.useEconomy() || source.getOptions().isFree()) { return 0;