Skip to content

Commit 06c886c

Browse files
authored
Fix /baltop on 1.15.2 and below (#6115)
Fixes #6093
1 parent f3a1b2b commit 06c886c

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

Essentials/src/main/java/com/earth2me/essentials/commands/Commandbalancetop.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.earth2me.essentials.utils.AdventureUtil;
88
import com.earth2me.essentials.utils.EnumUtil;
99
import com.earth2me.essentials.utils.NumberUtil;
10+
import com.earth2me.essentials.utils.VersionUtil;
1011
import com.google.common.collect.Lists;
1112
import net.essentialsx.api.v2.services.BalanceTop;
1213
import org.bukkit.Bukkit;
@@ -121,9 +122,14 @@ public void run() {
121122
final User user = ess.getUser(entry.getKey());
122123

123124
final Statistic PLAY_ONE_TICK = EnumUtil.getStatistic("PLAY_ONE_MINUTE", "PLAY_ONE_TICK");
125+
final boolean offlineStatisticSupported = VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_15_2_R01);
124126
final long playtime;
125127
if (user.getBase() == null || !user.getBase().isOnline()) {
126-
playtime = Bukkit.getServer().getOfflinePlayer(entry.getKey()).getStatistic(PLAY_ONE_TICK);
128+
if (offlineStatisticSupported) {
129+
playtime = Bukkit.getServer().getOfflinePlayer(entry.getKey()).getStatistic(PLAY_ONE_TICK);
130+
} else {
131+
playtime = -1;
132+
}
127133
} else {
128134
playtime = user.getBase().getStatistic(PLAY_ONE_TICK);
129135
}
@@ -133,7 +139,8 @@ public void run() {
133139
// Checking if player meets the requirements of minimum balance and minimum playtime to be listed in baltop list
134140
if ((ess.getSettings().showZeroBaltop() || balance.compareTo(BigDecimal.ZERO) > 0)
135141
&& balance.compareTo(ess.getSettings().getBaltopMinBalance()) >= 0 &&
136-
playTimeSecs >= ess.getSettings().getBaltopMinPlaytime()) {
142+
// Skip playtime check for offline players on versions below 1.15.2
143+
(playtime == -1 || playTimeSecs >= ess.getSettings().getBaltopMinPlaytime())) {
137144
newCache.getLines().add(AdventureUtil.miniToLegacy(tlLiteral("balanceTopLine", pos, entry.getValue().getDisplayName(), AdventureUtil.parsed(NumberUtil.displayCurrency(balance, ess)))));
138145
}
139146
pos++;

0 commit comments

Comments
 (0)