diff --git a/docs/changelog_v3.3.x.md b/docs/changelog_v3.3.x.md index 1a83c27a7..968534699 100644 --- a/docs/changelog_v3.3.x.md +++ b/docs/changelog_v3.3.x.md @@ -17,6 +17,11 @@ These change logs represent the work that has been going on within prison. # 3.3.0-alpha.16c 2024-03-15 + +* **Economy: For economies that prison supports that has a method to check if the player has an account, prison now tries to check if there is an account for the player before trying to use the economy.** +This could potentially prevent issues or run time failures. + + * **Prison API: Added a few new functions to work with ItemStacks.** diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/economies/EssEconomyWrapper.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/economies/EssEconomyWrapper.java index b1cf349d8..f3392f4f4 100644 --- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/economies/EssEconomyWrapper.java +++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/economies/EssEconomyWrapper.java @@ -39,7 +39,13 @@ class EssEconomyWrapper { double getBalance(Player player) { try { - return Economy.getMoneyExact(player.getName()).doubleValue(); + if ( Economy.playerExists( player.getName() ) ) { + return Economy.getMoneyExact(player.getName()).doubleValue(); + } + + player.sendMessage( "You don't exist in the economy plugin." ); + return 0; + } catch (UserDoesNotExistException e) { player.sendMessage("You don't exist in the economy plugin."); return 0.0; @@ -48,7 +54,14 @@ class EssEconomyWrapper { void setBalance(Player player, double amount) { try { - Economy.setMoney(player.getName(), new BigDecimal(amount)); + if ( Economy.playerExists( player.getName() ) ) { + Economy.setMoney(player.getName(), new BigDecimal(amount)); + } + else { + + player.sendMessage( "You don't exist in the economy plugin." ); + } + } catch (UserDoesNotExistException | NoLoanPermittedException e) { player.sendMessage("You don't exist in the economy plugin."); } diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/economies/SaneEconomyWrapper.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/economies/SaneEconomyWrapper.java index cee34711a..c4dd89504 100644 --- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/economies/SaneEconomyWrapper.java +++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/economies/SaneEconomyWrapper.java @@ -27,7 +27,15 @@ public double getBalance(Player player) { double result = 0; try { - result = economyManager.getBalance(toEconomablePlayer(player)); + EconomablePlayer p = toEconomablePlayer(player); + + if ( !economyManager.accountExists( p ) ) { + player.sendMessage( "Economy Error: You don't have an account."); + } + else { + + result = economyManager.getBalance( p ); + } } catch ( Exception e ) { Output.get().logError( "Failed to get SaneEconomy balance. " + @@ -39,7 +47,16 @@ public double getBalance(Player player) { public void setBalance(Player player, double amount) { try { - economyManager.setBalance(toEconomablePlayer(player), amount); + EconomablePlayer p = toEconomablePlayer(player); + + if ( !economyManager.accountExists( p ) ) { + player.sendMessage( "Economy Error: You don't have an account."); + } + else { + + economyManager.setBalance(toEconomablePlayer(player), amount); + } + } catch ( Exception e ) { Output.get().logError( "Failed to set SaneEconomy balance. " + diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/economies/VaultEconomyWrapper.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/economies/VaultEconomyWrapper.java index b34c0f9a8..aa3960a8c 100644 --- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/economies/VaultEconomyWrapper.java +++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/economies/VaultEconomyWrapper.java @@ -110,7 +110,13 @@ private OfflinePlayer getOfflinePlayer(Player player) { @SuppressWarnings( "deprecation" ) public double getBalance(Player player) { double results = 0; + + if ( economy != null && !economy.hasAccount( getOfflinePlayer( player ) ) ) { + player.sendMessage( "Economy Error: You don't have an account."); + } + else if (economy != null) { + if ( isPreV1_4() ) { results = economy.getBalance(player.getName()); } @@ -152,6 +158,11 @@ public double getBalance(Player player) { @SuppressWarnings( "deprecation" ) public boolean setBalance(Player player, double amount) { boolean results = false; + + if ( economy != null && !economy.hasAccount( getOfflinePlayer( player ) ) ) { + player.sendMessage( "Economy Error: You don't have an account."); + } + else if (economy != null) { if ( isPreV1_4() ) { @@ -191,6 +202,10 @@ public boolean addBalance(Player player, double amount) { if ( amount < 0 ) { results = removeBalance( player, amount ); } + + else if ( economy != null && !economy.hasAccount( getOfflinePlayer( player ) ) ) { + player.sendMessage( "Economy Error: You don't have an account."); + } else if (economy != null) { if ( isPreV1_4() ) { economy.depositPlayer( player.getName(), amount ); @@ -239,6 +254,10 @@ public boolean removeBalance(Player player, double amount) { amount *= -1; } + if ( economy != null && !economy.hasAccount( getOfflinePlayer( player ) ) ) { + player.sendMessage( "Economy Error: You don't have an account."); + } + else if (economy != null) { if ( isPreV1_4() ) { economy.withdrawPlayer( player.getName(), amount ); @@ -284,6 +303,11 @@ public boolean removeBalance(Player player, double amount) { @SuppressWarnings( "deprecation" ) public boolean canAfford(Player player, double amount) { boolean results = false; + + if ( economy != null && !economy.hasAccount( getOfflinePlayer( player ) ) ) { + player.sendMessage( "Economy Error: You don't have an account."); + } + else if (economy != null) { if ( isPreV1_4() ) { results = economy.has(player.getName(), amount);