diff --git a/docs/changelog_v3.3.x.md b/docs/changelog_v3.3.x.md index ad50d0710..a6951f4c5 100644 --- a/docs/changelog_v3.3.x.md +++ b/docs/changelog_v3.3.x.md @@ -14,7 +14,11 @@ These change logs represent the work that has been going on within prison. -# 3.3.0-alpha.17 2024-04-26 +# 3.3.0-alpha.17 2024-04-27 + + +* **Economies: fixed the display of too many economy related messages, including eliminating logging of messages for offline players.** +The vault economy check for offline players, will now only show one informational message if a player is not setup in the economy. * **GUI Player ranks: The setting for Options.Ranks.MaterialType.NoRankAccess was not hooked up properly so it was not really working.** diff --git a/prison-core/src/main/java/tech/mcprison/prison/ranks/data/RankPlayer.java b/prison-core/src/main/java/tech/mcprison/prison/ranks/data/RankPlayer.java index bda035e1c..2171cda20 100644 --- a/prison-core/src/main/java/tech/mcprison/prison/ranks/data/RankPlayer.java +++ b/prison-core/src/main/java/tech/mcprison/prison/ranks/data/RankPlayer.java @@ -118,6 +118,7 @@ public class RankPlayer private long economyCacheUpdateDelayTicks = -1; + public RankPlayer() { super(); @@ -902,28 +903,28 @@ public void dispatchCommand( String command ) @Override public boolean hasPermission( String perm ) { - Output.get().logError( "RankPlayer.hasPermission: Cannot access permissions for offline players." ); +// Output.get().logError( "RankPlayer.hasPermission: Cannot access permissions for offline players." ); return false; } @Override public void sendMessage( String message ) { - Output.get().logError( "RankPlayer.sendMessage: Cannot send messages to offline players." ); +// Output.get().logError( "RankPlayer.sendMessage: Cannot send messages to offline players." ); } @Override public void sendMessage( String[] messages ) { - Output.get().logError( "RankPlayer.sendMessage: Cannot send messages to offline players." ); +// Output.get().logError( "RankPlayer.sendMessage: Cannot send messages to offline players." ); } @Override public void sendMessage( List messages ) { - Output.get().logError( "RankPlayer.sendMessage: Cannot send messages to offline players." ); +// Output.get().logError( "RankPlayer.sendMessage: Cannot send messages to offline players." ); } @Override public void sendRaw( String json ) { - Output.get().logError( "RankPlayer.sendRaw: Cannot send messages to offline players." ); +// Output.get().logError( "RankPlayer.sendRaw: Cannot send messages to offline players." ); } @Override @@ -933,12 +934,12 @@ public boolean doesSupportColors() { @Override public void give( ItemStack itemStack ) { - Output.get().logError( "RankPlayer.give: Cannot give to offline players." ); +// Output.get().logError( "RankPlayer.give: Cannot give to offline players." ); } @Override public Location getLocation() { - Output.get().logError( "RankPlayer.getLocation: Offline players have no location." ); +// Output.get().logError( "RankPlayer.getLocation: Offline players have no location." ); return null; } @@ -957,17 +958,17 @@ public List getLineOfSightBlocks() { @Override public void teleport( Location location ) { - Output.get().logError( "RankPlayer.teleport: Offline players cannot be teleported." ); +// Output.get().logError( "RankPlayer.teleport: Offline players cannot be teleported." ); } @Override public void setScoreboard( Scoreboard scoreboard ) { - Output.get().logError( "RankPlayer.setScoreboard: Offline players cannot use scoreboards." ); +// Output.get().logError( "RankPlayer.setScoreboard: Offline players cannot use scoreboards." ); } @Override public Gamemode getGamemode() { - Output.get().logError( "RankPlayer.getGamemode: Offline is not a valid gamemode." ); +// Output.get().logError( "RankPlayer.getGamemode: Offline is not a valid gamemode." ); return null; } @@ -977,7 +978,7 @@ public void setGamemode( Gamemode gamemode ) { @Override public Optional getLocale() { - Output.get().logError( "RankPlayer.getLocale: Offline is not a valid gamemode." ); +// Output.get().logError( "RankPlayer.getLocale: Offline is not a valid gamemode." ); return null; } 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 c4dd89504..b93c5b6e1 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 @@ -29,7 +29,7 @@ public double getBalance(Player player) { try { EconomablePlayer p = toEconomablePlayer(player); - if ( !economyManager.accountExists( p ) ) { + if ( p == null || !economyManager.accountExists( p ) ) { player.sendMessage( "Economy Error: You don't have an account."); } else { @@ -49,7 +49,7 @@ public void setBalance(Player player, double amount) { try { EconomablePlayer p = toEconomablePlayer(player); - if ( !economyManager.accountExists( p ) ) { + if ( p == null || !economyManager.accountExists( p ) ) { player.sendMessage( "Economy Error: You don't have an account."); } else { 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 aa3960a8c..c63eb72d6 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 @@ -1,6 +1,7 @@ package tech.mcprison.prison.spigot.economies; import java.text.DecimalFormat; +import java.util.HashSet; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; @@ -31,9 +32,13 @@ public class VaultEconomyWrapper private boolean preV1dot4 = false; + private final HashSet hasNoAccount; + public VaultEconomyWrapper(String providerName ) { super(); + this.hasNoAccount = new HashSet<>(); + this.providerName = providerName; RegisteredServiceProvider economyProvider = @@ -55,6 +60,40 @@ public VaultEconomyWrapper(String providerName ) { } } + /** + *

