Skip to content

Commit e80a15c

Browse files
committed
StashLogger: Add logToFile option
This patch adds the logToFile option in the StashLogger module. This option, which is enabled by default, appends all the newfound stashes to a JSON file ($lambda_folder/stash_logger.json). This is useful for when you are afk stash hunting and you would like to keep a log of all the found stashes :)
1 parent 414581b commit e80a15c

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

src/main/kotlin/com/lambda/client/module/modules/misc/StashLogger.kt

+32-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.lambda.client.module.Category
66
import com.lambda.client.module.Module
77
import com.lambda.client.module.modules.movement.AutoWalk
88
import com.lambda.client.util.BaritoneUtils
9+
import com.lambda.client.util.FolderUtils
910
import com.lambda.client.util.TickTimer
1011
import com.lambda.client.util.TimeUnit
1112
import com.lambda.client.util.math.CoordinateConverter.asString
@@ -25,6 +26,9 @@ import net.minecraft.tileentity.*
2526
import net.minecraft.util.math.BlockPos
2627
import net.minecraft.util.math.ChunkPos
2728
import net.minecraftforge.fml.common.gameevent.TickEvent
29+
import org.json.JSONArray
30+
import org.json.JSONObject
31+
import java.io.File
2832
import java.text.SimpleDateFormat
2933
import java.util.*
3034
import kotlin.math.roundToInt
@@ -36,6 +40,7 @@ object StashLogger : Module(
3640
) {
3741
private val saveToWaypoints by setting("Save To Waypoints", true)
3842
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\"")
3944
private val playSound by setting("Play Sound", true)
4045
private val logChests by setting("Chests", true)
4146
private val chestDensity by setting("Min Chests", 5, 1..20, 1, { logChests })
@@ -96,10 +101,35 @@ object StashLogger : Module(
96101
}
97102
}
98103

99-
if (logToChat) {
104+
if (logToChat || logToFile) {
100105
val positionString = center.asString()
101106
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+
}
103133
}
104134

105135
found = true

0 commit comments

Comments
 (0)