diff --git a/src/main/java/dev/stardust/modules/ChatSigns.java b/src/main/java/dev/stardust/modules/ChatSigns.java index 06a7fe4..bfdde7a 100644 --- a/src/main/java/dev/stardust/modules/ChatSigns.java +++ b/src/main/java/dev/stardust/modules/ChatSigns.java @@ -41,6 +41,7 @@ import meteordevelopment.meteorclient.settings.*; import meteordevelopment.meteorclient.utils.Utils; import net.minecraft.block.entity.SignBlockEntity; +import dev.stardust.mixin.DisconnectS2CPacketAccessor; import net.minecraft.client.network.ClientPlayerEntity; import meteordevelopment.meteorclient.renderer.ShapeMode; import meteordevelopment.meteorclient.systems.modules.Module; @@ -76,10 +77,11 @@ public enum RepeatMode { private final SettingGroup formatGroup = settings.createGroup("Formatting", true); private final SettingGroup oldSignGroup = settings.createGroup("OldSigns Settings", true); private final SettingGroup blacklistGroup = settings.createGroup("SignText Blacklist", true); + private final SettingGroup autoLogGroup = settings.createGroup("SignBoard AutoLog", true); private final Setting chatMode = modesGroup.add( new EnumSetting.Builder() - .name("Chat Mode") + .name("chat-mode") .description("ESP = nearby only, Targeted = looking at only") .defaultValue(ChatMode.Both) .build() @@ -87,7 +89,7 @@ public enum RepeatMode { private final Setting repeatMode = modesGroup.add( new EnumSetting.Builder() - .name("Repeat Mode") + .name("repeat-mode") .description("How to handle repeating signs you're actively looking at.") .defaultValue(RepeatMode.Cooldown) .visible(() -> chatMode.get() != ChatMode.ESP) @@ -96,7 +98,7 @@ public enum RepeatMode { private final Setting repeatSeconds = modesGroup.add( new IntSetting.Builder() - .name("Repeat Cooldown") + .name("repeat-cooldown") .description("Value in seconds to wait before repeating looked-at signs.") .visible(() -> repeatMode.get() == RepeatMode.Cooldown && repeatMode.isVisible()) .range(1, 3600) @@ -107,7 +109,7 @@ public enum RepeatMode { private final Setting chatSpeed = modesGroup.add( new IntSetting.Builder() - .name("Chat Speed") + .name("chat-speed") .description("How many ticks to wait before printing the next encountered sign into chat.") .range(0, 500) .sliderRange(0, 100) @@ -117,7 +119,7 @@ public enum RepeatMode { private final Setting showOldSigns = oldSignGroup.add( new BoolSetting.Builder() - .name("Show Old Signs*") + .name("show-old-signs*") .description("*will show signs placed before 1.8, AND after 1.19. Use your best judgment to determine what's legit.") .defaultValue(false) .build() @@ -125,7 +127,7 @@ public enum RepeatMode { private final Setting onlyOldSigns = oldSignGroup.add( new BoolSetting.Builder() - .name("Only Show Old Signs") + .name("only-show-old-signs") .description("Only display text from signs that are either really old, or really new.") .defaultValue(false) .visible(showOldSigns::get) @@ -134,7 +136,7 @@ public enum RepeatMode { private final Setting ignoreNether = oldSignGroup.add( new BoolSetting.Builder() - .name("Ignore Nether") + .name("ignore -nether") .description("Ignore potentially-old signs in the nether (near highways they're all certainly new.)") .visible(showOldSigns::get) .defaultValue(true) @@ -143,7 +145,7 @@ public enum RepeatMode { private final Setting ignoreDuplicates = modesGroup.add( new BoolSetting.Builder() - .name("Ignore Duplicates") + .name("ignore-duplicates") .description("Ignore duplicate signs instead of displaying them with a counter.") .defaultValue(false) .build() @@ -151,7 +153,7 @@ public enum RepeatMode { private final Setting signColor = formatGroup.add( new EnumSetting.Builder() - .name("Sign Color") + .name("sign-color") .description("The color of displayed sign text.") .defaultValue(TextColor.Light_Gray) .build() @@ -159,7 +161,7 @@ public enum RepeatMode { private final Setting textFormat = formatGroup.add( new EnumSetting.Builder() - .name("Text Formatting") + .name("text-formatting") .description("Apply formatting to displayed sign text.") .defaultValue(TextFormat.Italic) .build() @@ -167,7 +169,7 @@ public enum RepeatMode { private final Setting oldSignColor = oldSignGroup.add( new EnumSetting.Builder() - .name("Old Sign Color") + .name("old-sign-color") .description("Text color for signs that might be old.") .defaultValue(TextColor.Yellow) .visible(showOldSigns::get) @@ -176,7 +178,7 @@ public enum RepeatMode { private final Setting oldSignFormat = oldSignGroup.add( new EnumSetting.Builder() - .name("Old Text Format") + .name("old-text-format") .description("Apply formatting to text displayed from (maybe) old signs.") .defaultValue(TextFormat.Italic) .visible(showOldSigns::get) @@ -184,28 +186,28 @@ public enum RepeatMode { ); private final Setting chatFormat = formatGroup.add(new BoolSetting.Builder() - .name("Fancy Display") + .name("fancy-display") .description("Displays each line of the sign on separate lines in chat.") .defaultValue(false) .build() ); private final Setting showCoords = formatGroup.add(new BoolSetting.Builder() - .name("Show Coordinates") + .name("show-coordinates") .description("Display sign coordinates in chat.") .defaultValue(false) .build() ); private final Setting renderOldSigns = oldSignGroup.add(new BoolSetting.Builder() - .name("OldSign ESP") + .name("oldSign-ESP") .description("Render signs which could be old through walls.") .defaultValue(false) .build() ); private final Setting espSettings = oldSignGroup.add(new GenericSetting.Builder() - .name("ESP Settings") + .name("ESP-settings") .defaultValue( new ESPBlockData( ShapeMode.Both, @@ -219,7 +221,7 @@ public enum RepeatMode { ); private final Setting clickESPSettings = formatGroup.add(new GenericSetting.Builder() - .name("ClickESP Settings") + .name("clickESP-settings") .description("Click on a chat entry to ESP the sign it belongs to. Click again or toggle the module to disable.") .defaultValue( new ESPBlockData( @@ -235,23 +237,31 @@ public enum RepeatMode { private final Setting clickESPTimeout = formatGroup.add( new IntSetting.Builder() - .name("ClickESP Timeout (Seconds)") + .name("clickESP-timeout-seconds") .description("Automatic timeout for active ClickESP entries. Set to 0 in order to disable timeout.") .range(0, 1200).sliderRange(0, 120).defaultValue(30) .build() ); - private final Setting signBoardAutoLog = settings.getDefaultGroup().add( + private final Setting signBoardAutoLog = autoLogGroup.add( new BoolSetting.Builder() - .name("SignBoard AutoLog") + .name("signBoard-autoLog") .description("Disconnect from the server when you render a cluster of signs.") .defaultValue(false) .build() ); - private final Setting signBoardAutoLogAmount = settings.getDefaultGroup().add( + private final Setting forceKick = autoLogGroup.add( + new BoolSetting.Builder() + .name("force-kick") + .description("Forces the server to kick you by sending an illegal packet.") + .defaultValue(false) + .build() + ); + + private final Setting signBoardAutoLogAmount = autoLogGroup.add( new IntSetting.Builder() - .name("SignBoard AutoLog Amount") + .name("signBoard-autoLog-amount") .description("The amount of signs to trigger a disconnect.") .range(1, 1200).sliderRange(1, 120).defaultValue(5) .build() @@ -259,7 +269,7 @@ public enum RepeatMode { private final Setting signBlacklist = blacklistGroup.add( new BoolSetting.Builder() - .name("SignText Blacklist") + .name("signText-blacklist") .description("Ignore signs that contain specific text (line-separated list in chatsigns-blacklist.txt)") .defaultValue(false) .onChanged(it -> { @@ -278,7 +288,7 @@ public enum RepeatMode { private final Setting caseSensitive = blacklistGroup.add( new BoolSetting.Builder() - .name("Case-sensitive Blacklist") + .name("case-sensitive-blacklist") .description("Force matches in the blacklist file to be case-sensitive.") .defaultValue(false) .visible(signBlacklist::get) @@ -287,7 +297,7 @@ public enum RepeatMode { private final Setting openBlacklistFile = blacklistGroup.add( new BoolSetting.Builder() - .name("Open Blacklist File") + .name("open-blacklist-file") .description("Open the chatsigns-blacklist.txt file.") .defaultValue(false) .visible(signBlacklist::get) @@ -303,6 +313,7 @@ public enum RepeatMode { private int timer = 0; private int chatTimer = 0; private int clusterAmount = 0; + @Nullable private Text disconnectReason = null; @Nullable private BlockPos lastFocusedSign = null; private final HashSet posSet = new HashSet<>(); private final HashSet oldSet = new HashSet<>(); @@ -640,6 +651,11 @@ private Vec3d getTracerOffset(BlockState state, BlockPos pos) { return new Vec3d(offsetX, offsetY, offsetZ); } + private void doForceKick(Text reason) { + disconnectReason = reason; + StardustUtil.illegalDisconnect(true, Stardust.illegalDisconnectMethodSetting.get()); + } + @Override public void onActivate() { if (mc.player == null || mc.world == null) return; @@ -679,12 +695,18 @@ public void onDeactivate() { chunkCache.clear(); blacklisted.clear(); signMessages.clear(); + lastFocusedSign = null; + disconnectReason = null; signsToHighlight.clear(); } @EventHandler private void onPacketReceived(PacketEvent.Receive event) { - if (!(event.packet instanceof PlayerRespawnS2CPacket)) return; + if (disconnectReason != null && event.packet instanceof DisconnectS2CPacket packet) { + ((DisconnectS2CPacketAccessor)(Object) packet).setReason(disconnectReason); + signBoardAutoLog.set(false); + return; + }else if (!(event.packet instanceof PlayerRespawnS2CPacket)) return; posSet.clear(); oldSet.clear(); chunkCache.clear(); @@ -705,10 +727,15 @@ private void onReceiveChunkData(ChunkDataEvent event) { @EventHandler private void onTick(TickEvent.Pre event) { if (signBoardAutoLog.get() && clusterAmount >= signBoardAutoLogAmount.get()) { - mc.getNetworkHandler().onDisconnect( - new DisconnectS2CPacket(Text.literal("§8[§a§oChatSigns§8] §7Disconnected you because you rendered a cluster of §a§o"+ clusterAmount + " §7signs§a!")) - ); - toggle(); + Text reason = Text.literal("§8[§a§oChatSigns§8] §7Disconnected you because you rendered a cluster of §a§o"+ clusterAmount + " §7signs§a!"); + if (forceKick.get()) { + doForceKick(reason); + } else { + signBoardAutoLog.set(false); + StardustUtil.disableAutoReconnect(); + mc.getNetworkHandler().onDisconnect(new DisconnectS2CPacket(reason)); + } + return; } if (chatMode.get() == ChatMode.ESP) return;