Skip to content

Commit 5b57b4a

Browse files
authored
Feat: ChatTimestamp, CustomChat, FancyChat, FriendHighlight (#215)
1 parent 4c392e9 commit 5b57b4a

File tree

10 files changed

+277
-27
lines changed

10 files changed

+277
-27
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/config/groups/FormatterSettings.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,22 @@ import com.lambda.util.NamedEnum
2323

2424
class FormatterSettings(
2525
c: Configurable,
26-
baseGroup: NamedEnum,
26+
vararg baseGroup: NamedEnum,
2727
) : FormatterConfig, SettingGroup(c) {
28-
val localeEnum by c.setting("Locale", FormatterConfig.Locales.US, "The regional formatting used for numbers").group(baseGroup).index()
28+
val localeEnum by c.setting("Locale", FormatterConfig.Locales.US, "The regional formatting used for numbers").group(*baseGroup).index()
2929
override val locale get() = localeEnum.locale
3030

31-
val sep by c.setting("Separator", FormatterConfig.TupleSeparator.Comma, "Separator for string serialization of tuple data structures").group(baseGroup).index()
32-
val customSep by c.setting("Custom Separator", "") { sep == FormatterConfig.TupleSeparator.Custom }.group(baseGroup).index()
31+
val sep by c.setting("Separator", FormatterConfig.TupleSeparator.Comma, "Separator for string serialization of tuple data structures").group(*baseGroup).index()
32+
val customSep by c.setting("Custom Separator", "") { sep == FormatterConfig.TupleSeparator.Custom }.group(*baseGroup).index()
3333
override val separator get() = if (sep == FormatterConfig.TupleSeparator.Custom) customSep else sep.separator
3434

35-
val group by c.setting("Tuple Prefix", FormatterConfig.TupleGrouping.Parentheses).group(baseGroup).index()
35+
val group by c.setting("Tuple Prefix", FormatterConfig.TupleGrouping.Parentheses).group(*baseGroup).index()
3636
override val prefix get() = group.prefix
3737
override val postfix get() = group.postfix
3838

39-
val floatingPrecision by c.setting("Floating Precision", 3, 0..6, 1, "Precision for floating point numbers").group(baseGroup).index()
39+
val floatingPrecision by c.setting("Floating Precision", 3, 0..6, 1, "Precision for floating point numbers").group(*baseGroup).index()
4040
override val precision get() = floatingPrecision
4141

42-
val timeFormat by c.setting("Time Format", FormatterConfig.Time.IsoDateTime).group(baseGroup).index()
42+
val timeFormat by c.setting("Time Format", FormatterConfig.Time.IsoDateTime).group(*baseGroup).index()
4343
override val format get() = timeFormat.format
4444
}

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: 8 additions & 8 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
@@ -79,13 +79,13 @@ object AntiSpam : Module(
7979
}
8080

8181
init {
82-
listen<ChatEvent.Message> { event ->
82+
listen<ChatEvent.Receive> { event ->
8383
var raw = event.message.string
8484
val author = MessageParser.playerName(raw)
8585

8686
if (
87-
ignoreSystem && !MessageType.Both.matches(raw) && !MessageDirection.Both.matches(raw) ||
88-
ignoreDms && MessageDirection.Receive.matches(raw)
87+
ignoreSystem && !MessageType.Both.matches(raw) && !DirectMessage.Both.matches(raw) ||
88+
ignoreDms && DirectMessage.Receive.matches(raw)
8989
) return@listen
9090

9191
val slurMatches = slurs.takeIf { detectSlurs.enabled }.orEmpty().flatMap { it.findAll(raw).toList().reversed() }
@@ -102,8 +102,8 @@ object AntiSpam : Module(
102102
fun doMatch(replace: ReplaceConfig, matches: Sequence<MatchResult>) {
103103
if (
104104
cancelled ||
105-
filterSystem && !MessageType.Both.matches(raw) && !MessageDirection.Both.matches(raw) ||
106-
filterDms && MessageDirection.Receive.matches(raw) ||
105+
filterSystem && !MessageType.Both.matches(raw) && !DirectMessage.Both.matches(raw) ||
106+
filterDms && DirectMessage.Receive.matches(raw) ||
107107
filterFriends && author?.let { FriendManager.isFriend(it) } == true ||
108108
filterSelf && MessageType.Self.matches(raw)
109109
) return
@@ -127,9 +127,9 @@ object AntiSpam : Module(
127127
doMatch(detectColors, colorMatches)
128128

129129
if (cancelled) return@listen event.cancel()
130-
if (!hasMatches) return@listen
131130

132-
event.message = Text.of(if (fancyChats) raw.toAscii else raw)
131+
if (hasMatches)
132+
event.message = Text.of(if (fancyChats) raw.toAscii else raw)
133133
}
134134
}
135135

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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.config.applyEdits
21+
import com.lambda.config.groups.FormatterConfig
22+
import com.lambda.config.groups.FormatterSettings
23+
import com.lambda.event.events.ChatEvent
24+
import com.lambda.event.listener.SafeListener.Companion.listen
25+
import com.lambda.module.Module
26+
import com.lambda.module.tag.ModuleTag
27+
import com.lambda.util.Formatting.format
28+
import com.lambda.util.text.buildText
29+
import com.lambda.util.text.literal
30+
import com.lambda.util.text.styled
31+
import com.lambda.util.text.text
32+
import net.minecraft.util.Formatting
33+
import java.awt.Color
34+
import java.time.LocalDateTime
35+
import java.time.ZoneId
36+
import java.time.ZonedDateTime
37+
import java.time.temporal.ChronoUnit
38+
39+
object ChatTimestamp : Module(
40+
name = "ChatTimestamp",
41+
description = "Displays the time a message was sent next to it",
42+
tag = ModuleTag.CHAT,
43+
) {
44+
var color: Formatting by setting("Color", Formatting.GRAY)
45+
.onValueChange { from, to -> if (to.colorIndex !in 0..15) color = from }
46+
47+
val javaColor: Color get() = Color(color.colorValue!! and 16777215)
48+
49+
val formatter = FormatterSettings(this).apply { applyEdits { hide(::localeEnum, ::sep, ::customSep, ::group, ::floatingPrecision); editTyped(::timeFormat) { defaultValue(FormatterConfig.Time.IsoLocalTime) } } }
50+
51+
private val currentTime get() =
52+
ZonedDateTime.of(LocalDateTime.now(), ZoneId.systemDefault())
53+
.truncatedTo(ChronoUnit.SECONDS)
54+
55+
init {
56+
listen<ChatEvent.Receive> {
57+
it.message = buildText {
58+
text(it.message)
59+
literal(" ")
60+
styled(javaColor, italic = true) { literal(currentTime.format(formatter)) }
61+
}
62+
}
63+
}
64+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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.google.common.collect.Comparators.min
21+
import com.lambda.event.events.ChatEvent
22+
import com.lambda.event.listener.SafeListener.Companion.listen
23+
import com.lambda.module.Module
24+
import com.lambda.module.tag.ModuleTag
25+
import com.lambda.util.NamedEnum
26+
27+
object CustomChat : Module(
28+
name = "CustomChat",
29+
description = "Adds a custom ending to your message",
30+
tag = ModuleTag.CHAT,
31+
) {
32+
private val decoration by setting("Decoration", Decoration.Separator)
33+
private val text by setting("Text", Text.Lambda)
34+
35+
private val customText by setting("Custom Text", "") { text == Text.Custom }
36+
37+
init {
38+
listen<ChatEvent.Send> {
39+
val message = "${it.message} ${decoration.block(text.block())}"
40+
it.message = message.take(min(256, message.length))
41+
}
42+
}
43+
44+
enum class Decoration(val block: (String) -> String) {
45+
Separator({ "| $it" }),
46+
Classic({ "\u00ab $it \u00bb" }),
47+
None({ it })
48+
}
49+
50+
private enum class Text(override val displayName: String, val block: () -> String) : NamedEnum {
51+
Lambda("Lambda", { "ʟᴀᴍʙᴅᴀ" }),
52+
LambdaOnTop("Lambda On Top", { "ʟᴀᴍʙᴅᴀ ᴏɴ ᴛᴏᴘ" }),
53+
KamiBlue("Kami Blue", { "ᴋᴀᴍɪ ʙʟᴜᴇ" }),
54+
LambdaWebsite("Lambda Website", { "lambda-client.org" }),
55+
Custom("Custom", { customText })
56+
}
57+
}
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+
}

0 commit comments

Comments
 (0)