Metrics improvements
Dieser Commit ist enthalten in:
Ursprung
d195fb6990
Commit
f9376432c4
@ -654,4 +654,8 @@ public class ProtocolLib extends JavaPlugin {
|
|||||||
public Statistics getStatistics() {
|
public Statistics getStatistics() {
|
||||||
return statistics;
|
return statistics;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ProtocolConfig getProtocolConfig() {
|
||||||
|
return config;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
@ -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.SimplePie("buildVersion", () -> splitVersion().getRight()));
|
||||||
|
}
|
||||||
|
|
||||||
metrics.addCustomChart(new Metrics.AdvancedPie("Plugin Users", new Callable<Map<String, Integer>>() {
|
public static Pair<String, String> splitVersion() {
|
||||||
@Override
|
String version = ProtocolLibrary.getPlugin().getDescription().getVersion();
|
||||||
public Map<String, Integer> call() throws Exception {
|
if (version.contains("-b")) {
|
||||||
return getPluginUsers(ProtocolLibrary.getProtocolManager());
|
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
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren