Skip to content

Commit

Permalink
Add $pos as a possible replacement to TopEntry message.
Browse files Browse the repository at this point in the history
  • Loading branch information
creatorfromhell committed Aug 31, 2024
1 parent 854f43c commit 0215947
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions .changelog/0.1.3.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Added configuration to currencies that will determine if the currency is shown in balance commands.
- Added new permissions to shared accounts; TRANSFER_OWNERSHIP and DELETE
- Added ability for messages from some money commands to be sent to players on different servers through bungee/redis/velocity
- Added $pos placeholder for TopEntry message.

## Internals
- Various improvements to the module system
Expand Down
2 changes: 2 additions & 0 deletions Core/src/net/tnemc/core/EconomyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
*/
public class EconomyManager {

public static final int TOP_PER_PAGE = 5;

//Our core identifiers, leave these as static final, because they shouldn't be changed.

//Normal and database are used internally only and don't have an associated holdings handler.
Expand Down
15 changes: 13 additions & 2 deletions Core/src/net/tnemc/core/command/MoneyCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
import java.util.Optional;
import java.util.UUID;

import static net.tnemc.core.EconomyManager.TOP_PER_PAGE;

/**
* MoneyCommands
*
Expand Down Expand Up @@ -862,19 +864,28 @@ public static void onTop(CmdSource<?> sender, Integer page, Currency currency, B

TopManager.instance().load();
}
final int max = TNECore.eco().getTopManager().page(currency.getUid());

if(page < 1) page = 1;
if(page > max) page = max;

TopPage<String> pageEntry = TNECore.eco().getTopManager().page(page, currency.getUid());
final TopPage<String> pageEntry = TNECore.eco().getTopManager().page(page, currency.getUid());
if(pageEntry != null) {
final MessageData data = new MessageData("Messages.Money.Top");
data.addReplacement("$page", String.valueOf(page));
data.addReplacement("$page_top", String.valueOf(TNECore.eco().getTopManager().page(currency.getUid())));
data.addReplacement("$page_top", String.valueOf(max));
sender.message(data);

final int adjusted = (page - 1) * TOP_PER_PAGE;
int i = 1;
for(Map.Entry<String, BigDecimal> entry : pageEntry.getValues().entrySet()) {
final MessageData en = new MessageData("Messages.Money.TopEntry");
en.addReplacement("$pos", (adjusted + i));
en.addReplacement("$player", entry.getKey());
en.addReplacement("$amount", CurrencyFormatter.format(senderAccount.get(), new HoldingsEntry(TNECore.eco().region().defaultRegion(), currency.getUid(), entry.getValue(), EconomyManager.NORMAL)));
sender.message(en);

i++;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class BaseTranslationProvider implements TranslationProvider {
@Override
public String getLang(UUID identifier) {

Optional<Account> account = TNECore.eco().account().findAccount(identifier);
final Optional<Account> account = TNECore.eco().account().findAccount(identifier);

if(account.isPresent() && account.get().isPlayer()) {
return ((PlayerAccount)account.get()).getLanguage();
Expand Down
4 changes: 3 additions & 1 deletion Core/src/net/tnemc/core/manager/top/TopCurrency.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import java.util.UUID;
import java.util.regex.Pattern;

import static net.tnemc.core.EconomyManager.TOP_PER_PAGE;

/**
* TopCurrency
*
Expand All @@ -34,7 +36,7 @@
*/
public class TopCurrency {

private final MultiTreeMap<String> balances = new MultiTreeMap<>(5);
private final MultiTreeMap<String> balances = new MultiTreeMap<>(TOP_PER_PAGE);

private final String region;
private final UUID currency;
Expand Down

0 comments on commit 0215947

Please sign in to comment.