Archiviert
13
0

Metrics improvements

Dieser Commit ist enthalten in:
Dan Mulloy 2017-10-08 16:02:10 -04:00
Ursprung d195fb6990
Commit f9376432c4
3 geänderte Dateien mit 39 neuen und 26 gelöschten Zeilen

Datei anzeigen

@ -654,4 +654,8 @@ public class ProtocolLib extends JavaPlugin {
public Statistics getStatistics() { public Statistics getStatistics() {
return statistics; return statistics;
} }
public ProtocolConfig getProtocolConfig() {
return config;
}
} }

Datei anzeigen

@ -1,5 +1,6 @@
package com.comphenix.protocol.metrics; package com.comphenix.protocol.metrics;
import org.apache.commons.lang3.tuple.Pair;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -128,6 +129,10 @@ public class Metrics {
} }
} }
void logFailedRequests(boolean value) {
logFailedRequests = value;
}
/** /**
* Adds a custom chart. * Adds a custom chart.
* *
@ -177,10 +182,10 @@ public class Metrics {
JSONObject data = new JSONObject(); JSONObject data = new JSONObject();
String pluginName = plugin.getDescription().getName(); String pluginName = plugin.getDescription().getName();
String pluginVersion = plugin.getDescription().getVersion(); Pair<String, String> pluginVersion = Statistics.splitVersion(); // ProtocolLib - remove build number
data.put("pluginName", pluginName); // Append the name of the plugin data.put("pluginName", pluginName); // Append the name of the plugin
data.put("pluginVersion", pluginVersion); // Append the version of the plugin data.put("pluginVersion", pluginVersion.getLeft()); // Append the version of the plugin
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

Datei anzeigen

@ -20,44 +20,48 @@ package com.comphenix.protocol.metrics;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.Callable;
import org.bukkit.plugin.Plugin;
import com.comphenix.protocol.ProtocolLib;
import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
import com.comphenix.protocol.events.PacketAdapter; import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketListener; import com.comphenix.protocol.events.PacketListener;
import org.apache.commons.lang3.tuple.Pair;
import org.bukkit.plugin.Plugin;
public class Statistics { public class Statistics {
// Metrics // Metrics
private Metrics metrics; private Metrics metrics;
public Statistics(Plugin plugin) throws IOException { public Statistics(ProtocolLib plugin) throws IOException {
metrics = new Metrics(plugin); metrics = new Metrics(plugin);
metrics.logFailedRequests(plugin.getProtocolConfig().isDebug());
// Determine who is using this library // Determine who is using this library
addPluginUserGraph(metrics); addPluginUserGraph(metrics);
} }
private void addPluginUserGraph(Metrics metrics) { private void addPluginUserGraph(Metrics metrics) {
metrics.addCustomChart(new Metrics.AdvancedPie("Plugin Users", this::getPluginUsers));
metrics.addCustomChart(new Metrics.AdvancedPie("Plugin Users", new Callable<Map<String, Integer>>() { metrics.addCustomChart(new Metrics.SimplePie("buildVersion", () -> splitVersion().getRight()));
@Override }
public Map<String, Integer> call() throws Exception {
return getPluginUsers(ProtocolLibrary.getProtocolManager()); public static Pair<String, String> splitVersion() {
String version = ProtocolLibrary.getPlugin().getDescription().getVersion();
if (version.contains("-b")) {
String[] split = version.split("-b");
return Pair.of(split[0], split[1]);
} else {
return Pair.of(version, "Unknown");
} }
}));
} }
// Retrieve loaded plugins // Retrieve loaded plugins
private Map<String, Integer> getPluginUsers(ProtocolManager manager) { private Map<String, Integer> getPluginUsers() {
Map<String, Integer> users = new HashMap<>();
Map<String, Integer> users = new HashMap<String, Integer>();
for (PacketListener listener : manager.getPacketListeners()) {
for (PacketListener listener : ProtocolLibrary.getProtocolManager().getPacketListeners()) {
String name = PacketAdapter.getPluginName(listener); String name = PacketAdapter.getPluginName(listener);
// Increment occurence // Increment occurence