11package com.lambda.client.module.modules.misc
22
33import com.lambda.client.commons.extension.synchronized
4+ import com.lambda.client.event.SafeClientEvent
45import com.lambda.client.manager.managers.WaypointManager
56import com.lambda.client.module.Category
67import com.lambda.client.module.Module
78import com.lambda.client.module.modules.movement.AutoWalk
89import com.lambda.client.util.BaritoneUtils
10+ import com.lambda.client.util.FolderUtils
911import com.lambda.client.util.TickTimer
1012import com.lambda.client.util.TimeUnit
1113import com.lambda.client.util.math.CoordinateConverter.asString
1214import com.lambda.client.util.text.MessageSendHelper
1315import com.lambda.client.util.threads.defaultScope
1416import com.lambda.client.util.threads.onMainThread
1517import com.lambda.client.util.threads.safeListener
18+ import kotlinx.coroutines.Dispatchers
1619import kotlinx.coroutines.coroutineScope
1720import kotlinx.coroutines.launch
21+ import kotlinx.coroutines.withContext
1822import net.minecraft.client.audio.PositionedSoundRecord
1923import net.minecraft.entity.Entity
2024import net.minecraft.entity.item.EntityMinecartChest
@@ -24,7 +28,13 @@ import net.minecraft.init.SoundEvents
2428import net.minecraft.tileentity.*
2529import net.minecraft.util.math.BlockPos
2630import net.minecraft.util.math.ChunkPos
31+ import net.minecraftforge.fml.common.FMLCommonHandler
2732import 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
2838import java.text.SimpleDateFormat
2939import java.util.*
3040import kotlin.math.roundToInt
@@ -36,6 +46,7 @@ object StashLogger : Module(
3646) {
3747 private val saveToWaypoints by setting(" Save To Waypoints" , true )
3848 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\" " )
3950 private val playSound by setting(" Play Sound" , true )
4051 private val logChests by setting(" Chests" , true )
4152 private val chestDensity by setting(" Min Chests" , 5 , 1 .. 20 , 1 , { logChests })
@@ -76,7 +87,7 @@ object StashLogger : Module(
7687 }
7788 }
7889
79- private suspend fun notification () {
90+ private suspend fun SafeClientEvent. notification () {
8091 var found = false
8192
8293 for (chunkStats in chunkData.values) {
@@ -96,10 +107,36 @@ object StashLogger : Module(
96107 }
97108 }
98109
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 )
102113 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+ };
103140 }
104141
105142 found = true
0 commit comments