Skip to content

Commit

Permalink
Add optional requirements for balance top listing (#5394)
Browse files Browse the repository at this point in the history
Co-authored-by: Josh Roy <[email protected]>
  • Loading branch information
ayush03dev and JRoy authored Nov 25, 2024
1 parent 3f0a412 commit 57c9edc
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,10 @@ public interface ISettings extends IConf {

Tag getSecondaryColor();

BigDecimal getBaltopMinBalance();

long getBaltopMinPlaytime();

enum KeepInvPolicy {
KEEP,
DELETE,
Expand Down
10 changes: 10 additions & 0 deletions Essentials/src/main/java/com/earth2me/essentials/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -2030,4 +2030,14 @@ private TextColor _getTagColor(final String color) {
}
return null;
}

@Override
public BigDecimal getBaltopMinBalance() {
return config.getBigDecimal("baltop-requirements.minimum-balance", BigDecimal.ZERO);
}

@Override
public long getBaltopMinPlaytime() {
return config.getLong("baltop-requirements.minimum-playtime", 0);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package com.earth2me.essentials.commands;

import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.User;
import com.earth2me.essentials.textreader.SimpleTextInput;
import com.earth2me.essentials.textreader.TextPager;
import com.earth2me.essentials.utils.AdventureUtil;
import com.earth2me.essentials.utils.EnumUtil;
import com.earth2me.essentials.utils.NumberUtil;
import com.google.common.collect.Lists;
import net.essentialsx.api.v2.services.BalanceTop;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.Statistic;
import org.bukkit.command.BlockCommandSender;

import java.math.BigDecimal;
Expand Down Expand Up @@ -113,14 +117,29 @@ public void run() {
newCache.getLines().add(AdventureUtil.miniToLegacy(tlLiteral("serverTotal", AdventureUtil.parsed(NumberUtil.displayCurrency(ess.getBalanceTop().getBalanceTopTotal(), ess)))));
int pos = 1;
for (final Map.Entry<UUID, BalanceTop.Entry> entry : ess.getBalanceTop().getBalanceTopCache().entrySet()) {
if (ess.getSettings().showZeroBaltop() || entry.getValue().getBalance().compareTo(BigDecimal.ZERO) > 0) {
newCache.getLines().add(AdventureUtil.miniToLegacy(tlLiteral("balanceTopLine", pos, entry.getValue().getDisplayName(), AdventureUtil.parsed(NumberUtil.displayCurrency(entry.getValue().getBalance(), ess)))));
final BigDecimal balance = entry.getValue().getBalance();
final User user = ess.getUser(entry.getKey());

final Statistic PLAY_ONE_TICK = EnumUtil.getStatistic("PLAY_ONE_MINUTE", "PLAY_ONE_TICK");
final long playtime;
if (user.getBase() == null || !user.getBase().isOnline()) {
playtime = Bukkit.getServer().getOfflinePlayer(entry.getKey()).getStatistic(PLAY_ONE_TICK);
} else {
playtime = user.getBase().getStatistic(PLAY_ONE_TICK);
}
// Play time in seconds
final long playTimeSecs = playtime / 20;

// Checking if player meets the requirements of minimum balance and minimum playtime to be listed in baltop list
if ((ess.getSettings().showZeroBaltop() || balance.compareTo(BigDecimal.ZERO) > 0)
&& balance.compareTo(ess.getSettings().getBaltopMinBalance()) >= 0 &&
playTimeSecs > ess.getSettings().getBaltopMinPlaytime()) {
newCache.getLines().add(AdventureUtil.miniToLegacy(tlLiteral("balanceTopLine", pos, entry.getValue().getDisplayName(), AdventureUtil.parsed(NumberUtil.displayCurrency(balance, ess)))));
}
pos++;
}
cache = newCache;
}

outputCache(sender, page);
});
}
Expand Down
6 changes: 6 additions & 0 deletions Essentials/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,12 @@ pay-excludes-ignore-list: false
# NOTE: After reloading the config, you must also run '/baltop force' for this to appear
show-zero-baltop: true

# Requirements which must be met by the player to get their name shown in the balance top list.
# Playtime is in seconds.
baltop-requirements:
minimum-balance: 0
minimum-playtime: 0

# The format of currency, excluding symbols. See currency-symbol-format-locale for symbol configuration.
#
# "#,##0.00" is how the majority of countries display currency.
Expand Down

0 comments on commit 57c9edc

Please sign in to comment.