From ff6d0bed06997503798eb8fd2964bd3e9ee637db Mon Sep 17 00:00:00 2001 From: theOptionalStever <238886338+theOptionalStever@users.noreply.github.com> Date: Tue, 7 Jul 2026 21:00:20 +0200 Subject: [PATCH] chore: remove original telemetry fix: spotless apply --- .../java/net/wurstclient/WurstClient.java | 11 - .../analytics/AnalyticsConfigFile.java | 94 ----- .../analytics/PlausibleAnalytics.java | 360 ------------------ .../net/wurstclient/hacks/AntiVoidHack.java | 8 +- .../options/WurstOptionsScreen.java | 6 - 5 files changed, 4 insertions(+), 475 deletions(-) delete mode 100644 src/main/java/net/wurstclient/analytics/AnalyticsConfigFile.java delete mode 100644 src/main/java/net/wurstclient/analytics/PlausibleAnalytics.java diff --git a/src/main/java/net/wurstclient/WurstClient.java b/src/main/java/net/wurstclient/WurstClient.java index 6beeab6b8c..a88ef56b71 100644 --- a/src/main/java/net/wurstclient/WurstClient.java +++ b/src/main/java/net/wurstclient/WurstClient.java @@ -17,7 +17,6 @@ import net.wurstclient.addons.AddonManager; import net.wurstclient.altmanager.AltManager; import net.wurstclient.altmanager.Encryption; -import net.wurstclient.analytics.PlausibleAnalytics; import net.wurstclient.clickgui.ClickGui; import net.wurstclient.command.CmdList; import net.wurstclient.command.CmdProcessor; @@ -65,7 +64,6 @@ public enum WurstClient public static final String VERSION = "7.54"; public static final String MC_VERSION = "26.2"; - private PlausibleAnalytics plausible; private EventManager eventManager; private AltManager altManager; private HackList hax; @@ -132,10 +130,6 @@ public void initialize() e.printStackTrace(); } - Path analyticsFile = wurstFolder.resolve("analytics.json"); - plausible = new PlausibleAnalytics(analyticsFile); - plausible.pageview("/"); - eventManager = new EventManager(this); playerRangeAlertManager = new PlayerRangeAlertManager(eventManager); serverObserver = new ServerObserver(MC); @@ -237,11 +231,6 @@ public String translate(String key, Object... args) return translator.translate(key, args); } - public PlausibleAnalytics getPlausible() - { - return plausible; - } - public EventManager getEventManager() { return eventManager; diff --git a/src/main/java/net/wurstclient/analytics/AnalyticsConfigFile.java b/src/main/java/net/wurstclient/analytics/AnalyticsConfigFile.java deleted file mode 100644 index 5cebb9eac0..0000000000 --- a/src/main/java/net/wurstclient/analytics/AnalyticsConfigFile.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 2014-2026 Wurst-Imperium and contributors. - * - * This source code is subject to the terms of the GNU General Public - * License, version 3. If a copy of the GPL was not distributed with this - * file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt - */ -package net.wurstclient.analytics; - -import java.io.IOException; -import java.nio.file.NoSuchFileException; -import java.nio.file.Path; - -import com.google.gson.JsonObject; - -import net.wurstclient.util.json.JsonException; -import net.wurstclient.util.json.JsonUtils; -import net.wurstclient.util.json.WsonObject; - -public final class AnalyticsConfigFile -{ - private final Path path; - private boolean disableSaving; - - public AnalyticsConfigFile(Path path) - { - this.path = path; - } - - public void load(PlausibleAnalytics plausible) - { - try - { - WsonObject wson = JsonUtils.parseFileToObject(path); - loadJson(wson, plausible); - - }catch(NoSuchFileException e) - { - // The file doesn't exist yet. No problem, we'll create it later. - - }catch(IOException | JsonException e) - { - System.out.println("Couldn't load " + path.getFileName()); - e.printStackTrace(); - } - - save(plausible); - } - - private void loadJson(WsonObject wson, PlausibleAnalytics plausible) - throws JsonException - { - try - { - disableSaving = true; - - // v1 was bugged, don't load it - if(!wson.has("version")) - return; - - plausible.setEnabled(wson.getBoolean("enabled")); - - }finally - { - disableSaving = false; - } - } - - public void save(PlausibleAnalytics plausible) - { - if(disableSaving) - return; - - JsonObject json = createJson(plausible); - - try - { - JsonUtils.toJson(json, path); - - }catch(IOException | JsonException e) - { - System.out.println("Couldn't save " + path.getFileName()); - e.printStackTrace(); - } - } - - private JsonObject createJson(PlausibleAnalytics plausible) - { - JsonObject json = new JsonObject(); - json.addProperty("version", 2); - json.addProperty("enabled", plausible.isEnabled()); - return json; - } -} diff --git a/src/main/java/net/wurstclient/analytics/PlausibleAnalytics.java b/src/main/java/net/wurstclient/analytics/PlausibleAnalytics.java deleted file mode 100644 index 0c69924720..0000000000 --- a/src/main/java/net/wurstclient/analytics/PlausibleAnalytics.java +++ /dev/null @@ -1,360 +0,0 @@ -/* - * Copyright (c) 2014-2026 Wurst-Imperium and contributors. - * - * This source code is subject to the terms of the GNU General Public - * License, version 3. If a copy of the GPL was not distributed with this - * file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt - */ -package net.wurstclient.analytics; - -import java.net.URI; -import java.net.http.HttpClient; -import java.net.http.HttpRequest; -import java.net.http.HttpResponse; -import java.nio.file.Path; -import java.time.Duration; -import java.util.Map; -import java.util.Optional; -import java.util.concurrent.LinkedBlockingQueue; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.gson.Gson; -import com.google.gson.JsonObject; - -import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLevelEvents; -import net.fabricmc.loader.api.FabricLoader; -import net.fabricmc.loader.api.ModContainer; -import net.fabricmc.loader.api.Version; -import net.fabricmc.loader.api.metadata.ModMetadata; -import net.minecraft.client.Minecraft; -import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.client.multiplayer.ServerData; -import net.minecraft.client.resources.language.LanguageManager; - -/** - * An implementation of the Plausible Events API for privacy-friendly - * analytics in Minecraft mods, without collecting any personal information. - * - *

- * See {@link https://plausible.io/docs/events-api} for technical details and - * {@link https://plausible.io/privacy-focused-web-analytics} for a - * non-technical overview of how Plausible works. - */ -public final class PlausibleAnalytics -{ - private static final Gson GSON = new Gson(); - private static final Logger LOGGER = LoggerFactory.getLogger("Plausible"); - - private static final String MOD_ID = "wurst"; - private static final URI API_ENDPOINT = - URI.create("https://plausible.wurstclient.net/api/event"); - - private final HttpClient httpClient = - HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(5)).build(); - private final LinkedBlockingQueue eventQueue = - new LinkedBlockingQueue<>(); - private final JsonObject sessionProps = new JsonObject(); - private final AnalyticsConfigFile configFile; - private boolean enabled = true; - - /** - * Creates a new PlausibleAnalytics instance and starts a background thread - * for sending events. - */ - public PlausibleAnalytics(Path configFile) - { - this.configFile = new AnalyticsConfigFile(configFile); - this.configFile.load(this); - - sessionProp("version", getVersion("wurst")); - sessionProp("short_version", getShortVersion("wurst")); - sessionProp("mc_version", getVersion("minecraft")); - sessionProp("fabric_api_version", getVersion("fabric-api")); - sessionProp("fabric_loader_version", getVersion("fabricloader")); - sessionProp("modmenu_version", getVersion("modmenu")); - sessionProp("sodium_version", getVersion("sodium")); - sessionProp("sinytra_connector_version", getVersion("connector")); - - Thread.ofPlatform().daemon().name("Plausible") - .start(this::runBackgroundLoop); - - ClientLevelEvents.AFTER_CLIENT_LEVEL_CHANGE - .register(this::onWorldChange); - } - - private String getVersion(String modId) - { - return FabricLoader.getInstance().getModContainer(modId) - .map(ModContainer::getMetadata).map(ModMetadata::getVersion) - .map(Version::toString).orElse(null); - } - - private String getShortVersion(String modId) - { - String version = getVersion(modId); - if(version != null && version.contains("-MC")) - return version.substring(0, version.indexOf("-MC")); - - return version; - } - - private void onWorldChange(Minecraft client, ClientLevel world) - { - sessionProp("language", getLanguage(client)); - sessionProp("game_type", getGameType(client)); - pageview("/in-game"); - } - - private String getLanguage(Minecraft client) - { - return Optional.ofNullable(client.getLanguageManager()) - .map(LanguageManager::getSelected).map(String::toLowerCase) - .orElse(null); - } - - private String getGameType(Minecraft client) - { - ServerData server = client.getCurrentServer(); - if(server == null) - return "singleplayer"; - if(server.isLan()) - return "lan"; - if(server.isRealm()) - return "realms"; - return "multiplayer"; - } - - public boolean isEnabled() - { - return enabled; - } - - public void setEnabled(boolean enabled) - { - this.enabled = enabled; - configFile.save(this); - } - - private boolean isDebugMode() - { - return FabricLoader.getInstance().isDevelopmentEnvironment() - || System.getProperty("fabric.client.gametest") != null; - } - - private void runBackgroundLoop() - { - while(!Thread.currentThread().isInterrupted()) - try - { - sendEvent(eventQueue.take()); - Thread.sleep(50); - - }catch(InterruptedException e) - { - Thread.currentThread().interrupt(); - break; - - }catch(Exception e) - { - LOGGER.error("Plausible error", e); - } - } - - private void sendEvent(PlausibleEvent event) - { - String body = createRequestBody(event); - if(isDebugMode()) - { - LOGGER.info("Event ({} props): {}", event.props().size(), body); - return; - } - - HttpRequest request = HttpRequest.newBuilder().uri(API_ENDPOINT) - .header("User-Agent", getUserAgent()) - .header("Content-Type", "application/json") - .POST(HttpRequest.BodyPublishers.ofString(body)) - .timeout(Duration.ofSeconds(5)).build(); - - httpClient.sendAsync(request, HttpResponse.BodyHandlers.discarding()) - .exceptionally(ex -> null); - } - - private String getUserAgent() - { - // Same as the "Operating System" entry in Minecraft crash reports. - return System.getProperty("os.name") + " (" - + System.getProperty("os.arch") + ") version " - + System.getProperty("os.version"); - } - - private String createRequestBody(PlausibleEvent event) - { - JsonObject body = new JsonObject(); - body.addProperty("name", event.name()); - body.addProperty("url", event.url()); - body.addProperty("domain", MOD_ID); - if(event.props() != null && !event.props().isEmpty()) - body.add("props", event.props()); - - return GSON.toJson(body); - } - - /** - * Sends a pageview event with the given path. - * - *

- * Any session properties set with {@link #sessionProp(String, String)} - * will also be included. - * - *

- * If Plausible is disabled at the time of this method call, no event will - * be sent. - */ - public void pageview(String path) - { - event("pageview", path, null); - } - - /** - * Sends a pageview event with the given path and properties. - * - *

- * Any session properties set with {@link #sessionProp(String, String)} - * will also be included. - * - *

- * The total number of properties is limited to 30. Any additional - * properties will be ignored. The length of each property name is limited - * to 300 characters and the length of each property value is limited to - * 2000 characters. Longer names and values will be truncated. - * - *

- * Properties MUST NOT contain any personal information. This includes - * usernames, emails, IP addresses and any persistent user IDs, even if - * they are randomly generated and/or hashed. - * - *

- * If Plausible is disabled at the time of this method call, no event will - * be sent. - */ - public void pageview(String path, Map props) - { - event("pageview", path, props); - } - - /** - * Sends an event with the given name and path. - * - *

- * Any session properties set with {@link #sessionProp(String, String)} - * will also be included. - * - *

- * If Plausible is disabled at the time of this method call, no event will - * be sent. - */ - public void event(String name, String path) - { - event(name, path, null); - } - - /** - * Sends an event with the given name, path and properties. - * - *

- * Any session properties set with {@link #sessionProp(String, String)} - * will also be included. - * - *

- * The total number of properties is limited to 30. Any additional - * properties will be ignored. The length of each property name is limited - * to 300 characters and the length of each property value is limited to - * 2000 characters. Longer names and values will be truncated. - * - *

- * Properties MUST NOT contain any personal information. This includes - * usernames, emails, IP addresses and any persistent user IDs, even if - * they are randomly generated and/or hashed. - * - *

- * If Plausible is disabled at the time of this method call, no event will - * be sent. - */ - public void event(String name, String path, Map props) - { - if(!isEnabled() || name == null || path == null) - return; - - String url = buildURL(path); - JsonObject jsonProps = buildJsonProps(props); - eventQueue.offer(new PlausibleEvent(name, url, jsonProps)); - } - - private String buildURL(String path) - { - String adjustedPath = path.startsWith("/") ? path : "/" + path; - return "mod://" + MOD_ID + adjustedPath; - } - - private JsonObject buildJsonProps(Map props) - { - JsonObject jsonProps = sessionProps.deepCopy(); - if(props == null || props.isEmpty()) - return jsonProps; - - for(Map.Entry entry : props.entrySet()) - { - String key = entry.getKey(); - if(isDebugMode() && key.length() > 300) - LOGGER.warn("Property key is too long ({} characters): {}", - key.length(), key); - - String value = entry.getValue(); - if(isDebugMode() && value.length() > 2000) - LOGGER.warn("Property value is too long ({} characters): {}", - value.length(), value); - - if(key != null && value != null) - jsonProps.addProperty(key, value); - } - - if(isDebugMode() && jsonProps.size() > 30) - LOGGER.warn("Too many properties ({})", jsonProps.size()); - - return jsonProps; - } - - /** - * Sets a session property, which will be included in all subsequent events. - * - *

- * The total number of properties is limited to 30. Any additional - * properties will be ignored. The length of each property name is limited - * to 300 characters and the length of each property value is limited to - * 2000 characters. Longer names and values will be truncated. - * - *

- * Properties MUST NOT contain any personal information. This includes - * usernames, emails, IP addresses and any persistent user IDs, even if - * they are randomly generated and/or hashed. - */ - public void sessionProp(String name, String value) - { - if(name != null && value != null) - sessionProps.addProperty(name, value); - } - - /** - * Removes a session property. - */ - public void removeSessionProp(String name) - { - if(name != null) - sessionProps.remove(name); - } - - private record PlausibleEvent(String name, String url, JsonObject props) - {} -} diff --git a/src/main/java/net/wurstclient/hacks/AntiVoidHack.java b/src/main/java/net/wurstclient/hacks/AntiVoidHack.java index 53d27e4eab..f9e9da3585 100644 --- a/src/main/java/net/wurstclient/hacks/AntiVoidHack.java +++ b/src/main/java/net/wurstclient/hacks/AntiVoidHack.java @@ -42,10 +42,10 @@ public final class AntiVoidHack extends Hack implements UpdateListener "Treat the Overworld, Nether and End as if they had a solid floor below you.", false); - private final SliderSetting overworldFalseFloorY = new SliderSetting( - "Overworld floor Y", - "Block Y for the fake Overworld floor. The walkable surface is one block above this.", - -68, -100, -64, 1, ValueDisplay.INTEGER); + private final SliderSetting overworldFalseFloorY = new SliderSetting( + "Overworld floor Y", + "Block Y for the fake Overworld floor. The walkable surface is one block above this.", + -68, -100, -64, 1, ValueDisplay.INTEGER); private final SliderSetting netherFalseFloorY = new SliderSetting( "Nether floor Y", diff --git a/src/main/java/net/wurstclient/options/WurstOptionsScreen.java b/src/main/java/net/wurstclient/options/WurstOptionsScreen.java index fe46eb04c6..7ba46a56c5 100644 --- a/src/main/java/net/wurstclient/options/WurstOptionsScreen.java +++ b/src/main/java/net/wurstclient/options/WurstOptionsScreen.java @@ -29,7 +29,6 @@ import net.wurstclient.altgui.TooManyHaxEditorScreen; import net.wurstclient.altmanager.LoginException; import net.wurstclient.altmanager.screens.AltManagerScreen; -import net.wurstclient.analytics.PlausibleAnalytics; import net.wurstclient.commands.FriendsCmd; import net.wurstclient.navigator.NavigatorMainScreen; import net.wurstclient.nicewurst.NiceWurstModule; @@ -153,7 +152,6 @@ private void addCoreSection() WurstClient wurst = WurstClient.INSTANCE; FriendsCmd friendsCmd = wurst.getCmds().friendsCmd; CheckboxSetting middleClickFriends = friendsCmd.getMiddleClickFriends(); - PlausibleAnalytics plausible = wurst.getPlausible(); WurstOptionsOtf options = wurst.getOtfs().wurstOptionsOtf; VanillaSpoofOtf vanillaSpoof = wurst.getOtfs().vanillaSpoofOtf; CheckboxSetting forceEnglish = @@ -184,10 +182,6 @@ private void addCoreSection() b -> middleClickFriends .setChecked(!middleClickFriends.isChecked())); - addButton(column, () -> "Count Users: " + onOff(plausible.isEnabled()), - "Anonymous usage analytics to help prioritize support and version compatibility.", - b -> plausible.setEnabled(!plausible.isEnabled())); - addButton(column, () -> "Hack Toggle Chat: " + onOff(hackToggleFeedback.isChecked()), "Show chat feedback when hacks are enabled or disabled.",