Skip to content

Commit ff418e5

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 ff418e5

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

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

+30-3
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,32 @@ object StashLogger : Module(
96101
}
97102
}
98103

99-
if (logToChat) {
100-
val positionString = center.asString()
101-
val timeStr = SimpleDateFormat.getDateTimeInstance().format(Calendar.getInstance().time)
104+
val positionString = center.asString()
105+
val timeStr = SimpleDateFormat.getDateTimeInstance().format(Calendar.getInstance().time)
106+
if (logToChat)
102107
MessageSendHelper.sendChatMessage("$chatName Found $string at ($positionString) [$timeStr]")
108+
if(logToFile) {
109+
val file = File(FolderUtils.lambdaFolder + "stash_logger.json")
110+
val json = when {
111+
file.exists() -> {
112+
val jsonString = file.readText(Charsets.UTF_8)
113+
JSONObject(jsonString)
114+
}
115+
else -> JSONObject()
116+
}
117+
val stashesJson = when {
118+
json.has("stashes") -> json.getJSONArray("stashes")
119+
else -> JSONArray()
120+
}
121+
122+
val stashJson = JSONObject()
123+
stashJson.put("date", timeStr)
124+
stashJson.put("location", positionString)
125+
stashJson.put("info", string)
126+
127+
stashesJson.put(stashJson)
128+
json.put("stashes", stashesJson)
129+
file.writeText(json.toString(4))
103130
}
104131

105132
found = true

0 commit comments

Comments
 (0)