mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-01-03 15:08:18 +01:00
Handle funky bStats classloading correctly
Fixes bStats for plugins that do funky classloading things, like AntiVPN.
This commit is contained in:
parent
76f36aa895
commit
dc6b9b89cd
@ -7,6 +7,7 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -93,9 +94,9 @@ public class MetricsWrapper {
|
|||||||
Map<String, int[]> result = new HashMap<>();
|
Map<String, int[]> result = new HashMap<>();
|
||||||
for (Map.Entry<String, Boolean> entry : commands.entrySet()) {
|
for (Map.Entry<String, Boolean> entry : commands.entrySet()) {
|
||||||
if (entry.getValue()) {
|
if (entry.getValue()) {
|
||||||
result.put(entry.getKey(), new int[]{1,0});
|
result.put(entry.getKey(), new int[]{1, 0});
|
||||||
} else {
|
} else {
|
||||||
result.put(entry.getKey(), new int[]{0,1});
|
result.put(entry.getKey(), new int[]{0, 1});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@ -111,7 +112,8 @@ public class MetricsWrapper {
|
|||||||
try {
|
try {
|
||||||
service.getField("B_STATS_VERSION"); // Identifies bStats classes
|
service.getField("B_STATS_VERSION"); // Identifies bStats classes
|
||||||
|
|
||||||
if (KNOWN_FORCED_METRICS.contains(JavaPlugin.getProvidingPlugin(service).getName())) {
|
JavaPlugin owningPlugin = getProvidingPlugin(service);
|
||||||
|
if (owningPlugin != null && KNOWN_FORCED_METRICS.contains(owningPlugin.getName())) {
|
||||||
warnForcedMetrics(service);
|
warnForcedMetrics(service);
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
@ -139,4 +141,21 @@ public class MetricsWrapper {
|
|||||||
plugin.getLogger().severe("This may cause data to be uploaded to bStats.org for plugins that use bStats, even if you've opted out in the bStats config.");
|
plugin.getLogger().severe("This may cause data to be uploaded to bStats.org for plugins that use bStats, even if you've opted out in the bStats config.");
|
||||||
plugin.getLogger().severe("Please report this to bStats and to the authors of '" + servicePlugin.getName() + "'. (Offending class: " + service.getName() + ")");
|
plugin.getLogger().severe("Please report this to bStats and to the authors of '" + servicePlugin.getName() + "'. (Offending class: " + service.getName() + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private JavaPlugin getProvidingPlugin(Class<?> clazz) {
|
||||||
|
try {
|
||||||
|
return JavaPlugin.getProvidingPlugin(clazz);
|
||||||
|
} catch (Exception ignored) {}
|
||||||
|
|
||||||
|
ClassLoader parent = clazz.getClassLoader().getParent();
|
||||||
|
if (parent.getClass().getName().equals("org.bukkit.plugin.java.PluginClassLoader")) {
|
||||||
|
try {
|
||||||
|
Field pluginField = parent.getClass().getDeclaredField("plugin");
|
||||||
|
pluginField.setAccessible(true);
|
||||||
|
return (JavaPlugin) pluginField.get(parent);
|
||||||
|
} catch (Exception ignored) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user