Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional requirements for balance top listing #5394

Merged
merged 7 commits into from
Nov 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -421,6 +421,10 @@ public interface ISettings extends IConf {

Tag getSecondaryColor();

BigDecimal getBaltopMinBalance();

long getBaltopMinPlaytime();

enum KeepInvPolicy {
KEEP,
DELETE,
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
@@ -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;
@@ -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);
});
}
6 changes: 6 additions & 0 deletions Essentials/src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -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.