Metrics improvements
Dieser Commit ist enthalten in:
Ursprung
d195fb6990
Commit
f9376432c4
@ -654,4 +654,8 @@ public class ProtocolLib extends JavaPlugin {
|
||||
public Statistics getStatistics() {
|
||||
return statistics;
|
||||
}
|
||||
|
||||
public ProtocolConfig getProtocolConfig() {
|
||||
return config;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.comphenix.protocol.metrics;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -128,6 +129,10 @@ public class Metrics {
|
||||
}
|
||||
}
|
||||
|
||||
void logFailedRequests(boolean value) {
|
||||
logFailedRequests = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a custom chart.
|
||||
*
|
||||
@ -177,10 +182,10 @@ public class Metrics {
|
||||
JSONObject data = new JSONObject();
|
||||
|
||||
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("pluginVersion", pluginVersion); // Append the version of the plugin
|
||||
data.put("pluginVersion", pluginVersion.getLeft()); // Append the version of the plugin
|
||||
JSONArray customCharts = new JSONArray();
|
||||
for (CustomChart customChart : charts) {
|
||||
// Add the data of the custom charts
|
||||
|
@ -20,44 +20,48 @@ package com.comphenix.protocol.metrics;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
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.ProtocolManager;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketListener;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class Statistics {
|
||||
|
||||
// Metrics
|
||||
private Metrics metrics;
|
||||
|
||||
public Statistics(Plugin plugin) throws IOException {
|
||||
public Statistics(ProtocolLib plugin) throws IOException {
|
||||
metrics = new Metrics(plugin);
|
||||
metrics.logFailedRequests(plugin.getProtocolConfig().isDebug());
|
||||
|
||||
// Determine who is using this library
|
||||
addPluginUserGraph(metrics);
|
||||
}
|
||||
|
||||
private void addPluginUserGraph(Metrics metrics) {
|
||||
|
||||
metrics.addCustomChart(new Metrics.AdvancedPie("Plugin Users", new Callable<Map<String, Integer>>() {
|
||||
@Override
|
||||
public Map<String, Integer> call() throws Exception {
|
||||
return getPluginUsers(ProtocolLibrary.getProtocolManager());
|
||||
metrics.addCustomChart(new Metrics.AdvancedPie("Plugin Users", this::getPluginUsers));
|
||||
metrics.addCustomChart(new Metrics.SimplePie("buildVersion", () -> splitVersion().getRight()));
|
||||
}
|
||||
|
||||
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
|
||||
private Map<String, Integer> getPluginUsers(ProtocolManager manager) {
|
||||
|
||||
Map<String, Integer> users = new HashMap<String, Integer>();
|
||||
|
||||
for (PacketListener listener : manager.getPacketListeners()) {
|
||||
private Map<String, Integer> getPluginUsers() {
|
||||
Map<String, Integer> users = new HashMap<>();
|
||||
|
||||
for (PacketListener listener : ProtocolLibrary.getProtocolManager().getPacketListeners()) {
|
||||
String name = PacketAdapter.getPluginName(listener);
|
||||
|
||||
// Increment occurence
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren