Compare commits

..

1 Commits

Author SHA1 Message Date
dependabot[bot] 53e947abfe
Merge 72fce754ae into 292f974681 2025-10-18 17:25:54 +01:00
2 changed files with 39 additions and 18 deletions

View File

@ -85,7 +85,6 @@ public class Unsafe {
public void a(Player player) { public void a(Player player) {
instance.playersByName.put(player.getName(), player); instance.playersByName.put(player.getName(), player);
instance.playersByUUID.put(player.getUniqueId(), player); instance.playersByUUID.put(player.getUniqueId(), player);
instance.getMetrics().updatePlayersCount();
} }
@Deprecated @Deprecated

View File

@ -39,7 +39,6 @@ import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.zip.GZIPOutputStream; import java.util.zip.GZIPOutputStream;
/** /**
@ -50,9 +49,6 @@ import java.util.zip.GZIPOutputStream;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public class Metrics { public class Metrics {
// The name of the server software
private static final String SERVER_SOFTWARE = "Limbo";
// The version of this bStats class // The version of this bStats class
public static final int B_STATS_VERSION = 1; public static final int B_STATS_VERSION = 1;
@ -62,15 +58,29 @@ public class Metrics {
// Should failed requests be logged? // Should failed requests be logged?
private static boolean logFailedRequests = false; private static boolean logFailedRequests = false;
// The name of the server software
private final String name;
// The uuid of the server // The uuid of the server
private final String serverUUID; private final String serverUUID;
private final String limboVersion;
// A list with all custom charts // A list with all custom charts
private final List<CustomChart> charts = new ArrayList<>(); private final List<CustomChart> charts = new ArrayList<>();
private final AtomicInteger maxPlayerCountInPeriod = new AtomicInteger(0); /**
* Class constructor.
*
* @param name The name of the server software.
* @param serverUUID The uuid of the server.
* @param logFailedRequests Whether failed requests should be logged or not.
* @param logger The logger for the failed requests.
* @throws IOException
*/
public Metrics() throws IOException { public Metrics() throws IOException {
name = "Limbo";
// Get the config file // Get the config file
File configFile = new File("plugins/bStats", "config.yml"); File configFile = new File("plugins/bStats", "config.yml");
FileConfiguration config = new FileConfiguration(configFile); FileConfiguration config = new FileConfiguration(configFile);
@ -98,6 +108,8 @@ public class Metrics {
e.printStackTrace(); e.printStackTrace();
} }
} }
limboVersion = Limbo.getInstance().LIMBO_IMPLEMENTATION_VERSION;
// Load the data // Load the data
serverUUID = config.get("serverUuid", String.class); serverUUID = config.get("serverUuid", String.class);
@ -106,16 +118,26 @@ public class Metrics {
startSubmitting(); startSubmitting();
} }
addCustomChart(new Metrics.SingleLineChart("players", () -> maxPlayerCountInPeriod.getAndSet(0))); addCustomChart(new Metrics.SingleLineChart("players", new Callable<Integer>() {
addCustomChart(new Metrics.SimplePie("limbo_version", () -> Limbo.getInstance().LIMBO_IMPLEMENTATION_VERSION)); @Override
addCustomChart(new Metrics.SimplePie("minecraftVersion", () -> Limbo.getInstance().SERVER_IMPLEMENTATION_VERSION)); public Integer call() throws Exception {
} return Limbo.getInstance().getPlayers().size();
}
}));
addCustomChart(new Metrics.SimplePie("limbo_version", new Callable<String>() {
@Override
public String call() throws Exception {
return limboVersion;
}
}));
/** addCustomChart(new Metrics.SimplePie("minecraftVersion", new Callable<String>() {
* Record the max player count for the last update period. @Override
*/ public String call() throws Exception {
public void updatePlayersCount() { return Limbo.getInstance().SERVER_IMPLEMENTATION_VERSION;
maxPlayerCountInPeriod.getAndUpdate(i -> Math.max(i, Limbo.getInstance().getPlayers().size())); }
}));
} }
/** /**
@ -154,7 +176,7 @@ public class Metrics {
private JSONObject getPluginData() { private JSONObject getPluginData() {
JSONObject data = new JSONObject(); JSONObject data = new JSONObject();
data.put("pluginName", SERVER_SOFTWARE); // Append the name of the server software data.put("pluginName", name); // Append the name of the server software
JSONArray customCharts = new JSONArray(); JSONArray customCharts = new JSONArray();
for (CustomChart customChart : charts) { for (CustomChart customChart : charts) {
// Add the data of the custom charts // Add the data of the custom charts
@ -210,7 +232,7 @@ public class Metrics {
} catch (Exception e) { } catch (Exception e) {
// Something went wrong! :( // Something went wrong! :(
if (logFailedRequests) { if (logFailedRequests) {
Limbo.getInstance().getConsole().sendMessage("Could not submit stats of " + SERVER_SOFTWARE + "\n" + e); Limbo.getInstance().getConsole().sendMessage("Could not submit stats of " + name + "\n" + e);
} }
} }
} }