From e80a15c8dfa655fadd1c473d738c5639d2c32a2d Mon Sep 17 00:00:00 2001 From: Baitinq Date: Thu, 19 Jan 2023 15:25:00 +0100 Subject: [PATCH] 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 :) --- .../client/module/modules/misc/StashLogger.kt | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/StashLogger.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/StashLogger.kt index 042e5684f..8d545222d 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/StashLogger.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/StashLogger.kt @@ -6,6 +6,7 @@ import com.lambda.client.module.Category import com.lambda.client.module.Module import com.lambda.client.module.modules.movement.AutoWalk import com.lambda.client.util.BaritoneUtils +import com.lambda.client.util.FolderUtils import com.lambda.client.util.TickTimer import com.lambda.client.util.TimeUnit import com.lambda.client.util.math.CoordinateConverter.asString @@ -25,6 +26,9 @@ import net.minecraft.tileentity.* import net.minecraft.util.math.BlockPos import net.minecraft.util.math.ChunkPos import net.minecraftforge.fml.common.gameevent.TickEvent +import org.json.JSONArray +import org.json.JSONObject +import java.io.File import java.text.SimpleDateFormat import java.util.* import kotlin.math.roundToInt @@ -36,6 +40,7 @@ object StashLogger : Module( ) { private val saveToWaypoints by setting("Save To Waypoints", true) private val logToChat by setting("Log To Chat", true) + private val logToFile by setting("Log To File", true, description = "Logs found stashes in \".minecraft/lambda/stash_logger.json\"") private val playSound by setting("Play Sound", true) private val logChests by setting("Chests", true) private val chestDensity by setting("Min Chests", 5, 1..20, 1, { logChests }) @@ -96,10 +101,35 @@ object StashLogger : Module( } } - if (logToChat) { + if (logToChat || logToFile) { val positionString = center.asString() val timeStr = SimpleDateFormat.getDateTimeInstance().format(Calendar.getInstance().time) - MessageSendHelper.sendChatMessage("$chatName Found $string at ($positionString) [$timeStr]") + val msg = "$chatName Found $string at ($positionString) [$timeStr]" + if (logToChat) + MessageSendHelper.sendChatMessage(msg) + if(logToFile) { + val file = File(FolderUtils.lambdaFolder + "stash_logger.json") + val json = when { + file.exists() -> { + val jsonString = file.readText(Charsets.UTF_8) + JSONObject(jsonString) + } + else -> JSONObject() + } + val stashesJson = when { + json.has("stashes") -> json.getJSONArray("stashes") + else -> JSONArray() + } + + val stashJson = JSONObject() + stashJson.put("date", timeStr) + stashJson.put("location", positionString) + stashJson.put("info", string) + + stashesJson.put(stashJson) + json.put("stashes", stashesJson) + file.writeText(json.toString(4)) + } } found = true