Fallback gracefully and log missing Economy plugin instead of Exception

Some places I kept the exception because there is no handling or return type in place that allows
for that economy transaction to fail.
So instead of not rewarding the player with the money, an exception is logged instead
This commit is contained in:
Christian Koop 2023-08-21 10:57:35 +02:00
parent 7589bae8b0
commit c12c82afe2
No known key found for this signature in database
GPG Key ID: 89A8181384E010A3
5 changed files with 50 additions and 9 deletions

View File

@ -77,7 +77,6 @@ public class BankManager {
}
public List<String> getBalanceLore(Player player) {
;
Economy economy = this.plugin.getEconomyManager().getEconomy();
List<String> result = new ArrayList<>();
@ -85,8 +84,13 @@ public class BankManager {
Island island = SkyBlock.getPlugin(SkyBlock.class).getIslandManager().getIsland(player);
result.add("If this is null then its a easy to fix bug: " + island.toString());
if (island != null) {
double accountBalance = 0;
if (economy != null) {
accountBalance = economy.getBalance(player);
}
result.clear();
result.add(player.getDisplayName() + "'s balance is " + EconomyManager.formatEconomy(economy.getBalance(player)));
result.add(player.getDisplayName() + "'s balance is " + EconomyManager.formatEconomy(accountBalance));
result.add(player.getDisplayName() + "'s island has " + EconomyManager.formatEconomy(island.getBankBalance()));
}
return result;
@ -118,7 +122,11 @@ public class BankManager {
}
if (!admin) {
if (!economy.hasBalance(player, amt)) {
if (economy == null || !economy.hasBalance(player, amt)) {
if (economy == null) {
this.plugin.getLogger().warning("No compatible economy plugin found Please check your configuration");
}
return BankResponse.NOT_ENOUGH_MONEY;
}
@ -153,7 +161,11 @@ public class BankManager {
}
if (!admin) {
if (amt > island.getBankBalance()) {
if (economy == null || amt > island.getBankBalance()) {
if (economy == null) {
this.plugin.getLogger().warning("No compatible economy plugin found Please check your configuration");
}
return BankResponse.NOT_ENOUGH_MONEY;
}

View File

@ -574,6 +574,11 @@ public class Challenge {
@Override
public boolean has(Player p, Object obj) {
Economy economy = SkyBlock.getPlugin(SkyBlock.class).getEconomyManager().getEconomy();
if (economy == null) {
SkyBlock.getInstance().getLogger().warning("No compatible economy plugin found Please check your configuration");
return false;
}
if (obj instanceof Number) {
return economy.getBalance(p) >= ((Number) obj).doubleValue();
}

View File

@ -56,10 +56,24 @@ public class AdminBank extends SubCommand {
} else {
switch (args[0].toLowerCase()) {
case "balance":
double balance = 0;
if (args.length >= 3) {
messageManager.sendMessage(player, configLoad.getString("Command.Island.Admin.Bank.Balance.Message").replace("%player%", args[1]).replace("%bal%", EconomyManager.formatEconomy(economy.getBalance(Bukkit.getOfflinePlayer(island.getOwnerUUID())))));
if (economy != null) {
balance = economy.getBalance(Bukkit.getOfflinePlayer(island.getOwnerUUID()));
}
messageManager.sendMessage(player, configLoad.getString("Command.Island.Admin.Bank.Balance.Message")
.replace("%player%", args[1])
.replace("%bal%", EconomyManager.formatEconomy(balance)));
} else {
messageManager.sendMessage(player, configLoad.getString("Command.Island.Admin.Bank.Balance.Message").replace("%player%", args[1]).replace("%bal%", EconomyManager.formatEconomy(economy.getBalance(Bukkit.getOfflinePlayer(args[1])))));
if (economy != null) {
balance = economy.getBalance(Bukkit.getOfflinePlayer(args[1]));
}
messageManager.sendMessage(player, configLoad.getString("Command.Island.Admin.Bank.Balance.Message")
.replace("%player%", args[1])
.replace("%bal%", EconomyManager.formatEconomy(balance)));
}
return;
case "deposit":
@ -122,7 +136,13 @@ public class AdminBank extends SubCommand {
}
switch (args[0]) {
case "balance":
messageManager.sendMessage(sender, configLoad.getString("Command.Island.Admin.Bank.Balance.Message").replace("%player%", args[1]).replace("%bal%", EconomyManager.formatEconomy(economy.getBalance(Bukkit.getOfflinePlayer(args[1])))));
double balance = 0;
if (economy != null) {
balance = economy.getBalance(Bukkit.getOfflinePlayer(args[1]));
}
messageManager.sendMessage(sender, configLoad.getString("Command.Island.Admin.Bank.Balance.Message")
.replace("%player%", args[1])
.replace("%bal%", EconomyManager.formatEconomy(balance)));
return;
case "deposit":
if (args.length >= 3) {

View File

@ -72,7 +72,11 @@ public class UnlockCommand extends SubCommand {
double price = fileManager.getConfig(new File(this.plugin.getDataFolder(), "config.yml"))
.getFileConfiguration().getDouble("Island.World." + islandWorld.getFriendlyName() + ".UnlockPrice");
if (!economy.hasBalance(player, price)) {
if (economy == null || !economy.hasBalance(player, price)) {
if (economy == null) {
this.plugin.getLogger().warning("No compatible economy plugin found Please check your configuration");
}
messageManager.sendMessage(player, configLoad.getString("Command.Island.Unlock.Money.Message").replace(
"%cost%", NumberUtils.formatNumber(price)));
soundManager.playSound(player, XSound.BLOCK_ANVIL_LAND);

View File

@ -55,7 +55,7 @@ public class Upgrade {
FileConfiguration configLoad = plugin.getLanguage();
if (!economy.isEnabled()) {
if (economy == null || !economy.isEnabled()) {
messageManager.sendMessage(player, configLoad.getString("Island.Upgrade.Disabled.Message"));
soundManager.playSound(player, XSound.BLOCK_ANVIL_LAND);