mirror of
https://github.com/songoda/FabledSkyBlock.git
synced 2024-09-29 23:17:26 +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) {
|
public List<String> getBalanceLore(Player player) {
|
||||||
;
|
|
||||||
Economy economy = this.plugin.getEconomyManager().getEconomy();
|
Economy economy = this.plugin.getEconomyManager().getEconomy();
|
||||||
|
|
||||||
List<String> result = new ArrayList<>();
|
List<String> result = new ArrayList<>();
|
||||||
@ -85,8 +84,13 @@ public class BankManager {
|
|||||||
Island island = SkyBlock.getPlugin(SkyBlock.class).getIslandManager().getIsland(player);
|
Island island = SkyBlock.getPlugin(SkyBlock.class).getIslandManager().getIsland(player);
|
||||||
result.add("If this is null then its a easy to fix bug: " + island.toString());
|
result.add("If this is null then its a easy to fix bug: " + island.toString());
|
||||||
if (island != null) {
|
if (island != null) {
|
||||||
|
double accountBalance = 0;
|
||||||
|
if (economy != null) {
|
||||||
|
accountBalance = economy.getBalance(player);
|
||||||
|
}
|
||||||
|
|
||||||
result.clear();
|
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()));
|
result.add(player.getDisplayName() + "'s island has " + EconomyManager.formatEconomy(island.getBankBalance()));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@ -118,7 +122,11 @@ public class BankManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!admin) {
|
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;
|
return BankResponse.NOT_ENOUGH_MONEY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,7 +161,11 @@ public class BankManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!admin) {
|
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;
|
return BankResponse.NOT_ENOUGH_MONEY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -574,6 +574,11 @@ public class Challenge {
|
|||||||
@Override
|
@Override
|
||||||
public boolean has(Player p, Object obj) {
|
public boolean has(Player p, Object obj) {
|
||||||
Economy economy = SkyBlock.getPlugin(SkyBlock.class).getEconomyManager().getEconomy();
|
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) {
|
if (obj instanceof Number) {
|
||||||
return economy.getBalance(p) >= ((Number) obj).doubleValue();
|
return economy.getBalance(p) >= ((Number) obj).doubleValue();
|
||||||
}
|
}
|
||||||
|
@ -56,10 +56,24 @@ public class AdminBank extends SubCommand {
|
|||||||
} else {
|
} else {
|
||||||
switch (args[0].toLowerCase()) {
|
switch (args[0].toLowerCase()) {
|
||||||
case "balance":
|
case "balance":
|
||||||
|
double balance = 0;
|
||||||
|
|
||||||
if (args.length >= 3) {
|
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 {
|
} 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;
|
return;
|
||||||
case "deposit":
|
case "deposit":
|
||||||
@ -122,7 +136,13 @@ public class AdminBank extends SubCommand {
|
|||||||
}
|
}
|
||||||
switch (args[0]) {
|
switch (args[0]) {
|
||||||
case "balance":
|
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;
|
return;
|
||||||
case "deposit":
|
case "deposit":
|
||||||
if (args.length >= 3) {
|
if (args.length >= 3) {
|
||||||
|
@ -72,7 +72,11 @@ public class UnlockCommand extends SubCommand {
|
|||||||
double price = fileManager.getConfig(new File(this.plugin.getDataFolder(), "config.yml"))
|
double price = fileManager.getConfig(new File(this.plugin.getDataFolder(), "config.yml"))
|
||||||
.getFileConfiguration().getDouble("Island.World." + islandWorld.getFriendlyName() + ".UnlockPrice");
|
.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(
|
messageManager.sendMessage(player, configLoad.getString("Command.Island.Unlock.Money.Message").replace(
|
||||||
"%cost%", NumberUtils.formatNumber(price)));
|
"%cost%", NumberUtils.formatNumber(price)));
|
||||||
soundManager.playSound(player, XSound.BLOCK_ANVIL_LAND);
|
soundManager.playSound(player, XSound.BLOCK_ANVIL_LAND);
|
||||||
|
@ -55,7 +55,7 @@ public class Upgrade {
|
|||||||
|
|
||||||
FileConfiguration configLoad = plugin.getLanguage();
|
FileConfiguration configLoad = plugin.getLanguage();
|
||||||
|
|
||||||
if (!economy.isEnabled()) {
|
if (economy == null || !economy.isEnabled()) {
|
||||||
messageManager.sendMessage(player, configLoad.getString("Island.Upgrade.Disabled.Message"));
|
messageManager.sendMessage(player, configLoad.getString("Island.Upgrade.Disabled.Message"));
|
||||||
soundManager.playSound(player, XSound.BLOCK_ANVIL_LAND);
|
soundManager.playSound(player, XSound.BLOCK_ANVIL_LAND);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user