1
1
package com.lambda.client.module.modules.misc
2
2
3
3
import com.lambda.client.commons.extension.synchronized
4
+ import com.lambda.client.event.SafeClientEvent
4
5
import com.lambda.client.manager.managers.WaypointManager
5
6
import com.lambda.client.module.Category
6
7
import com.lambda.client.module.Module
7
8
import com.lambda.client.module.modules.movement.AutoWalk
8
9
import com.lambda.client.util.BaritoneUtils
10
+ import com.lambda.client.util.FolderUtils
9
11
import com.lambda.client.util.TickTimer
10
12
import com.lambda.client.util.TimeUnit
11
13
import com.lambda.client.util.math.CoordinateConverter.asString
12
14
import com.lambda.client.util.text.MessageSendHelper
13
15
import com.lambda.client.util.threads.defaultScope
14
16
import com.lambda.client.util.threads.onMainThread
15
17
import com.lambda.client.util.threads.safeListener
18
+ import kotlinx.coroutines.Dispatchers
16
19
import kotlinx.coroutines.coroutineScope
17
20
import kotlinx.coroutines.launch
21
+ import kotlinx.coroutines.withContext
18
22
import net.minecraft.client.audio.PositionedSoundRecord
19
23
import net.minecraft.entity.Entity
20
24
import net.minecraft.entity.item.EntityMinecartChest
@@ -24,7 +28,13 @@ import net.minecraft.init.SoundEvents
24
28
import net.minecraft.tileentity.*
25
29
import net.minecraft.util.math.BlockPos
26
30
import net.minecraft.util.math.ChunkPos
31
+ import net.minecraftforge.fml.common.FMLCommonHandler
27
32
import net.minecraftforge.fml.common.gameevent.TickEvent
33
+ import org.json.JSONArray
34
+ import org.json.JSONObject
35
+ import java.io.File
36
+ import java.nio.file.Files
37
+ import java.nio.file.Paths
28
38
import java.text.SimpleDateFormat
29
39
import java.util.*
30
40
import kotlin.math.roundToInt
@@ -36,6 +46,7 @@ object StashLogger : Module(
36
46
) {
37
47
private val saveToWaypoints by setting(" Save To Waypoints" , true )
38
48
private val logToChat by setting(" Log To Chat" , true )
49
+ private val logToFile by setting(" Log To File" , true , description = " Logs found stashes in \" .minecraft/lambda/stash-logger/servername.json\" " )
39
50
private val playSound by setting(" Play Sound" , true )
40
51
private val logChests by setting(" Chests" , true )
41
52
private val chestDensity by setting(" Min Chests" , 5 , 1 .. 20 , 1 , { logChests })
@@ -76,7 +87,7 @@ object StashLogger : Module(
76
87
}
77
88
}
78
89
79
- private suspend fun notification () {
90
+ private suspend fun SafeClientEvent. notification () {
80
91
var found = false
81
92
82
93
for (chunkStats in chunkData.values) {
@@ -96,10 +107,36 @@ object StashLogger : Module(
96
107
}
97
108
}
98
109
99
- if (logToChat) {
100
- val positionString = center.asString( )
101
- val timeStr = SimpleDateFormat .getDateTimeInstance().format( Calendar .getInstance().time )
110
+ val positionString = center.asString()
111
+ val timeStr = SimpleDateFormat .getDateTimeInstance().format( Calendar .getInstance().time )
112
+ if (logToChat )
102
113
MessageSendHelper .sendChatMessage(" $chatName Found $string at ($positionString ) [$timeStr ]" )
114
+ if (logToFile) {
115
+ val fileName = mc.currentServerData?.serverIP ? : FMLCommonHandler .instance()?.minecraftServerInstance?.folderName
116
+ withContext(Dispatchers .IO ) {
117
+ val stashLoggerFolder = Files .createDirectory(Paths .get(FolderUtils .lambdaFolder + " stash-logger" ))
118
+ val file = File (stashLoggerFolder.toString() + " /${fileName} .json" )
119
+ val json = when {
120
+ file.exists() -> {
121
+ val jsonString = file.readText(Charsets .UTF_8 )
122
+ JSONObject (jsonString)
123
+ }
124
+ else -> JSONObject ()
125
+ }
126
+ val stashesJson = when {
127
+ json.has(" stashes" ) -> json.getJSONArray(" stashes" )
128
+ else -> JSONArray ()
129
+ }
130
+
131
+ val stashJson = JSONObject ()
132
+ stashJson.put(" date" , timeStr)
133
+ stashJson.put(" location" , positionString)
134
+ stashJson.put(" info" , string)
135
+
136
+ stashesJson.put(stashJson)
137
+ json.put(" stashes" , stashesJson)
138
+ file.writeText(json.toString(4 ))
139
+ };
103
140
}
104
141
105
142
found = true
0 commit comments