Skip to content

Commit ca7f3b5

Browse files
maxcom1JRoy
andauthored
Add option to limit baltop entries (#6300)
```yml # Allows to limit cached balance top (/baltop) entries. This is especially recommended if # you have a large number of players, then only a certain number of entries will be stored # in the server's memory. Set to -1 to disable the limit baltop-entry-limit: -1 ``` --------- Co-authored-by: Josh Roy <[email protected]>
1 parent 973e5f8 commit ca7f3b5

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

Essentials/src/main/java/com/earth2me/essentials/BalanceTopImpl.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ private void calculateBalanceTopMap() {
5353
}
5454
final LinkedHashMap<UUID, Entry> sortedMap = new LinkedHashMap<>();
5555
entries.sort((entry1, entry2) -> entry2.getBalance().compareTo(entry1.getBalance()));
56-
for (Entry entry : entries) {
56+
final int entryLimit = ess.getSettings().getBaltopEntryLimit();
57+
final int limit = entryLimit == -1 ? entries.size() : Math.min(entryLimit, entries.size());
58+
for (int i = 0; i < limit; i++) {
59+
final Entry entry = entries.get(i);
5760
sortedMap.put(entry.getUuid(), entry);
5861
}
5962
topCache = sortedMap;

Essentials/src/main/java/com/earth2me/essentials/ISettings.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,8 @@ public interface ISettings extends IConf {
446446

447447
long getBaltopMinPlaytime();
448448

449+
int getBaltopEntryLimit();
450+
449451
enum KeepInvPolicy {
450452
KEEP,
451453
DELETE,

Essentials/src/main/java/com/earth2me/essentials/Settings.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2231,6 +2231,11 @@ public BigDecimal getBaltopMinBalance() {
22312231
return config.getBigDecimal("baltop-requirements.minimum-balance", BigDecimal.ZERO);
22322232
}
22332233

2234+
@Override
2235+
public int getBaltopEntryLimit() {
2236+
return config.getInt("baltop-entry-limit", -1);
2237+
}
2238+
22342239
@Override
22352240
public long getBaltopMinPlaytime() {
22362241
return config.getLong("baltop-requirements.minimum-playtime", 0);

Essentials/src/main/resources/config.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,11 @@ baltop-requirements:
893893
minimum-balance: 0
894894
minimum-playtime: 0
895895

896+
# Allows to limit cached balance top (/baltop) entries. This is especially recommended if
897+
# you have a large number of players, then only a certain number of entries will be stored
898+
# in the server's memory. Set to -1 to disable the limit
899+
baltop-entry-limit: -1
900+
896901
# The format of currency, excluding symbols. For symbol configuration, see 'currency-symbol-format-locale' below.
897902
#
898903
# "#,##0.00" is how the majority of countries display currency.

0 commit comments

Comments
 (0)