Checks if the player has an account, if they do not, then they are + * added to the HashSet and the informational message about no account + * will only be shown once. + *

+ * + * @param player + * @return + */ + public boolean hasAccount( Player player ) { + boolean hasAccount = false; + + OfflinePlayer oPlayer = getOfflinePlayer( player ); + + try { + hasAccount = economy.hasAccount( oPlayer ); + } + catch (Exception e) { + + if ( !hasNoAccount.contains(player) ) { + Output.get().logInfo( + String.format( + "Vault economy: Player %s does not have an econ account. " + + "Informational. Not a concern. Message: [%s]", + player.getName(), e.getMessage() + )); + + hasNoAccount.add(player); + } + } + + + return hasAccount; + } public String getProviderName() { return providerName; @@ -111,7 +150,9 @@ private OfflinePlayer getOfflinePlayer(Player player) { public double getBalance(Player player) { double results = 0; - if ( economy != null && !economy.hasAccount( getOfflinePlayer( player ) ) ) { + boolean hasAccount = hasAccount(player); + + if ( economy != null && !hasAccount ) { player.sendMessage( "Economy Error: You don't have an account."); } else @@ -159,7 +200,9 @@ public double getBalance(Player player) { public boolean setBalance(Player player, double amount) { boolean results = false; - if ( economy != null && !economy.hasAccount( getOfflinePlayer( player ) ) ) { + boolean hasAccount = hasAccount(player); + + if ( economy != null && !hasAccount ) { player.sendMessage( "Economy Error: You don't have an account."); } else @@ -199,11 +242,14 @@ public boolean setBalance(Player player, double amount) { public boolean addBalance(Player player, double amount) { boolean results = false; + boolean hasAccount = hasAccount(player); + if ( amount < 0 ) { results = removeBalance( player, amount ); } - else if ( economy != null && !economy.hasAccount( getOfflinePlayer( player ) ) ) { + + else if ( economy != null && !hasAccount ) { player.sendMessage( "Economy Error: You don't have an account."); } else if (economy != null) { @@ -254,7 +300,9 @@ public boolean removeBalance(Player player, double amount) { amount *= -1; } - if ( economy != null && !economy.hasAccount( getOfflinePlayer( player ) ) ) { + boolean hasAccount = hasAccount(player); + + if ( economy != null && !hasAccount ) { player.sendMessage( "Economy Error: You don't have an account."); } else @@ -304,7 +352,9 @@ public boolean removeBalance(Player player, double amount) { public boolean canAfford(Player player, double amount) { boolean results = false; - if ( economy != null && !economy.hasAccount( getOfflinePlayer( player ) ) ) { + boolean hasAccount = hasAccount(player); + + if ( economy != null && !hasAccount ) { player.sendMessage( "Economy Error: You don't have an account."); } else