BleachDev / BleachHack

block game utility mod that makes you a cool kid
https://bleachhack.org
GNU General Public License v3.0
743 stars 134 forks source link

[Bug] BetterChat prefix not working, encryption does not work in /msg and /whisper #304

Closed SolsticeSpectrum closed 3 years ago

SolsticeSpectrum commented 3 years ago

Whenever I set prefix, it doesn't display it.

Also encryption only works when I type directly into public chat. When I type into pm/msg/whisper it does not work. It would be nice to encrypt PM messages because then admins can't understand what we are typing on non anarchy servers and we don't get kicked for spamming into public chat.

SolsticeSpectrum commented 3 years ago

Btw I don't understand why you remove prefix for /msg but you don't remove suffix for /msg

SolsticeSpectrum commented 3 years ago

I'm gonna be honest with you that I didn't quite understand your thinking why did you had those regexes for prefix but not suffix but this works. Also I had to put empty string there because else it was doubling the prefix.


    @BleachSubscribe
    public void onPacketSend(EventSendPacket event) {
        if (event.getPacket() instanceof ChatMessageC2SPacket) {
            String empty = "";
            String text = ((ChatMessageC2SPacket) event.getPacket()).getChatMessage();
            if (text.startsWith("/") || text.startsWith("!") || text.startsWith("/r") || text.startsWith("/reply") || text.startsWith("/msg") || text.startsWith("/tell") || text.startsWith("/w")) {
                return;
            }

            if (getSetting(0).asToggle().state) {
                text = fonts.get(getSetting(0).asToggle().getChild(0).asMode().mode).replace(text);
            }

            if (getSetting(1).asToggle().state) {
                text = prefix + text;
            }

            if (getSetting(2).asToggle().state) {
                text = text + suffix;
            }

            if (getSetting(5).asToggle().state) {
                String key = getRandomString(4);
                text = encrypt(text, key) + "\u00ff" + key;
            }

            if (!text.equals(((ChatMessageC2SPacket) event.getPacket()).getChatMessage())) {
                FabricReflect.writeField(event.getPacket(), empty + text, "field_12764", "chatMessage");
            }
        }
    }
SolsticeSpectrum commented 3 years ago

Oh that code also affects the encryption I see Well it is funky to be honest

SolsticeSpectrum commented 3 years ago

And I don't understand what it does anyway

BleachDev commented 3 years ago

The code is there so suffix/encryption works in messages Untitled

SolsticeSpectrum commented 3 years ago

Okay yeah I found my issue. The issue was that I used /pm instead of /msg and the code does not count with that

BleachDev commented 3 years ago

and i removed prefix form /msg so it doesn't screw up the command but i realized now i could just put it after the /msg instead of removing it

SolsticeSpectrum commented 3 years ago

Yeah that would be nice also put /pm there

SolsticeSpectrum commented 3 years ago

Btw having encryption enabled screws /register command

SolsticeSpectrum commented 3 years ago

The problem with the code is that it completely destroys prefix btw

BleachDev commented 3 years ago

Fixed both in https://github.com/BleachDrinker420/BleachHack/commit/07dc6b4ebe904a325399fe6e55219ccf8ee5d923