@@ -6,6 +6,7 @@ import com.lambda.client.module.Category
6
6
import com.lambda.client.module.Module
7
7
import com.lambda.client.module.modules.movement.AutoWalk
8
8
import com.lambda.client.util.BaritoneUtils
9
+ import com.lambda.client.util.FolderUtils
9
10
import com.lambda.client.util.TickTimer
10
11
import com.lambda.client.util.TimeUnit
11
12
import com.lambda.client.util.math.CoordinateConverter.asString
@@ -25,6 +26,9 @@ import net.minecraft.tileentity.*
25
26
import net.minecraft.util.math.BlockPos
26
27
import net.minecraft.util.math.ChunkPos
27
28
import net.minecraftforge.fml.common.gameevent.TickEvent
29
+ import org.json.JSONArray
30
+ import org.json.JSONObject
31
+ import java.io.File
28
32
import java.text.SimpleDateFormat
29
33
import java.util.*
30
34
import kotlin.math.roundToInt
@@ -36,6 +40,7 @@ object StashLogger : Module(
36
40
) {
37
41
private val saveToWaypoints by setting(" Save To Waypoints" , true )
38
42
private val logToChat by setting(" Log To Chat" , true )
43
+ private val logToFile by setting(" Log To File" , true , description = " Logs found stashes in \" .minecraft/lambda/stash_logger.json\" " )
39
44
private val playSound by setting(" Play Sound" , true )
40
45
private val logChests by setting(" Chests" , true )
41
46
private val chestDensity by setting(" Min Chests" , 5 , 1 .. 20 , 1 , { logChests })
@@ -96,10 +101,35 @@ object StashLogger : Module(
96
101
}
97
102
}
98
103
99
- if (logToChat) {
104
+ if (logToChat || logToFile ) {
100
105
val positionString = center.asString()
101
106
val timeStr = SimpleDateFormat .getDateTimeInstance().format(Calendar .getInstance().time)
102
- MessageSendHelper .sendChatMessage(" $chatName Found $string at ($positionString ) [$timeStr ]" )
107
+ val msg = " $chatName Found $string at ($positionString ) [$timeStr ]"
108
+ if (logToChat)
109
+ MessageSendHelper .sendChatMessage(msg)
110
+ if (logToFile) {
111
+ val file = File (FolderUtils .lambdaFolder + " stash_logger.json" )
112
+ val json = when {
113
+ file.exists() -> {
114
+ val jsonString = file.readText(Charsets .UTF_8 )
115
+ JSONObject (jsonString)
116
+ }
117
+ else -> JSONObject ()
118
+ }
119
+ val stashesJson = when {
120
+ json.has(" stashes" ) -> json.getJSONArray(" stashes" )
121
+ else -> JSONArray ()
122
+ }
123
+
124
+ val stashJson = JSONObject ()
125
+ stashJson.put(" date" , timeStr)
126
+ stashJson.put(" location" , positionString)
127
+ stashJson.put(" info" , string)
128
+
129
+ stashesJson.put(stashJson)
130
+ json.put(" stashes" , stashesJson)
131
+ file.writeText(json.toString(4 ))
132
+ }
103
133
}
104
134
105
135
found = true
0 commit comments