Skip to content

Commit

Permalink
StashLogger: Add logToFile option
Browse files Browse the repository at this point in the history
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 :)
  • Loading branch information
Baitinq committed Jan 19, 2023
1 parent 414581b commit ff418e5
Showing 1 changed file with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 })
Expand Down Expand Up @@ -96,10 +101,32 @@ object StashLogger : Module(
}
}

if (logToChat) {
val positionString = center.asString()
val timeStr = SimpleDateFormat.getDateTimeInstance().format(Calendar.getInstance().time)
val positionString = center.asString()
val timeStr = SimpleDateFormat.getDateTimeInstance().format(Calendar.getInstance().time)
if (logToChat)
MessageSendHelper.sendChatMessage("$chatName Found $string at ($positionString) [$timeStr]")
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
Expand Down

0 comments on commit ff418e5

Please sign in to comment.