Skip to content

Commit 7312d3c

Browse files
Added AutoExcuse external file mode and more excuses (#409)
* Make AutoExcuse external only * Changed var name in AutoExcuse.kt * In-Order option for AutoExcuse * Remove unused import * Brought back default excuses :) * More excuses Co-authored-by: Constructor <[email protected]>
1 parent 889a6ed commit 7312d3c

File tree

1 file changed

+69
-29
lines changed
  • src/main/kotlin/com/lambda/client/module/modules/chat

1 file changed

+69
-29
lines changed
Lines changed: 69 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.lambda.client.module.modules.chat
22

33
import com.lambda.client.LambdaMod
4+
import com.lambda.client.commons.extension.synchronized
45
import com.lambda.client.event.SafeClientEvent
56
import com.lambda.client.event.events.PacketEvent
67
import com.lambda.client.module.Category
@@ -10,27 +11,43 @@ import com.lambda.client.util.TickTimer
1011
import com.lambda.client.util.TimeUnit
1112
import com.lambda.client.util.text.MessageSendHelper
1213
import com.lambda.client.util.text.MessageSendHelper.sendServerMessage
14+
import com.lambda.client.util.threads.defaultScope
1315
import com.lambda.client.util.threads.safeListener
16+
import kotlinx.coroutines.Dispatchers
17+
import kotlinx.coroutines.launch
1418
import net.minecraft.init.Items
1519
import net.minecraft.network.play.server.SPacketUpdateHealth
1620
import net.minecraft.util.EnumHand
1721
import java.io.File
22+
import kotlin.random.Random
1823

