mirror of https://github.com/LOOHP/Limbo.git
Updated how players are counted in metrics
This commit is contained in:
parent
292f974681
commit
17c2f58069
|
|
@ -85,6 +85,7 @@ 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
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ 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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -49,6 +50,9 @@ 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;
|
||||||
|
|
||||||
|
|
@ -58,29 +62,15 @@ 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 {
|
|
||||||
name = "Limbo";
|
|
||||||
|
|
||||||
|
public Metrics() throws IOException {
|
||||||
// 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);
|
||||||
|
|
@ -109,8 +99,6 @@ public class Metrics {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
limboVersion = Limbo.getInstance().LIMBO_IMPLEMENTATION_VERSION;
|
|
||||||
|
|
||||||
// Load the data
|
// Load the data
|
||||||
serverUUID = config.get("serverUuid", String.class);
|
serverUUID = config.get("serverUuid", String.class);
|
||||||
logFailedRequests = config.get("logFailedRequests", Boolean.class);
|
logFailedRequests = config.get("logFailedRequests", Boolean.class);
|
||||||
|
|
@ -118,26 +106,16 @@ public class Metrics {
|
||||||
startSubmitting();
|
startSubmitting();
|
||||||
}
|
}
|
||||||
|
|
||||||
addCustomChart(new Metrics.SingleLineChart("players", new Callable<Integer>() {
|
addCustomChart(new Metrics.SingleLineChart("players", () -> maxPlayerCountInPeriod.getAndSet(0)));
|
||||||
@Override
|
addCustomChart(new Metrics.SimplePie("limbo_version", () -> Limbo.getInstance().LIMBO_IMPLEMENTATION_VERSION));
|
||||||
public Integer call() throws Exception {
|
addCustomChart(new Metrics.SimplePie("minecraftVersion", () -> Limbo.getInstance().SERVER_IMPLEMENTATION_VERSION));
|
||||||
return Limbo.getInstance().getPlayers().size();
|
}
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
addCustomChart(new Metrics.SimplePie("limbo_version", new Callable<String>() {
|
/**
|
||||||
@Override
|
* Record the max player count for the last update period.
|
||||||
public String call() throws Exception {
|
*/
|
||||||
return limboVersion;
|
public void updatePlayersCount() {
|
||||||
}
|
maxPlayerCountInPeriod.getAndUpdate(i -> Math.max(i, Limbo.getInstance().getPlayers().size()));
|
||||||
}));
|
|
||||||
|
|
||||||
addCustomChart(new Metrics.SimplePie("minecraftVersion", new Callable<String>() {
|
|
||||||
@Override
|
|
||||||
public String call() throws Exception {
|
|
||||||
return Limbo.getInstance().SERVER_IMPLEMENTATION_VERSION;
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -176,7 +154,7 @@ public class Metrics {
|
||||||
private JSONObject getPluginData() {
|
private JSONObject getPluginData() {
|
||||||
JSONObject data = new JSONObject();
|
JSONObject data = new JSONObject();
|
||||||
|
|
||||||
data.put("pluginName", name); // Append the name of the server software
|
data.put("pluginName", SERVER_SOFTWARE); // 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
|
||||||
|
|
@ -232,7 +210,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 " + name + "\n" + e);
|
Limbo.getInstance().getConsole().sendMessage("Could not submit stats of " + SERVER_SOFTWARE + "\n" + e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue