mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-01-05 23:08:23 +00:00
Update metrics warnings
This commit is contained in:
parent
c2617e5a1d
commit
2ce5797d5e
1 changed files with 21 additions and 6 deletions
|
@ -14,7 +14,9 @@ import java.util.Map;
|
||||||
|
|
||||||
public class MetricsWrapper {
|
public class MetricsWrapper {
|
||||||
|
|
||||||
private static final List<String> KNOWN_FORCED_METRICS = ImmutableList.of("ChatControl");
|
private static final List<String> KNOWN_FORCED_METRICS = ImmutableList.of(
|
||||||
|
"ChatControl",
|
||||||
|
"catserver.server.Metrics");
|
||||||
private static boolean hasWarned = false;
|
private static boolean hasWarned = false;
|
||||||
private final Essentials ess;
|
private final Essentials ess;
|
||||||
private final Metrics metrics;
|
private final Metrics metrics;
|
||||||
|
@ -93,15 +95,29 @@ public class MetricsWrapper {
|
||||||
final Map<String, int[]> result = new HashMap<>();
|
final Map<String, int[]> result = new HashMap<>();
|
||||||
for (final Map.Entry<String, Boolean> entry : commands.entrySet()) {
|
for (final 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;
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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() {
|
private void checkForcedMetrics() {
|
||||||
if (hasWarned) return;
|
if (hasWarned) return;
|
||||||
hasWarned = true;
|
hasWarned = true;
|
||||||
|
@ -111,8 +127,7 @@ public class MetricsWrapper {
|
||||||
try {
|
try {
|
||||||
service.getField("B_STATS_VERSION"); // Identifies bStats classes
|
service.getField("B_STATS_VERSION"); // Identifies bStats classes
|
||||||
|
|
||||||
final JavaPlugin owningPlugin = getProvidingPlugin(service);
|
if (isForcedMetricsClass(service)) {
|
||||||
if (owningPlugin != null && KNOWN_FORCED_METRICS.contains(owningPlugin.getName())) {
|
|
||||||
warnForcedMetrics(service);
|
warnForcedMetrics(service);
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
|
@ -123,7 +138,7 @@ public class MetricsWrapper {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
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) {
|
} catch (final NoSuchFieldException e) {
|
||||||
warnForcedMetrics(service);
|
warnForcedMetrics(service);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue