Remove Fabric bstats
This commit is contained in:
1 parent
5a8682dc26
commit
4a5543da2a
4 files changed
+8
-210
No files matched your search
@@ -27,7 +27,8 @@ public class FabricLoaderMod implements PreLaunchEntrypoint, ModInitializer {
|
||||
core.enable();
|
||||
ServerLifecycleEvents.SERVER_STOPPING.register((server) -> {
|
||||
core.scheduler.shutdown();
|
||||
core.statsManager.getMetrics().shutdown();
|
||||
// bstats removal
|
||||
// core.statsManager.getMetrics().shutdown();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,97 +0,0 @@
|
||||
package me.caseload.knockbacksync.stats.custom;
|
||||
|
||||
import org.yaml.snakeyaml.DumperOptions;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class BStatsConfig {
|
||||
private static final String HEADER = """
|
||||
# bStats (https://bStats.org) collects some basic information for plugin authors, like how
|
||||
# many people use their plugin and their total player count. It's recommended to keep bStats
|
||||
# enabled, but if you're not comfortable with this, you can turn this setting off. There is no
|
||||
# performance penalty associated with having metrics enabled, and data sent to bStats is fully
|
||||
# anonymous.
|
||||
""";
|
||||
|
||||
public static Config loadConfig() {
|
||||
File bStatsFolder = new File(FabricLoader.getInstance().getConfigDir().toString(), "bStats");
|
||||
File configFile = new File(bStatsFolder, "config.yml");
|
||||
|
||||
DumperOptions options = new DumperOptions();
|
||||
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
||||
options.setPrettyFlow(true);
|
||||
Yaml yaml = new Yaml(options);
|
||||
|
||||
Map<String, Object> data;
|
||||
Config config = new Config();
|
||||
|
||||
try {
|
||||
if (!configFile.exists()) {
|
||||
bStatsFolder.mkdirs();
|
||||
|
||||
// Create default config
|
||||
data = new LinkedHashMap<>();
|
||||
data.put("enabled", true);
|
||||
data.put("serverUuid", UUID.randomUUID().toString());
|
||||
data.put("logFailedRequests", false);
|
||||
data.put("logSentData", false);
|
||||
data.put("logResponseStatusText", false);
|
||||
|
||||
// Write config with header
|
||||
try (Writer writer = new OutputStreamWriter(new FileOutputStream(configFile), StandardCharsets.UTF_8)) {
|
||||
writer.write(HEADER);
|
||||
yaml.dump(data, writer);
|
||||
}
|
||||
} else {
|
||||
// Load existing config
|
||||
data = yaml.load(new FileInputStream(configFile));
|
||||
if (data == null) {
|
||||
data = new LinkedHashMap<>();
|
||||
}
|
||||
}
|
||||
|
||||
// Map the data to Config object
|
||||
config.enabled = getBoolean(data, "enabled", true);
|
||||
config.serverUuid = getString(data, "serverUuid", UUID.randomUUID().toString());
|
||||
config.logFailedRequests = getBoolean(data, "logFailedRequests", false);
|
||||
config.logSentData = getBoolean(data, "logSentData", false);
|
||||
config.logResponseStatusText = getBoolean(data, "logResponseStatusText", false);
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
// Fallback to default values
|
||||
config.enabled = true;
|
||||
config.serverUuid = UUID.randomUUID().toString();
|
||||
config.logFailedRequests = false;
|
||||
config.logSentData = false;
|
||||
config.logResponseStatusText = false;
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
private static boolean getBoolean(Map<String, Object> map, String key, boolean defaultValue) {
|
||||
Object value = map.get(key);
|
||||
return value instanceof Boolean ? (Boolean) value : defaultValue;
|
||||
}
|
||||
|
||||
private static String getString(Map<String, Object> map, String key, String defaultValue) {
|
||||
Object value = map.get(key);
|
||||
return value instanceof String ? (String) value : defaultValue;
|
||||
}
|
||||
|
||||
// Your existing Config class
|
||||
public static class Config {
|
||||
public boolean enabled = true;
|
||||
public String serverUuid;
|
||||
public boolean logFailedRequests = false;
|
||||
public boolean logSentData = false;
|
||||
public boolean logResponseStatusText = false;
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,11 @@ import me.caseload.knockbacksync.Base;
|
||||
|
||||
public class FabricStatsManager extends StatsManager {
|
||||
public FabricStatsManager() {
|
||||
super(new MetricsFabric(23568));
|
||||
super(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
// no op remove bstats
|
||||
}
|
||||
}
|
||||
@@ -1,111 +0,0 @@
|
||||
package me.caseload.knockbacksync.stats.custom;
|
||||
|
||||
/*
|
||||
* This Metrics class was auto-generated and can be copied into your project if you are
|
||||
* not using a build tool like Gradle or Maven for dependency management.
|
||||
*
|
||||
* IMPORTANT: You are not allowed to modify this class, except changing the package.
|
||||
*
|
||||
* Disallowed modifications include but are not limited to:
|
||||
* - Remove the option for users to opt-out
|
||||
* - Change the frequency for data submission
|
||||
* - Obfuscate the code (every obfuscator should allow you to make an exception for specific files)
|
||||
* - Reformat the code (if you use a linter, add an exception)
|
||||
*
|
||||
* Violations will result in a ban of your plugin and account from bStats.
|
||||
*/
|
||||
|
||||
import me.caseload.knockbacksync.FabricLoaderMod;
|
||||
import me.caseload.knockbacksync.Base;
|
||||
import me.caseload.knockbacksync.stats.CustomChart;
|
||||
import me.caseload.knockbacksync.stats.JsonObjectBuilder;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class MetricsFabric implements Metrics {
|
||||
|
||||
private final MetricsBase metricsBase;
|
||||
|
||||
/**
|
||||
* Creates a new Metrics instance.
|
||||
*
|
||||
* @param serviceId The id of the service. It can be found at <a
|
||||
* href="https://bstats.org/what-is-my-plugin-id">What is my plugin id?</a>
|
||||
*/
|
||||
public MetricsFabric(int serviceId) {
|
||||
// Get the config file
|
||||
BStatsConfig.Config config = BStatsConfig.loadConfig();
|
||||
|
||||
// Load the data
|
||||
boolean enabled = config.enabled;
|
||||
String serverUUID = config.serverUuid;
|
||||
boolean logErrors = config.logFailedRequests;
|
||||
boolean logSentData = config.logSentData;
|
||||
boolean logResponseStatusText = config.logResponseStatusText;
|
||||
|
||||
metricsBase =
|
||||
new // See https://github.com/Bastian/bstats-metrics/pull/126
|
||||
// See https://github.com/Bastian/bstats-metrics/pull/126
|
||||
// See https://github.com/Bastian/bstats-metrics/pull/126
|
||||
// See https://github.com/Bastian/bstats-metrics/pull/126
|
||||
// See https://github.com/Bastian/bstats-metrics/pull/126
|
||||
// See https://github.com/Bastian/bstats-metrics/pull/126
|
||||
// See https://github.com/Bastian/bstats-metrics/pull/126
|
||||
MetricsBase(
|
||||
"fabric",
|
||||
serverUUID,
|
||||
serviceId,
|
||||
enabled,
|
||||
this::appendPlatformData,
|
||||
this::appendServiceData,
|
||||
submitDataTask -> Base.INSTANCE.getScheduler().runTask(submitDataTask),
|
||||
() -> true,
|
||||
(message, error) -> Base.INSTANCE.getLogger().log(Level.WARNING, message, error),
|
||||
(message) -> Base.INSTANCE.getLogger().log(Level.INFO, message),
|
||||
logErrors,
|
||||
logSentData,
|
||||
logResponseStatusText,
|
||||
false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shuts down the underlying scheduler service.
|
||||
*/
|
||||
public void shutdown() {
|
||||
metricsBase.shutdown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a custom chart.
|
||||
*
|
||||
* @param chart The chart to add.
|
||||
*/
|
||||
public void addCustomChart(CustomChart chart) {
|
||||
metricsBase.addCustomChart(chart);
|
||||
}
|
||||
|
||||
private void appendPlatformData(JsonObjectBuilder builder) {
|
||||
builder.appendField("playerAmount", getPlayerAmount());
|
||||
builder.appendField("onlineMode", FabricLoaderMod.getServer().isOnlineMode() ? 0 : 1);
|
||||
builder.appendField("bukkitVersion", "Fabric " + FabricLoader.getInstance().getModContainer("fabricloader").get().getMetadata().getVersion().getFriendlyString() + " (MC: " + FabricLoaderMod.getServer().getVersion() + ")");
|
||||
builder.appendField("bukkitName", "Fabric");
|
||||
builder.appendField("javaVersion", System.getProperty("java.version"));
|
||||
builder.appendField("osName", System.getProperty("os.name"));
|
||||
builder.appendField("osArch", System.getProperty("os.arch"));
|
||||
builder.appendField("osVersion", System.getProperty("os.version"));
|
||||
builder.appendField("coreCount", Runtime.getRuntime().availableProcessors());
|
||||
}
|
||||
|
||||
private void appendServiceData(JsonObjectBuilder builder) {
|
||||
builder.appendField("pluginVersion", FabricLoader.getInstance().getModContainer("knockbacksync").get().getMetadata().getVersion().getFriendlyString());
|
||||
}
|
||||
|
||||
private int getPlayerAmount() {
|
||||
if (FabricLoaderMod.getServer().isRunning()) {
|
||||
return FabricLoaderMod.getServer().getCurrentPlayerCount();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user