diff --git a/betterstats-3-fabric-1.20.1/src/main/java/io/github/thecsdev/betterstats/client/gui/stats/panel/ActionBarPanel.java b/betterstats-3-fabric-1.20.1/src/main/java/io/github/thecsdev/betterstats/client/gui/stats/panel/ActionBarPanel.java index 2e3b2493..cf3856e8 100644 --- a/betterstats-3-fabric-1.20.1/src/main/java/io/github/thecsdev/betterstats/client/gui/stats/panel/ActionBarPanel.java +++ b/betterstats-3-fabric-1.20.1/src/main/java/io/github/thecsdev/betterstats/client/gui/stats/panel/ActionBarPanel.java @@ -1,9 +1,11 @@ package io.github.thecsdev.betterstats.client.gui.stats.panel; -import static io.github.thecsdev.betterstats.client.network.BetterStatsClientNetworkHandler.c2s_liveStats; -import static io.github.thecsdev.betterstats.client.network.BetterStatsClientNetworkHandler.serverHasBSS; import static io.github.thecsdev.betterstats.BetterStatsConfig.LEGAL_NET_CONSENT; import static io.github.thecsdev.betterstats.client.BetterStatsClient.MC_CLIENT; +import static io.github.thecsdev.betterstats.client.network.BetterStatsClientNetworkHandler.c2s_liveStats; +import static io.github.thecsdev.betterstats.client.network.BetterStatsClientNetworkHandler.serverHasBSS; +import static io.github.thecsdev.betterstats.network.BetterStatsNetworkHandler.TXT_CONSENT_WARNING; +import static io.github.thecsdev.betterstats.network.BetterStatsNetworkHandler.TXT_TOGGLE_TOOLTIP; import static io.github.thecsdev.tcdcommons.api.util.TextUtils.translatable; import java.awt.Rectangle; @@ -15,6 +17,8 @@ import io.github.thecsdev.tcdcommons.api.client.gui.util.UITexture; import io.github.thecsdev.tcdcommons.api.client.gui.widget.TButtonWidget; import io.github.thecsdev.tcdcommons.api.client.util.interfaces.IParentScreenProvider; +import it.unimi.dsi.fastutil.booleans.BooleanConsumer; +import net.minecraft.client.gui.screen.ConfirmScreen; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.tooltip.Tooltip; @@ -56,24 +60,30 @@ public ActionBarPanel(int x, int y, int width, ActionBarPanelProxy proxy) throws //bss network button final var btn_bssNet = new TButtonWidget(btn_options.getX() - 21, btn_options.getY(), 20, 20); - btn_bssNet.setTooltip(Tooltip.of(translatable("TODO - Tooltip"))); //FIXME - BSS NET tooltip + btn_bssNet.setTooltip(Tooltip.of(TXT_TOGGLE_TOOLTIP)); btn_bssNet.setIcon(LEGAL_NET_CONSENT ? new UITexture(BS_WIDGETS_TEXTURE, new Rectangle(20, 80, 20, 20)) : new UITexture(BS_WIDGETS_TEXTURE, new Rectangle(0, 80, 20, 20))); btn_bssNet.setOnClick(__ -> { - //FIXME - Implement BSS NET consent screen! - //if enabled, and turning off, do not do any more live updates - if(LEGAL_NET_CONSENT) c2s_liveStats(false); - - //toggle - LEGAL_NET_CONSENT = !LEGAL_NET_CONSENT; - - //if just turned on, send live updates preference packet - if(LEGAL_NET_CONSENT) c2s_liveStats(); + //if turning off, send a packet indicating no more live updates + if(LEGAL_NET_CONSENT) + { + c2s_liveStats(false); + LEGAL_NET_CONSENT = false; + refresh(); + return; + } - //finally, refresh the panel - refresh(); + //else if turning on, go through a consent screen + final var currentScreen = MC_CLIENT.currentScreen; + final BooleanConsumer confirmScreenCallback = (accepted) -> + { + LEGAL_NET_CONSENT = accepted; + MC_CLIENT.setScreen(currentScreen); + if(LEGAL_NET_CONSENT) c2s_liveStats(); + }; + MC_CLIENT.setScreen(new ConfirmScreen(confirmScreenCallback, TXT_TOGGLE_TOOLTIP, TXT_CONSENT_WARNING)); }); btn_bssNet.setEnabled(serverHasBSS() && !MC_CLIENT.isInSingleplayer()); addChild(btn_bssNet, false); diff --git a/betterstats-3-fabric-1.20.1/src/main/java/io/github/thecsdev/betterstats/client/network/BetterStatsClientNetworkHandler.java b/betterstats-3-fabric-1.20.1/src/main/java/io/github/thecsdev/betterstats/client/network/BetterStatsClientNetworkHandler.java index eea87c69..d1115dcd 100644 --- a/betterstats-3-fabric-1.20.1/src/main/java/io/github/thecsdev/betterstats/client/network/BetterStatsClientNetworkHandler.java +++ b/betterstats-3-fabric-1.20.1/src/main/java/io/github/thecsdev/betterstats/client/network/BetterStatsClientNetworkHandler.java @@ -35,6 +35,9 @@ public static void init() {} LOGGER.info("Clearing '" + BetterStatsClientNetworkHandler.class.getSimpleName() + "' flags."); serverHasBSS = false; LEGAL_NET_CONSENT = false; + + //also clear the HUD, as it now references an outdated stats-provider + BetterStatsHudScreen.getInstance().clearEntries(); }); //initialize network handlers diff --git a/betterstats-3-fabric-1.20.1/src/main/java/io/github/thecsdev/betterstats/network/BetterStatsNetworkHandler.java b/betterstats-3-fabric-1.20.1/src/main/java/io/github/thecsdev/betterstats/network/BetterStatsNetworkHandler.java index 4acdc9c4..b38d338d 100644 --- a/betterstats-3-fabric-1.20.1/src/main/java/io/github/thecsdev/betterstats/network/BetterStatsNetworkHandler.java +++ b/betterstats-3-fabric-1.20.1/src/main/java/io/github/thecsdev/betterstats/network/BetterStatsNetworkHandler.java @@ -1,5 +1,6 @@ package io.github.thecsdev.betterstats.network; +import static io.github.thecsdev.tcdcommons.api.util.TextUtils.translatable; import java.util.WeakHashMap; import org.jetbrains.annotations.ApiStatus.Internal; @@ -12,6 +13,7 @@ import net.minecraft.network.PacketByteBuf; import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket; import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.text.Text; import net.minecraft.util.Identifier; /** @@ -22,6 +24,9 @@ // ================================================== private BetterStatsNetworkHandler() {} // -------------------------------------------------- + public static final Text TXT_TOGGLE_TOOLTIP = translatable("betterstats.network.betterstatsnetworkhandler.toggle_tooltip"); + public static final Text TXT_CONSENT_WARNING = translatable("betterstats.network.betterstatsnetworkhandler.consent_warning"); + // public static final int NETWORK_VERSION = 1; // public static final Identifier S2C_I_HAVE_BSS; @@ -77,7 +82,7 @@ public static void s2c_liveStats(ServerPlayerEntity player) //obtain prefs if(player == null) return; final var prefs = PlayerPrefs.get(player); - if(prefs == null) return; //shouldn't happen at all, but just in case + if(prefs == null || !prefs.liveStats) return; //check last update time, and avoid packet spam final long currentTime = System.currentTimeMillis(); diff --git a/betterstats-3-fabric-1.20.1/src/main/resources/META-INF/jarjar/tcdcommons-3.0.0+fabric-1.20.1.jar b/betterstats-3-fabric-1.20.1/src/main/resources/META-INF/jarjar/tcdcommons-3.0.0+fabric-1.20.1.jar index 07b0403c..fd3918cc 100644 Binary files a/betterstats-3-fabric-1.20.1/src/main/resources/META-INF/jarjar/tcdcommons-3.0.0+fabric-1.20.1.jar and b/betterstats-3-fabric-1.20.1/src/main/resources/META-INF/jarjar/tcdcommons-3.0.0+fabric-1.20.1.jar differ diff --git a/betterstats-3-fabric-1.20.1/src/main/resources/assets/betterstats/lang/en_us.json b/betterstats-3-fabric-1.20.1/src/main/resources/assets/betterstats/lang/en_us.json index 82aea8c6..d35a9a85 100644 --- a/betterstats-3-fabric-1.20.1/src/main/resources/assets/betterstats/lang/en_us.json +++ b/betterstats-3-fabric-1.20.1/src/main/resources/assets/betterstats/lang/en_us.json @@ -43,5 +43,8 @@ "betterstats.client.gui.screen.hud.betterstatshudscreen": "Statistics hud", - "betterstats.client.gui.screen.hud.betterstatshudscreen.pin_stat": "Pin to HUD" + "betterstats.client.gui.screen.hud.betterstatshudscreen.pin_stat": "Pin to HUD", + + "betterstats.network.betterstatsnetworkhandler.toggle_tooltip": "Toggle 'betterstats' server connection", + "betterstats.network.betterstatsnetworkhandler.consent_warning": "IMPORTANT:\nBy enabling this feature, the server will find out that you are using a modified client with 'betterstats' installed. To protect your privacy, do not use this feature on servers that may not allow modified clients or this mod.\n\nEnabling this feature adds some extra features that are available when the mod is installed on the server as well." } \ No newline at end of file