mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-02-16 20:32:29 +01:00
Implements better online player counter. (#1791)
Current one is based on online player count when bStats sends data to the server. This one will send data about amount of players who logged in the server.
This commit is contained in:
parent
19ddd73204
commit
3a1ec0a570
@ -1,7 +1,10 @@
|
||||
package world.bentobox.bentobox;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bstats.charts.AdvancedPie;
|
||||
@ -29,6 +32,13 @@ public class BStats {
|
||||
*/
|
||||
private int islandsCreatedCount = 0;
|
||||
|
||||
/**
|
||||
* Contains the amount of connected players since last data send.
|
||||
* @since 1.17.1
|
||||
*/
|
||||
private final Set<UUID> connectedPlayerSet = new HashSet<>();
|
||||
|
||||
|
||||
BStats(BentoBox plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
@ -86,6 +96,15 @@ public class BStats {
|
||||
islandsCreatedCount++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds given UUID to the connected player set.
|
||||
* @param uuid UUID of a player who logins.
|
||||
* @since 1.17.1
|
||||
*/
|
||||
public void addPlayer(UUID uuid) {
|
||||
this.connectedPlayerSet.add(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the enabled addons (except GameModeAddons) of this server.
|
||||
* @since 1.1
|
||||
@ -132,7 +151,9 @@ public class BStats {
|
||||
*/
|
||||
private void registerPlayersPerServerChart() {
|
||||
metrics.addCustomChart(new SimplePie("playersPerServer", () -> {
|
||||
int players = Bukkit.getOnlinePlayers().size();
|
||||
int players = this.connectedPlayerSet.size();
|
||||
this.connectedPlayerSet.clear();
|
||||
|
||||
if (players <= 0) return "0";
|
||||
else if (players <= 10) return "1-10";
|
||||
else if (players <= 30) return "11-30";
|
||||
|
@ -102,6 +102,9 @@ public class JoinLeaveListener implements Listener {
|
||||
plugin.getIslands().getMaxMembers(i, RanksManager.TRUSTED_RANK);
|
||||
plugin.getIslands().getMaxHomes(i);
|
||||
});
|
||||
|
||||
// Add a player to the bStats cache.
|
||||
plugin.getMetrics().ifPresent(bStats -> bStats.addPlayer(playerUUID));
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user