Skip to content

Commit

Permalink
Add option in MetricsBase to disable relocate check
Browse files Browse the repository at this point in the history
While being enabled in all of the "normal" Metrics classes, some server
implementations also use the MetricBase. When they ensure that it does
not share a class loader with their plugins, the relocate check is not
necessary.
  • Loading branch information
Bastian committed Jul 28, 2024
1 parent e8d3b1c commit 184ceb9
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 7 deletions.
9 changes: 7 additions & 2 deletions base/src/main/java/org/bstats/MetricsBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public class MetricsBase {
* logged.
* @param logResponseStatusText Whether or not the response status text
* should be logged.
* @param skipRelocateCheck Whether or not the relocate check should be
* skipped.
*/
public MetricsBase(
String platform,
Expand All @@ -94,7 +96,8 @@ public MetricsBase(
Consumer<String> infoLogger,
boolean logErrors,
boolean logSentData,
boolean logResponseStatusText) {
boolean logResponseStatusText,
boolean skipRelocateCheck) {
ScheduledThreadPoolExecutor scheduler = new ScheduledThreadPoolExecutor(1,
task -> {
Thread thread = new Thread(task, "bStats-Metrics");
Expand Down Expand Up @@ -122,7 +125,9 @@ public MetricsBase(
this.logSentData = logSentData;
this.logResponseStatusText = logResponseStatusText;

checkRelocation();
if (!skipRelocateCheck) {
checkRelocation();
}

if (enabled) { // WARNING: Removing the option to opt-out will get your plugin banned from
// bStats
Expand Down
2 changes: 1 addition & 1 deletion base/src/test/java/org/bstats/RelocateCheckTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void shouldRespectDisabledRelocateCheck() {
}

private MetricsBase createDummyMetricsBase() {
return new MetricsBase("", "", -1, false, null, null, null, null, null, null, true, true, true);
return new MetricsBase("", "", -1, false, null, null, null, null, null, null, true, true, true, false);
}

}
3 changes: 2 additions & 1 deletion bukkit/src/main/java/org/bstats/bukkit/Metrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ public Metrics(JavaPlugin plugin, int serviceId) {
(message) -> this.plugin.getLogger().log(Level.INFO, message),
logErrors,
logSentData,
logResponseStatusText
logResponseStatusText,
false
);
}

Expand Down
3 changes: 2 additions & 1 deletion bungeecord/src/main/java/org/bstats/bungeecord/Metrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public Metrics(Plugin plugin, int serviceId) {
(message) -> this.plugin.getLogger().log(Level.INFO, message),
logErrors,
logSentData,
logResponseStatusText
logResponseStatusText,
false
);
}

Expand Down
3 changes: 2 additions & 1 deletion sponge/src/main/java/org/bstats/sponge/Metrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ public void startup(ConstructPluginEvent event) {
logger::info,
logErrors,
logSentData,
logResponseStatusText
logResponseStatusText,
false
);

StringBuilder builder = new StringBuilder().append(System.lineSeparator());
Expand Down
3 changes: 2 additions & 1 deletion velocity/src/main/java/org/bstats/velocity/Metrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ private Metrics(Object plugin, ProxyServer server, Logger logger, Path dataDirec
logger::info,
config.isLogErrorsEnabled(),
config.isLogSentDataEnabled(),
config.isLogResponseStatusTextEnabled()
config.isLogResponseStatusTextEnabled(),
false
);

if (!config.didExistBefore()) {
Expand Down

0 comments on commit 184ceb9

Please sign in to comment.