This repository was archived by the owner on Dec 12, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 141
Expand file tree
/
Copy pathLoginMessage.kt
More file actions
86 lines (76 loc) · 3.18 KB
/
LoginMessage.kt
File metadata and controls
86 lines (76 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package com.lambda.client.module.modules.chat
import com.lambda.client.event.events.ConnectionEvent
import com.lambda.client.event.listener.listener
import com.lambda.client.manager.managers.NotificationManager
import com.lambda.client.module.Category
import com.lambda.client.module.Module
import com.lambda.client.util.FolderUtils
import com.lambda.client.util.MovementUtils.isMoving
import com.lambda.client.util.notifications.NotificationType
import com.lambda.client.util.text.MessageDetection
import com.lambda.client.util.text.MessageSendHelper
import com.lambda.client.util.text.MessageSendHelper.sendServerMessage
import com.lambda.client.util.threads.defaultScope
import com.lambda.client.util.threads.safeListener
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import net.minecraftforge.fml.common.gameevent.TickEvent
import java.io.File
import java.util.concurrent.CopyOnWriteArrayList
object LoginMessage : Module(
name = "LoginMessage",
description = "Sends a given message(s) to public chat on login",
category = Category.CHAT,
showOnArray = false,
modulePriority = 150
) {
private val sendAfterMoving by setting("Send After Moving", false, description = "Wait until you have moved after logging in")
private val file = File(FolderUtils.lambdaFolder + "loginmsg.txt")
private val loginMessages = CopyOnWriteArrayList<String>()
private var sent = false
private var moved = false
init {
onEnable {
if (file.exists()) {
defaultScope.launch(Dispatchers.IO) {
try {
file.forEachLine {
if (it.isNotBlank()) loginMessages.add(it.trim())
}
NotificationManager.registerNotification("$chatName Loaded ${loginMessages.size} login messages!")
} catch (e: Exception) {
NotificationManager.registerNotification("$chatName Failed loading login messages, $e",
NotificationType.ERROR)
disable()
}
}
} else {
file.createNewFile()
MessageSendHelper.sendErrorMessage("$chatName Login Messages file not found!" +
", please add them in the &7loginmsg.txt&f under the &7.minecraft/lambda&f directory.")
disable()
}
}
onDisable {
loginMessages.clear()
}
listener<ConnectionEvent.Disconnect> {
sent = false
moved = false
}
safeListener<TickEvent.ClientTickEvent> { event ->
if (event.phase != TickEvent.Phase.END) return@safeListener
if (!sent && (!sendAfterMoving || moved)) {
for (message in loginMessages) {
if (MessageDetection.Command.LAMBDA detect message) {
MessageSendHelper.sendLambdaCommand(message)
} else {
sendServerMessage(message)
}
}
sent = true
}
if (!moved) moved = player.isMoving
}
}
}