Skip to content

Commit

Permalink
ChatSigns - Added 'Illegal Disconnect' option to SignBoard AutoLog.
Browse files Browse the repository at this point in the history
  • Loading branch information
0xTas committed Oct 1, 2024
1 parent b37ecf6 commit 6d84e5c
Showing 1 changed file with 57 additions and 30 deletions.
87 changes: 57 additions & 30 deletions src/main/java/dev/stardust/modules/ChatSigns.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -76,18 +77,19 @@ 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> chatMode = modesGroup.add(
new EnumSetting.Builder<ChatMode>()
.name("Chat Mode")
.name("chat-mode")
.description("ESP = nearby only, Targeted = looking at only")
.defaultValue(ChatMode.Both)
.build()
);

private final Setting<RepeatMode> repeatMode = modesGroup.add(
new EnumSetting.Builder<RepeatMode>()
.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)
Expand All @@ -96,7 +98,7 @@ public enum RepeatMode {

private final Setting<Integer> 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)
Expand All @@ -107,7 +109,7 @@ public enum RepeatMode {

private final Setting<Integer> 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)
Expand All @@ -117,15 +119,15 @@ public enum RepeatMode {

private final Setting<Boolean> 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()
);

private final Setting<Boolean> 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)
Expand All @@ -134,7 +136,7 @@ public enum RepeatMode {

private final Setting<Boolean> 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)
Expand All @@ -143,31 +145,31 @@ public enum RepeatMode {

private final Setting<Boolean> 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()
);

private final Setting<TextColor> signColor = formatGroup.add(
new EnumSetting.Builder<TextColor>()
.name("Sign Color")
.name("sign-color")
.description("The color of displayed sign text.")
.defaultValue(TextColor.Light_Gray)
.build()
);

private final Setting<TextFormat> textFormat = formatGroup.add(
new EnumSetting.Builder<TextFormat>()
.name("Text Formatting")
.name("text-formatting")
.description("Apply formatting to displayed sign text.")
.defaultValue(TextFormat.Italic)
.build()
);

private final Setting<TextColor> oldSignColor = oldSignGroup.add(
new EnumSetting.Builder<TextColor>()
.name("Old Sign Color")
.name("old-sign-color")
.description("Text color for signs that might be old.")
.defaultValue(TextColor.Yellow)
.visible(showOldSigns::get)
Expand All @@ -176,36 +178,36 @@ public enum RepeatMode {

private final Setting<TextFormat> oldSignFormat = oldSignGroup.add(
new EnumSetting.Builder<TextFormat>()
.name("Old Text Format")
.name("old-text-format")
.description("Apply formatting to text displayed from (maybe) old signs.")
.defaultValue(TextFormat.Italic)
.visible(showOldSigns::get)
.build()
);

private final Setting<Boolean> 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<Boolean> showCoords = formatGroup.add(new BoolSetting.Builder()
.name("Show Coordinates")
.name("show-coordinates")
.description("Display sign coordinates in chat.")
.defaultValue(false)
.build()
);

private final Setting<Boolean> 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<ESPBlockData> espSettings = oldSignGroup.add(new GenericSetting.Builder<ESPBlockData>()
.name("ESP Settings")
.name("ESP-settings")
.defaultValue(
new ESPBlockData(
ShapeMode.Both,
Expand All @@ -219,7 +221,7 @@ public enum RepeatMode {
);

private final Setting<ESPBlockData> clickESPSettings = formatGroup.add(new GenericSetting.Builder<ESPBlockData>()
.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(
Expand All @@ -235,31 +237,39 @@ public enum RepeatMode {

private final Setting<Integer> 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<Boolean> signBoardAutoLog = settings.getDefaultGroup().add(
private final Setting<Boolean> 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<Integer> signBoardAutoLogAmount = settings.getDefaultGroup().add(
private final Setting<Boolean> 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<Integer> 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()
);

private final Setting<Boolean> 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 -> {
Expand All @@ -278,7 +288,7 @@ public enum RepeatMode {

private final Setting<Boolean> 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)
Expand All @@ -287,7 +297,7 @@ public enum RepeatMode {

private final Setting<Boolean> 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)
Expand All @@ -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<BlockPos> posSet = new HashSet<>();
private final HashSet<BlockPos> oldSet = new HashSet<>();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand Down

0 comments on commit 6d84e5c

Please sign in to comment.