Skip to content

Commit 03b4c70

Browse files
committed
Added betterchat
1 parent 5a5f59c commit 03b4c70

File tree

8 files changed

+166
-16
lines changed

8 files changed

+166
-16
lines changed

src/main/java/com/lambda/mixin/network/ClientPlayNetworkHandlerMixin.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package com.lambda.mixin.network;
1919

2020
import com.lambda.event.EventFlow;
21+
import com.lambda.event.events.ChatEvent;
2122
import com.lambda.event.events.InventoryEvent;
2223
import com.lambda.event.events.WorldEvent;
2324
import com.lambda.interaction.managers.inventory.InventoryManager;
@@ -118,4 +119,12 @@ private void wrapOnScreenHandlerSlotUpdate(ScreenHandlerSlotUpdateS2CPacket pack
118119
private void wrapOnInventory(InventoryS2CPacket packet, Operation<Void> original) {
119120
InventoryManager.onInventoryUpdate(packet, original);
120121
}
122+
123+
@WrapMethod(method = "sendChatMessage(Ljava/lang/String;)V")
124+
void onSendMessage(String content, Operation<Void> original) {
125+
var event = new ChatEvent.Send(content);
126+
127+
if (!EventFlow.post(event).isCanceled())
128+
original.call(event.getMessage());
129+
}
121130
}

