Skip to content

Commit

Permalink
Economies: fixed the display of too many economy related messages, in…
Browse files Browse the repository at this point in the history
…cluding 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.
  • Loading branch information
rbluer committed Apr 28, 2024
1 parent c8ac93c commit 036a178
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 19 deletions.
6 changes: 5 additions & 1 deletion docs/changelog_v3.3.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public class RankPlayer


private long economyCacheUpdateDelayTicks = -1;


public RankPlayer() {
super();
Expand Down Expand Up @@ -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<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 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
Expand All @@ -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;
}

Expand All @@ -957,17 +958,17 @@ public List<tech.mcprison.prison.internal.block.Block> 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;
}

Expand All @@ -977,7 +978,7 @@ public void setGamemode( Gamemode gamemode ) {

@Override
public Optional<String> 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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -31,9 +32,13 @@ public class VaultEconomyWrapper

private boolean preV1dot4 = false;

private final HashSet<Player> hasNoAccount;

public VaultEconomyWrapper(String providerName ) {
super();

this.hasNoAccount = new HashSet<>();

this.providerName = providerName;

RegisteredServiceProvider<net.milkbowl.vault.economy.Economy> economyProvider =
Expand All @@ -55,6 +60,40 @@ public VaultEconomyWrapper(String providerName ) {
}
}

/**
* <p>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.
* </p>
*
* @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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 036a178

Please sign in to comment.