From 2ce5797d5ee46045261973ffd99e54e3cbc674d2 Mon Sep 17 00:00:00 2001 From: MD <1917406+mdcfe@users.noreply.github.com> Date: Thu, 26 Nov 2020 12:26:08 +0000 Subject: [PATCH] Update metrics warnings --- .../essentials/metrics/MetricsWrapper.java | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/metrics/MetricsWrapper.java b/Essentials/src/main/java/com/earth2me/essentials/metrics/MetricsWrapper.java index 2d601527c..2b8f8ea06 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/metrics/MetricsWrapper.java +++ b/Essentials/src/main/java/com/earth2me/essentials/metrics/MetricsWrapper.java @@ -14,7 +14,9 @@ import java.util.Map; public class MetricsWrapper { - private static final List KNOWN_FORCED_METRICS = ImmutableList.of("ChatControl"); + private static final List KNOWN_FORCED_METRICS = ImmutableList.of( + "ChatControl", + "catserver.server.Metrics"); private static boolean hasWarned = false; private final Essentials ess; private final Metrics metrics; @@ -93,15 +95,29 @@ public class MetricsWrapper { final Map result = new HashMap<>(); for (final Map.Entry entry : commands.entrySet()) { if (entry.getValue()) { - result.put(entry.getKey(), new int[] {1, 0}); + result.put(entry.getKey(), new int[]{1, 0}); } else { - result.put(entry.getKey(), new int[] {0, 1}); + result.put(entry.getKey(), new int[]{0, 1}); } } return result; })); } + private boolean isForcedMetricsClass(Class bStatsService) { + for (String identifier : KNOWN_FORCED_METRICS) { + if (bStatsService.getCanonicalName().contains(identifier)) { + return true; + } + } + + final JavaPlugin owningPlugin = getProvidingPlugin(bStatsService); + if (owningPlugin != null && KNOWN_FORCED_METRICS.contains(owningPlugin.getName())) { + return true; + } + return false; + } + private void checkForcedMetrics() { if (hasWarned) return; hasWarned = true; @@ -111,8 +127,7 @@ public class MetricsWrapper { try { service.getField("B_STATS_VERSION"); // Identifies bStats classes - final JavaPlugin owningPlugin = getProvidingPlugin(service); - if (owningPlugin != null && KNOWN_FORCED_METRICS.contains(owningPlugin.getName())) { + if (isForcedMetricsClass(service)) { warnForcedMetrics(service); } else { try { @@ -123,7 +138,7 @@ public class MetricsWrapper { } try { - service.getDeclaredField("enabled"); // In modified forced metrics classes, this will fail + service.getDeclaredField("enabled"); // In some modified forced metrics classes, this will fail } catch (final NoSuchFieldException e) { warnForcedMetrics(service); }