AntiSpam module

AntiSpam: Minecraft 26.3 cheat module, full source for every implementation (1 client: OfflineClient).

1 implementationMISC

Clients with this module

Full module source: 1 implementation

Every implementation below is the complete module file, verbatim. Expand a client to read its code.

OfflineClientMISCsrc/main/java/com/jellypudding/offlineclient/modules/misc/AntiSpam.javaJava · 68 lines · 2.5 KB

Stacks repeated chat lines into one.

SettingsDepth
AntiSpam.javaJava · Minecraft 26.2 · 68 lines · 2.5 KB · complete file, verbatimOriginal ↗
1
package com.jellypudding.offlineclient.modules.misc;
2
3
import com.jellypudding.offlineclient.module.Category;
4
import com.jellypudding.offlineclient.module.Module;
5
import com.jellypudding.offlineclient.setting.NumberSetting;
6
import net.minecraft.ChatFormatting;
7
import net.minecraft.client.gui.components.ChatComponent;
8
import net.minecraft.client.multiplayer.chat.GuiMessage;
9
import net.minecraft.network.chat.Component;
10
11
import java.util.List;
12
import java.util.regex.Matcher;
13
import java.util.regex.Pattern;
14
15
public final class AntiSpam extends Module {
16
17
    private static final Pattern COUNTER = Pattern.compile(" x(\\d{1,8})$");
18
19
    // A clock stamp on the front of a stored line. BetterChat adds one and some servers do too.
20
    private static final Pattern STAMP = Pattern.compile("^\\[\\d{2}:\\d{2}(?::\\d{2})?\\] ");
21
22
    private final NumberSetting depth = new NumberSetting("Depth",
23
        "How many recent lines are checked.", 4, 1, 20, 1).max(50);
24
25
    public AntiSpam() {
26
        super("AntiSpam", "Stacks repeated chat lines into one.", Category.MISC);
27
        addSettings(depth);
28
        searchTags("chat", "duplicate");
29
    }
30
31
    // A stored line may already carry a clock stamp. Compare the text without it.
32
    private static String body(String line) {
33
        return STAMP.matcher(line).replaceFirst("");
34
    }
35
36
    // Returns the line to add.
37
    public Component fold(ChatComponent chat, Component message) {
38
        if (!isEnabled()) {
39
            return message;
40
        }
41
        String incoming = body(message.getString());
42
        if (incoming.isBlank()) {
43
            return message;
44
        }
45
        List<GuiMessage> all = chat.allMessages;
46
        int max = Math.min(depth.getInt(), all.size());
47
        for (int i = 0; i < max; i++) {
48
            String existing = body(all.get(i).content().getString());
49
            int count = 0;
50
            if (existing.equals(incoming)) {
51
                count = 2;
52
            } else {
53
                Matcher matcher = COUNTER.matcher(existing);
54
                if (matcher.find() && existing.substring(0, matcher.start()).equals(incoming)) {
55
                    count = Integer.parseInt(matcher.group(1)) + 1;
56
                }
57
            }
58
            if (count > 0) {
59
                all.remove(i);
60
                chat.refreshTrimmedMessages();
61
                return message.copy()
62
                    .append(Component.literal(" x" + count).withStyle(ChatFormatting.GRAY));
63
            }
64
        }
65
        return message;
66
    }
67
}
68