src/main/java/com/lambda/mixin/render/ChatHudMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class ChatHudMixin {
4444

4545
@WrapMethod(method = "addMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignatureData;Lnet/minecraft/client/gui/hud/MessageIndicator;)V")
4646
void wrapAddMessage(Text message, MessageSignatureData signatureData, MessageIndicator indicator, Operation<Void> original) {
47-
var event = new ChatEvent.Message(message, signatureData, indicator);
47+
var event = new ChatEvent.Receive(message, signatureData, indicator);
4848

4949
if (!EventFlow.post(event).isCanceled())
5050
original.call(event.getMessage(), event.getSignature(), event.getIndicator());

src/main/kotlin/com/lambda/event/events/ChatEvent.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ import net.minecraft.network.message.MessageSignatureData
2424
import net.minecraft.text.Text
2525

2626
sealed class ChatEvent {
27-
class Message(
27+
class Send(var message: String) : Event, Cancellable()
28+
29+
class Receive(
2830
var message: Text,
2931
var signature: MessageSignatureData?,
3032
var indicator: MessageIndicator?,

src/main/kotlin/com/lambda/module/modules/chat/AntiSpam.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import com.lambda.util.ChatUtils.slurs
3535
import com.lambda.util.ChatUtils.swears
3636
import com.lambda.util.ChatUtils.toAscii
3737
import com.lambda.util.NamedEnum
38-
import com.lambda.util.text.MessageDirection
38+
import com.lambda.util.text.DirectMessage
3939
import com.lambda.util.text.MessageParser
4040
import com.lambda.util.text.MessageType
4141
import net.minecraft.text.Text
@@ -75,13 +75,13 @@ object AntiSpam : Module(
7575
}
7676

7777
init {
78-
listen<ChatEvent.Message> { event ->
78+
listen<ChatEvent.Receive> { event ->
7979
var raw = event.message.string
8080
val author = MessageParser.playerName(raw)
8181

8282
if (
83-
ignoreSystem && !MessageType.Both.matches(raw) && !MessageDirection.Both.matches(raw) ||
84-
ignoreDms && MessageDirection.Receive.matches(raw) ||
83+
ignoreSystem && !MessageType.Both.matches(raw) && !DirectMessage.Both.matches(raw) ||
84+
ignoreDms && DirectMessage.Receive.matches(raw) ||
8585
ignoreFriends && author?.let { FriendManager.isFriend(it) } == true ||
8686
ignoreSelf && MessageType.Self.matches(raw)
8787
) return@listen
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2025 Lambda
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.lambda.module.modules.chat
19+
20+
import com.lambda.event.events.ChatEvent
21+
import com.lambda.event.listener.SafeListener.Companion.listen
22+
import com.lambda.module.Module
23+
import com.lambda.module.tag.ModuleTag
24+
import com.lambda.util.ChatUtils.toBlue
25+
import com.lambda.util.ChatUtils.toGreen
26+
import com.lambda.util.ChatUtils.toLeet
27+
import com.lambda.util.ChatUtils.toUwu
28+
29+
object FancyChat : Module(
30+
name = "FancyChat",
31+
description = "Makes messages you send - fancy",
32+
tag = ModuleTag.CHAT,
33+
) {
34+
private val uwu by setting("uwu", true)
35+
private val leet by setting("1337", false)
36+
private val green by setting(">", false)
37+
private val blue by setting("`", false)
38+
39+
init {
40+
listen<ChatEvent.Send> {
41+
if (uwu) it.message = it.message.toUwu
42+
if (leet) it.message = it.message.toLeet
43+
if (green) it.message = it.message.toGreen
44+
if (blue) it.message = it.message.toBlue
45+
}
46+
}
47+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright 2025 Lambda
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.lambda.module.modules.chat
19+
20+
import com.lambda.event.events.ChatEvent
21+
import com.lambda.event.listener.SafeListener.Companion.listen
22+
import com.lambda.friend.FriendManager
23+
import com.lambda.module.Module
24+
import com.lambda.module.tag.ModuleTag
25+
import com.lambda.sound.SoundManager.playSound
26+
import com.lambda.util.Communication.logError
27+
import com.lambda.util.text.MessageType
28+
import com.lambda.util.text.buildText
29+
import com.lambda.util.text.literal
30+
import com.lambda.util.text.styled
31+
import net.minecraft.sound.SoundEvents
32+
import net.minecraft.util.Formatting
33+
import java.awt.Color
34+
35+
object FriendHighlight : Module(
36+
name = "FriendHighlight",
37+
description = "Highlights your friends names in chat",
38+
tag = ModuleTag.CHAT,
39+
) {
40+
var color: Formatting by setting("Color", Formatting.GREEN)
41+
.onValueChange { from, to -> if (to.colorIndex !in 0..15) color = from }
42+
43+
val javaColor: Color get() = Color(color.colorValue!! and 16777215)
44+
45+
val bold by setting("Bold", true)
46+
val italic by setting("Italic", false)
47+
val underlined by setting("Underlined", false)
48+
val strikethrough by setting("Strikethrough", false)
49+
50+
val ping by setting("Ping On Message", true)
51+
52+
init {
53+
onEnable {
54+
if (FriendManager.friends.isEmpty())
55+
logError("You don't have any friends added, silly! Go add some friends before using the module")
56+
}
57+
58+
listen<ChatEvent.Receive> {
59+
val raw = it.message.string
60+
val author = MessageType.Others.playerName(raw) ?: return@listen
61+
val content = MessageType.Others.removedOrNull(raw) ?: return@listen
62+
63+
if (!FriendManager.isFriend(author)) return@listen
64+
65+
if (ping) playSound(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP)
66+
67+
it.message = buildText {
68+
literal("<")
69+
styled(javaColor, bold, italic, underlined, strikethrough) { literal(author) }
70+
literal(">")
71+
72+
literal(content.toString())
73+
}
74+
}
75+
}
76+
}

src/main/kotlin/com/lambda/util/ChatUtils.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,27 @@ object ChatUtils {
2727
val colors = sequenceOf(">", "`").map { Regex(it) }
2828

2929
val fancyToAscii = mapOf('' to 'a', 'ʙ' to 'b', 'c' to 'c', '' to 'd', '' to 'e', '' to 'f', 'ɢ' to 'g', 'ʜ' to 'h', 'ɪ' to 'i', '' to 'j', '' to 'k', 'ʟ' to 'l', '' to 'm', 'ɴ' to 'n', '' to 'o', '' to 'p', 'q' to 'q', 'ʀ' to 'r', '' to 's', '' to 't', '' to 'u', '' to 'v', '' to 'w', 'x' to 'x', 'y' to 'y', '' to 'z',)
30+
val asciiToFancy = fancyToAscii.entries.associate { (key, value) -> value to key }
31+
val asciiToLeet = mapOf('a' to '4', 'e' to '3', 'g' to '6', 'l' to '1', 'i' to '1', 'o' to '0', 's' to '$', 't' to '7')
3032

33+
val String.toFancy get() = buildString { this@toFancy.forEach { append(asciiToFancy.getOrDefault(it, it)) } }
3134
val String.toAscii get() = buildString { this@toAscii.forEach { append(fancyToAscii.getOrDefault(it, it)) } }
35+
val String.toLeet get() = buildString { this@toLeet.forEach { append(asciiToLeet.getOrDefault(it, it)) } }
36+
val String.toGreen get() = ">$this"
37+
val String.toBlue get() = "`$this"
38+
39+
val String.toUwu get() =
40+
replace("my", "mai")
41+
.replace("friend", "fwend")
42+
.replace("small", "smol")
43+
.replace("cute", "cyute")
44+
.replace("very", "vewy")
45+
.replace("ove", "uv")
46+
.replace("no", "nu")
47+
.replace("you", "yew")
48+
.replace("the", "da")
49+
.replace("is", "ish")
50+
.replace('r', 'w')
51+
.replace("ve", "v")
52+
.replace('l', 'w')
3253
}

src/main/kotlin/com/lambda/util/text/Detections.kt

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@
1717

1818
package com.lambda.util.text
1919

20-
import baritone.api.BaritoneAPI
2120
import com.lambda.Lambda.mc
22-
import com.lambda.command.CommandRegistry
23-
import com.lambda.command.commands.PrefixCommand
24-
import kotlin.math.max
25-
import kotlin.text.substring
2621

2722
val playerRegex = "^<(.+)>".toRegex()
2823

@@ -72,28 +67,28 @@ enum class MessageType : Detector, PlayerDetector, RemovableDetector {
7267
override fun matches(input: CharSequence) = playerName(input) != null
7368

7469
override fun playerName(input: CharSequence) =
75-
playerRegex.find(input)?.groupValues?.getOrNull(1)?.takeIf { it.isNotBlank() && it != name }?.drop(1)?.dropLast(1)
70+
playerRegex.find(input)?.groupValues?.getOrNull(1)?.takeIf { it.isNotBlank() && it != name }
7671
},
7772
Both {
7873
override fun matches(input: CharSequence) = input.contains(playerRegex)
7974

8075
override fun playerName(input: CharSequence) =
81-
playerRegex.find(input)?.groupValues?.getOrNull(1)?.takeIf { it.isNotBlank() }?.drop(1)?.dropLast(1)
76+
playerRegex.find(input)?.groupValues?.getOrNull(1)?.takeIf { it.isNotBlank() }
8277
};
8378

8479
override fun removedOrNull(input: CharSequence) =
8580
playerName(input)?.let { input.removePrefix("<$it>") }
8681
}
8782

88-
enum class MessageDirection(override vararg val regexes: Regex) : RegexDetector, PlayerDetector {
89-
Sent("^To (.+?): ".toRegex(RegexOption.IGNORE_CASE)),
83+
enum class DirectMessage(override vararg val regexes: Regex) : RegexDetector, PlayerDetector {
84+
Send("^To (.+?): ".toRegex(RegexOption.IGNORE_CASE)),
9085
Receive(
9186
"^(.+?) whispers( to you)?: ".toRegex(),
9287
"^\\[?(.+?)( )?->( )?.+?]?( )?:? ".toRegex(),
9388
"^From (.+?): ".toRegex(RegexOption.IGNORE_CASE),
9489
"^. (.+?) » .w+? » ".toRegex()
9590
),
96-
Both(*Sent.regexes, *Receive.regexes);
91+
Both(*Send.regexes, *Receive.regexes);
9792

9893
override fun playerName(input: CharSequence) =
9994
result(input)?.find(input)?.groupValues?.getOrNull(1)?.takeIf { it.isNotBlank() }

0 commit comments

Comments
 (0)