mirror of
https://github.com/songoda/FabledSkyBlock.git
synced 2024-06-28 23:54:57 +02:00
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:
parent
7589bae8b0
commit
c12c82afe2
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user