From a5f926eb4ed8f0dafafc8a351162a01e03ec37f4 Mon Sep 17 00:00:00 2001 From: ayush03dev Date: Fri, 16 Jun 2023 08:22:55 +0530 Subject: [PATCH 1/4] Added balancetop requirements --- .../com/earth2me/essentials/ISettings.java | 4 +++- .../com/earth2me/essentials/Settings.java | 9 ++++++-- .../commands/Commandbalancetop.java | 22 +++++++++++++++++-- Essentials/src/main/resources/config.yml | 9 ++++---- 4 files changed, 35 insertions(+), 9 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/ISettings.java b/Essentials/src/main/java/com/earth2me/essentials/ISettings.java index 823734ebcf9..4e4bf946495 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/ISettings.java +++ b/Essentials/src/main/java/com/earth2me/essentials/ISettings.java @@ -404,7 +404,9 @@ public interface ISettings extends IConf { boolean isUpdateCheckEnabled(); - boolean showZeroBaltop(); + double getBaltopMinBalance(); + + long getBaltopMinPlaytime(); enum KeepInvPolicy { KEEP, diff --git a/Essentials/src/main/java/com/earth2me/essentials/Settings.java b/Essentials/src/main/java/com/earth2me/essentials/Settings.java index 43d2109d75c..c982ff76ce9 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Settings.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Settings.java @@ -1940,7 +1940,12 @@ public boolean isUpdateCheckEnabled() { } @Override - public boolean showZeroBaltop() { - return config.getBoolean("show-zero-baltop", true); + public double getBaltopMinBalance() { + return config.getDouble("baltop-requirements.minimum-balance", 0); + } + + @Override + public long getBaltopMinPlaytime() { + return config.getLong("baltop-requirements.minimum-playtime", 0); } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandbalancetop.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandbalancetop.java index a0846e43dca..188565ce187 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandbalancetop.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandbalancetop.java @@ -1,12 +1,16 @@ 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.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; @@ -112,14 +116,28 @@ public void run() { newCache.getLines().add(tl("serverTotal", NumberUtil.displayCurrency(ess.getBalanceTop().getBalanceTopTotal(), ess))); int pos = 1; for (final Map.Entry entry : ess.getBalanceTop().getBalanceTopCache().entrySet()) { - if (ess.getSettings().showZeroBaltop() || entry.getValue().getBalance().compareTo(BigDecimal.ZERO) > 0) { + 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 (balance.compareTo(BigDecimal.valueOf(ess.getSettings().getBaltopMinBalance())) >= 0 && + playTimeSecs > ess.getSettings().getBaltopMinPlaytime()) { newCache.getLines().add(tl("balanceTopLine", pos, entry.getValue().getDisplayName(), NumberUtil.displayCurrency(entry.getValue().getBalance(), ess))); } pos++; } cache = newCache; } - outputCache(sender, page); }); } diff --git a/Essentials/src/main/resources/config.yml b/Essentials/src/main/resources/config.yml index ba35a3157ad..1f2d6ee5962 100644 --- a/Essentials/src/main/resources/config.yml +++ b/Essentials/src/main/resources/config.yml @@ -832,10 +832,11 @@ minimum-pay-amount: 0.001 # Enable this to block users who try to /pay another user which ignore them. pay-excludes-ignore-list: false -# Whether or not users with a balance less than or equal to $0 should be shown in balance-top. -# Setting to false will not show people with balances <= 0 in balance-top. -# 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. # From f6095da72f6c1a667e15757cbfb0a83e05b5beba Mon Sep 17 00:00:00 2001 From: ayush03dev Date: Sat, 17 Jun 2023 07:18:18 +0530 Subject: [PATCH 2/4] Backward compatibility for show-zero-baltop --- .../src/main/java/com/earth2me/essentials/ISettings.java | 2 ++ .../src/main/java/com/earth2me/essentials/Settings.java | 5 +++++ .../com/earth2me/essentials/commands/Commandbalancetop.java | 3 ++- Essentials/src/main/resources/config.yml | 5 +++++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/ISettings.java b/Essentials/src/main/java/com/earth2me/essentials/ISettings.java index 4e4bf946495..8db3daaf888 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/ISettings.java +++ b/Essentials/src/main/java/com/earth2me/essentials/ISettings.java @@ -404,6 +404,8 @@ public interface ISettings extends IConf { boolean isUpdateCheckEnabled(); + boolean showZeroBaltop(); + double getBaltopMinBalance(); long getBaltopMinPlaytime(); diff --git a/Essentials/src/main/java/com/earth2me/essentials/Settings.java b/Essentials/src/main/java/com/earth2me/essentials/Settings.java index c982ff76ce9..8d0590992fa 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Settings.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Settings.java @@ -1939,6 +1939,11 @@ public boolean isUpdateCheckEnabled() { return config.getBoolean("update-check", true); } + @Override + public boolean showZeroBaltop() { + return config.getBoolean("show-zero-baltop", true); + } + @Override public double getBaltopMinBalance() { return config.getDouble("baltop-requirements.minimum-balance", 0); diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandbalancetop.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandbalancetop.java index 188565ce187..16b8f2adcc1 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandbalancetop.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandbalancetop.java @@ -130,7 +130,8 @@ public void run() { final long playTimeSecs = playtime / 20; // Checking if player meets the requirements of minimum balance and minimum playtime to be listed in baltop list - if (balance.compareTo(BigDecimal.valueOf(ess.getSettings().getBaltopMinBalance())) >= 0 && + if ((ess.getSettings().showZeroBaltop() || entry.getValue().getBalance().compareTo(BigDecimal.ZERO) > 0) + && balance.compareTo(BigDecimal.valueOf(ess.getSettings().getBaltopMinBalance())) >= 0 && playTimeSecs > ess.getSettings().getBaltopMinPlaytime()) { newCache.getLines().add(tl("balanceTopLine", pos, entry.getValue().getDisplayName(), NumberUtil.displayCurrency(entry.getValue().getBalance(), ess))); } diff --git a/Essentials/src/main/resources/config.yml b/Essentials/src/main/resources/config.yml index 1f2d6ee5962..3678977df74 100644 --- a/Essentials/src/main/resources/config.yml +++ b/Essentials/src/main/resources/config.yml @@ -832,6 +832,11 @@ minimum-pay-amount: 0.001 # Enable this to block users who try to /pay another user which ignore them. pay-excludes-ignore-list: false +# Whether or not users with a balance less than or equal to $0 should be shown in balance-top. +# Setting to false will not show people with balances <= 0 in balance-top. +# 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: From 2f25f8aec4877bc08429ccf6626611fad9c0ee0e Mon Sep 17 00:00:00 2001 From: ayush03dev Date: Sun, 18 Jun 2023 07:08:19 +0530 Subject: [PATCH 3/4] Replaced double with BigDecimal --- .../src/main/java/com/earth2me/essentials/ISettings.java | 2 +- .../src/main/java/com/earth2me/essentials/Settings.java | 4 ++-- .../com/earth2me/essentials/commands/Commandbalancetop.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/ISettings.java b/Essentials/src/main/java/com/earth2me/essentials/ISettings.java index 8db3daaf888..f7a69dd0f16 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/ISettings.java +++ b/Essentials/src/main/java/com/earth2me/essentials/ISettings.java @@ -406,7 +406,7 @@ public interface ISettings extends IConf { boolean showZeroBaltop(); - double getBaltopMinBalance(); + BigDecimal getBaltopMinBalance(); long getBaltopMinPlaytime(); diff --git a/Essentials/src/main/java/com/earth2me/essentials/Settings.java b/Essentials/src/main/java/com/earth2me/essentials/Settings.java index 8d0590992fa..3d0baa7b5a0 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Settings.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Settings.java @@ -1945,8 +1945,8 @@ public boolean showZeroBaltop() { } @Override - public double getBaltopMinBalance() { - return config.getDouble("baltop-requirements.minimum-balance", 0); + public BigDecimal getBaltopMinBalance() { + return config.getBigDecimal("baltop-requirements.minimum-balance", BigDecimal.ZERO); } @Override diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandbalancetop.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandbalancetop.java index 16b8f2adcc1..94edeaeed4f 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandbalancetop.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandbalancetop.java @@ -131,7 +131,7 @@ public void run() { // Checking if player meets the requirements of minimum balance and minimum playtime to be listed in baltop list if ((ess.getSettings().showZeroBaltop() || entry.getValue().getBalance().compareTo(BigDecimal.ZERO) > 0) - && balance.compareTo(BigDecimal.valueOf(ess.getSettings().getBaltopMinBalance())) >= 0 && + && balance.compareTo(ess.getSettings().getBaltopMinBalance()) >= 0 && playTimeSecs > ess.getSettings().getBaltopMinPlaytime()) { newCache.getLines().add(tl("balanceTopLine", pos, entry.getValue().getDisplayName(), NumberUtil.displayCurrency(entry.getValue().getBalance(), ess))); } From 78e12f338899268f6e9d104bc76b82b1c6206f5b Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Sun, 24 Nov 2024 22:00:13 -0500 Subject: [PATCH 4/4] Update Essentials/src/main/java/com/earth2me/essentials/commands/Commandbalancetop.java --- .../com/earth2me/essentials/commands/Commandbalancetop.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandbalancetop.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandbalancetop.java index 94edeaeed4f..cd3ee073415 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandbalancetop.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandbalancetop.java @@ -130,10 +130,10 @@ public void run() { 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() || entry.getValue().getBalance().compareTo(BigDecimal.ZERO) > 0) + if ((ess.getSettings().showZeroBaltop() || balance.compareTo(BigDecimal.ZERO) > 0) && balance.compareTo(ess.getSettings().getBaltopMinBalance()) >= 0 && playTimeSecs > ess.getSettings().getBaltopMinPlaytime()) { - newCache.getLines().add(tl("balanceTopLine", pos, entry.getValue().getDisplayName(), NumberUtil.displayCurrency(entry.getValue().getBalance(), ess))); + newCache.getLines().add(tl("balanceTopLine", pos, entry.getValue().getDisplayName(), NumberUtil.displayCurrency(balance, ess))); } pos++; }