1924
object AutoExcuse : Module(
2025
name = "AutoExcuse",
2126
description = "Makes an excuse for you when you die",
2227
category = Category.CHAT,
2328
modulePriority = 500
2429
) {
25-
private val mode by setting("Mode", Mode.INTERNAL)
30+
private val modeSetting by setting("Order", Mode.RANDOM_ORDER)
31+
private val modeSource by setting("Source", SourceMode.INTERNAL)
32+
33+
private val file = File(FolderUtils.lambdaFolder + "excuses.txt")
34+
private val loadedExcuses = ArrayList<String>().synchronized()
35+
private var currentLine = 0
36+
37+
private val timer = TickTimer(TimeUnit.SECONDS)
2638

2739
private enum class Mode {
40+
IN_ORDER, RANDOM_ORDER
41+
}
42+
43+
private enum class SourceMode {
2844
INTERNAL, EXTERNAL
2945
}
3046

3147
private const val CLIENT_NAME = "%CLIENT%"
48+
3249
private val defaultExcuses = arrayOf(
33-
"Sorry, im using $CLIENT_NAME client",
50+
"Sorry, im using $CLIENT_NAME",
3451
"My ping is so bad",
3552
"I was changing my config :(",
3653
"Why did my AutoTotem break",
@@ -39,10 +56,10 @@ object AutoExcuse : Module(
3956
"Wow, so many try hards",
4057
"Lagggg",
4158
"I wasn't trying",
42-
"I'm not using $CLIENT_NAME client",
59+
"I'm not using $CLIENT_NAME",
4360
"Thers to much lag",
4461
"My dog ate my pc",
45-
"Sorry, $CLIENT_NAME Client is really bad",
62+
"Sorry, $CLIENT_NAME is really bad",
4663
"I was lagging",
4764
"He was cheating!",
4865
"Your hacking!",
@@ -52,54 +69,77 @@ object AutoExcuse : Module(
5269
"My wifi went down",
5370
"I'm playing vanila",
5471
"My optifine didn't work",
55-
"The CPU cheated!"
72+
"The CPU cheated!",
73+
"I am using a cracked client",
74+
"My brother was playing.",
75+
"Phobos hacked my pc!!",
76+
"I didn't have enough totems",
77+
"I died for you <3",
78+
"I was trying the popbob exploit!!",
79+
"Sorry, let me relog with ${LambdaMod.NAME}",
80+
"I was alt tabbing",
81+
"I was trying out a new mod",
5682
)
5783

58-
private val file = File(FolderUtils.lambdaFolder + "excuses.txt")
59-
private var loadedExcuses = defaultExcuses
60-
6184
private val clients = arrayOf(
62-
"Future",
85+
"Future Client",
6386
"Salhack",
6487
"Pyro",
6588
"Impact"
6689
)
6790

68-
private val timer = TickTimer(TimeUnit.SECONDS)
69-
7091
init {
7192
safeListener<PacketEvent.Receive> {
7293
if (loadedExcuses.isEmpty() || it.packet !is SPacketUpdateHealth) return@safeListener
7394
if (it.packet.health <= 0.0f && !isHoldingTotem && timer.tick(3L)) {
74-
sendServerMessage(getExcuse())
95+
val message = if (modeSetting == Mode.IN_ORDER) getOrdered() else getRandom()
96+
sendServerMessage(message.replace("%CLIENT%", clients.random()))
7597
}
7698
}
7799

78100
onEnable {
79-
loadedExcuses = if (mode == Mode.EXTERNAL) {
80-
if (file.exists()) {
81-
val cacheList = ArrayList<String>()
82-
try {
83-
file.forEachLine { if (it.isNotBlank()) cacheList.add(it.trim()) }
84-
MessageSendHelper.sendChatMessage("$chatName Loaded spammer messages!")
85-
} catch (e: Exception) {
86-
LambdaMod.LOG.error("Failed loading excuses", e)
101+
loadedExcuses.clear()
102+
currentLine = 0
103+
104+
when (modeSource) {
105+
SourceMode.INTERNAL -> loadedExcuses.addAll(defaultExcuses)
106+
SourceMode.EXTERNAL -> {
107+
defaultScope.launch(Dispatchers.IO) {
108+
if (!file.exists()) {
109+
file.createNewFile()
110+
MessageSendHelper.sendErrorMessage("$chatName Excuses file is empty!" +
111+
", please add them in the &7excuses.txt&f under the &7.minecraft/lambda&f directory.")
112+
disable()
113+
return@launch
114+
}
115+
116+
try {
117+
file.forEachLine { if (it.isNotBlank()) loadedExcuses.add(it.trim()) }
118+
MessageSendHelper.sendChatMessage("$chatName Loaded excuse messages!")
119+
} catch (e: Exception) {
120+
MessageSendHelper.sendErrorMessage("$chatName Failed loading excuses, $e")
121+
disable()
122+
}
87123
}
88-
cacheList.toTypedArray()
89-
} else {
90-
file.createNewFile()
91-
MessageSendHelper.sendErrorMessage("$chatName Excuses file is empty!" +
92-
", please add them in the &7excuses.txt&f under the &7.minecraft/lambda&f directory.")
93-
defaultExcuses
94124
}
95-
} else {
96-
defaultExcuses
97125
}
98126
}
99127
}
100128

101129
private val SafeClientEvent.isHoldingTotem: Boolean
102130
get() = EnumHand.values().any { player.getHeldItem(it).item == Items.TOTEM_OF_UNDYING }
103131

104-
private fun getExcuse() = loadedExcuses.random().replace(CLIENT_NAME, clients.random())
132+
private fun getOrdered(): String {
133+
currentLine %= loadedExcuses.size
134+
return loadedExcuses[currentLine++]
135+
}
136+
137+
private fun getRandom(): String {
138+
val prevLine = currentLine
139+
// Avoids sending the same message
140+
while (loadedExcuses.size != 1 && currentLine == prevLine) {
141+
currentLine = Random.nextInt(loadedExcuses.size)
142+
}
143+
return loadedExcuses[currentLine]
144+
}
105145
}

0 commit comments

Comments
 (0)