Skip to content

Commit

Permalink
Add message for when accounts hold balances of invalid currencies.
Browse files Browse the repository at this point in the history
Signed-off-by: creatorfromhell <[email protected]>
  • Loading branch information
creatorfromhell committed Aug 24, 2023
1 parent e6c2d67 commit 426843d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
16 changes: 16 additions & 0 deletions Core/src/net/tnemc/core/EconomyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@
import net.tnemc.core.region.RegionProvider;
import net.tnemc.core.utils.Identifier;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -65,6 +67,8 @@ public class EconomyManager {

private final LinkedHashMap<String, HoldingsHandler> handlers = new LinkedHashMap<>();

private final List<String> invalidCurrencies = new ArrayList<>();

private final Map<String, Identifier> ids = new ConcurrentHashMap<>();

private final AccountManager accountManager;
Expand Down Expand Up @@ -163,4 +167,16 @@ public TopManager getTopManager() {
public static EconomyManager instance() {
return instance;
}

public static List<String> invalidCurrencies() {
return instance.invalidCurrencies;
}

public void printInvalid() {
if(invalidCurrencies.size() > 0) {
for(final String currency : invalidCurrencies) {
TNECore.log().inform("Account Balances found for non existent currency ID: " + currency);
}
}
}
}
2 changes: 2 additions & 0 deletions Core/src/net/tnemc/core/TNECore.java
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,8 @@ protected void onEnable() {
}
}

economyManager.printInvalid();

server.scheduler().createDelayedTask(()-> economyManager.getTopManager().load(), new ChoreTime(2), ChoreExecution.SECONDARY);
server.scheduler().createRepeatingTask(()-> economyManager.getTopManager().load(), new ChoreTime(2), new ChoreTime(MainConfig.yaml().getInt("Core.Commands.Top.Refresh"), TimeUnit.SECONDS), ChoreExecution.SECONDARY);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import net.tnemc.core.EconomyManager;
import net.tnemc.core.TNECore;
import net.tnemc.core.account.Account;
import net.tnemc.core.account.holdings.CurrencyHoldings;
Expand Down Expand Up @@ -147,9 +148,15 @@ public Collection<HoldingsEntry> loadAll(StorageConnector<?> connector, @Nullabl
})) {
while(result.next()) {

final String currency = result.getString("currency");

if(TNECore.eco().currency().findCurrency(currency).isEmpty()) {
EconomyManager.invalidCurrencies().add(currency);
}

//region, currency, amount, type
final HoldingsEntry entry = new HoldingsEntry(result.getString("region"),
UUID.fromString(result.getString("currency")),
UUID.fromString(currency),
result.getBigDecimal("holdings"),
Identifier.fromID(result.getString("holdings_type")));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import net.tnemc.core.EconomyManager;
import net.tnemc.core.TNECore;
import net.tnemc.core.account.Account;
import net.tnemc.core.account.holdings.CurrencyHoldings;
Expand Down Expand Up @@ -185,6 +186,10 @@ public Collection<HoldingsEntry> loadAll(StorageConnector<?> connector, @Nullabl
}
for(final String currency : main.getConfigurationSection(server + "." + region).getKeys(false)) {

if(TNECore.eco().currency().findCurrency(currency).isEmpty()) {
EconomyManager.invalidCurrencies().add(currency);
}

if(!main.contains(server + "." + region + "." + currency)) {
continue;
}
Expand Down

0 comments on commit 426843d

Please sign in to comment.