1
1
package com.lambda.client.module.modules.chat
2
2
3
3
import com.lambda.client.LambdaMod
4
+ import com.lambda.client.commons.extension.synchronized
4
5
import com.lambda.client.event.SafeClientEvent
5
6
import com.lambda.client.event.events.PacketEvent
6
7
import com.lambda.client.module.Category
@@ -10,27 +11,43 @@ import com.lambda.client.util.TickTimer
10
11
import com.lambda.client.util.TimeUnit
11
12
import com.lambda.client.util.text.MessageSendHelper
12
13
import com.lambda.client.util.text.MessageSendHelper.sendServerMessage
14
+ import com.lambda.client.util.threads.defaultScope
13
15
import com.lambda.client.util.threads.safeListener
16
+ import kotlinx.coroutines.Dispatchers
17
+ import kotlinx.coroutines.launch
14
18
import net.minecraft.init.Items
15
19
import net.minecraft.network.play.server.SPacketUpdateHealth
16
20
import net.minecraft.util.EnumHand
17
21
import java.io.File
22
+ import kotlin.random.Random
18
23
19
24
object AutoExcuse : Module(
20
25
name = " AutoExcuse" ,
21
26
description = " Makes an excuse for you when you die" ,
22
27
category = Category .CHAT ,
23
28
modulePriority = 500
24
29
) {
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 )
26
38
27
39
private enum class Mode {
40
+ IN_ORDER , RANDOM_ORDER
41
+ }
42
+
43
+ private enum class SourceMode {
28
44
INTERNAL , EXTERNAL
29
45
}
30
46
31
47
private const val CLIENT_NAME = " %CLIENT%"
48
+
32
49
private val defaultExcuses = arrayOf(
33
- " Sorry, im using $CLIENT_NAME client " ,
50
+ " Sorry, im using $CLIENT_NAME " ,
34
51
" My ping is so bad" ,
35
52
" I was changing my config :(" ,
36
53
" Why did my AutoTotem break" ,
@@ -39,10 +56,10 @@ object AutoExcuse : Module(
39
56
" Wow, so many try hards" ,
40
57
" Lagggg" ,
41
58
" I wasn't trying" ,
42
- " I'm not using $CLIENT_NAME client " ,
59
+ " I'm not using $CLIENT_NAME " ,
43
60
" Thers to much lag" ,
44
61
" My dog ate my pc" ,
45
- " Sorry, $CLIENT_NAME Client is really bad" ,
62
+ " Sorry, $CLIENT_NAME is really bad" ,
46
63
" I was lagging" ,
47
64
" He was cheating!" ,
48
65
" Your hacking!" ,
@@ -52,54 +69,77 @@ object AutoExcuse : Module(
52
69
" My wifi went down" ,
53
70
" I'm playing vanila" ,
54
71
" 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" ,
56
82
)
57
83
58
- private val file = File (FolderUtils .lambdaFolder + " excuses.txt" )
59
- private var loadedExcuses = defaultExcuses
60
-
61
84
private val clients = arrayOf(
62
- " Future" ,
85
+ " Future Client " ,
63
86
" Salhack" ,
64
87
" Pyro" ,
65
88
" Impact"
66
89
)
67
90
68
- private val timer = TickTimer (TimeUnit .SECONDS )
69
-
70
91
init {
71
92
safeListener<PacketEvent .Receive > {
72
93
if (loadedExcuses.isEmpty() || it.packet !is SPacketUpdateHealth ) return @safeListener
73
94
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()))
75
97
}
76
98
}
77
99
78
100
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
+ }
87
123
}
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
94
124
}
95
- } else {
96
- defaultExcuses
97
125
}
98
126
}
99
127
}
100
128
101
129
private val SafeClientEvent .isHoldingTotem: Boolean
102
130
get() = EnumHand .values().any { player.getHeldItem(it).item == Items .TOTEM_OF_UNDYING }
103
131
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
+ }
105
145
}
0 commit comments