Skip to content

Commit 7a4a285

Browse files
committed
Add some more useful metrics
1 parent f38c393 commit 7a4a285

File tree

2 files changed

+36
-10
lines changed

2 files changed

+36
-10
lines changed

src/main/java/com/comphenix/protocol/metrics/Metrics.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,10 @@ public JSONObject getPluginData() {
174174
JSONObject data = new JSONObject();
175175

176176
String pluginName = plugin.getDescription().getName();
177-
Pair<String, String> pluginVersion = Statistics.splitVersion(); // ProtocolLib - remove build number
177+
String pluginVersion = Statistics.getVersion(); // ProtocolLib - remove build number
178178

179179
data.put("pluginName", pluginName); // Append the name of the plugin
180-
data.put("pluginVersion", pluginVersion.getLeft()); // Append the version of the plugin
180+
data.put("pluginVersion", pluginVersion); // Append the version of the plugin
181181
JSONArray customCharts = new JSONArray();
182182
for (CustomChart customChart : charts) {
183183
// Add the data of the custom charts

src/main/java/com/comphenix/protocol/metrics/Statistics.java

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
import com.comphenix.protocol.ProtocolLibrary;
2222
import com.comphenix.protocol.events.PacketAdapter;
2323
import com.comphenix.protocol.events.PacketListener;
24+
import com.comphenix.protocol.utility.Util;
25+
26+
import org.bukkit.Bukkit;
2427
import org.bukkit.craftbukkit.libs.org.apache.commons.lang3.tuple.Pair;
2528

2629
import java.io.IOException;
@@ -36,22 +39,45 @@ public Statistics(ProtocolLib plugin) throws IOException {
3639
metrics = new Metrics(plugin);
3740
metrics.logFailedRequests(plugin.getProtocolConfig().isDebug());
3841

39-
// Determine who is using this library
40-
addPluginUserGraph(metrics);
42+
addCustomGraphs(metrics);
43+
}
44+
45+
private void addCustomGraphs(Metrics metrics) {
46+
metrics.addCustomChart(new Metrics.AdvancedPie("pluginUsers", this::getPluginUsers));
47+
metrics.addCustomChart(new Metrics.SimplePie("buildVersion", this::getBuildNumber));
48+
metrics.addCustomChart(new Metrics.SimplePie("serverBrand", this::getServerBrand));
49+
}
50+
51+
private String getServerBrand() {
52+
// spigot doesn't overwrite the serverName, but paper does
53+
if (!Bukkit.getServer().getName().equals("CraftBukkit")) {
54+
return Bukkit.getServer().getName();
55+
} else if (Util.isUsingSpigot()) {
56+
return "Spigot";
57+
} else {
58+
return "CraftBukkit";
59+
}
4160
}
4261

43-
private void addPluginUserGraph(Metrics metrics) {
44-
metrics.addCustomChart(new Metrics.AdvancedPie("Plugin Users", this::getPluginUsers));
45-
metrics.addCustomChart(new Metrics.SimplePie("buildVersion", () -> splitVersion().getRight()));
62+
private String getBuildNumber() {
63+
String version = ProtocolLibrary.getPlugin().getDescription().getVersion();
64+
if (version.contains("-b")) {
65+
String[] split = version.split("-b");
66+
return split[1];
67+
} else if (!version.contains("SNAPSHOT")) {
68+
return "Release";
69+
} else {
70+
return "Unknown";
71+
}
4672
}
4773

48-
public static Pair<String, String> splitVersion() {
74+
public static String getVersion() {
4975
String version = ProtocolLibrary.getPlugin().getDescription().getVersion();
5076
if (version.contains("-b")) {
5177
String[] split = version.split("-b");
52-
return Pair.of(split[0], split[1]);
78+
return split[0];
5379
} else {
54-
return Pair.of(version, "Unknown");
80+
return version;
5581
}
5682
}
5783

0 commit comments

Comments
 (0)