LoreStorage

class LoreStorage : SavedData(source)

Persistent storage for lore entries and weekly news snapshots.

This class extends Minecraft's SavedData to automatically persist lore entries to the world save. It maintains weekly snapshots for the Lorekeeper Gazette and submitted-book inventory.

Usage

val storage = LoreStorage.get(server)
storage.addEntry(LoreEntry("Player built a castle", "Steve", System.currentTimeMillis()))

See also

for generating books from stored entries

for the data structure of individual entries

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard
object Companion

Companion object containing constants and factory methods.

Link copied to clipboard
data class LoreEntry(val text: String, val author: String, val timestamp: Long, val notionId: String = "", val notionLastEdited: Long = 0, val qualityScore: Int = 0, val qualityTags: List<String> = emptyList(), val qualitySummary: String = "")

A single lore entry recording an event or player contribution.

Link copied to clipboard
data class MemoryRecord(val recordId: String, val source: String, val sourceRef: String, val timestamp: Long, val text: String, val tags: List<String> = emptyList(), val names: List<String> = emptyList(), val subjects: List<String> = emptyList())

Canonical interpreted memory record used for retrieval-oriented AI context assembly.

Link copied to clipboard
data class ReputationMemoryEvent(val playerId: String, val playerName: String, val timestamp: Long, val source: String, val delta: Int, val reason: String, val evidence: String = "", val relatedNames: List<String> = emptyList())

A structured event describing why reputation changed or what context was observed.

Link copied to clipboard
data class ReputationProfile(val playerId: String, val playerName: String, val alignment: String, val score: Int, val tier: String, val timestamp: Long, val summary: String, val trigger: String)

An archived hero/villain profile generated for a player.

Link copied to clipboard
data class SubmittedBook(val title: String, val author: String, val content: String, val submittedBy: String, val submittedById: String = "", val timestamp: Long, val qualityScore: Int = 0)

A player-submitted written book preserved for future sale by the Lorekeeper.

Link copied to clipboard
data class WeeklyNews(val week: Long, val entries: List<LoreStorage.LoreEntry>)

A snapshot of lore entries for a specific in-game week.

Link copied to clipboard
data class WeeklySummary(val week: Long, val summary: String)

AI-generated summary for a specific week.

Properties

Link copied to clipboard
open var isDirty: Boolean

Functions

Link copied to clipboard

Adds a single lore entry to storage.

Link copied to clipboard
fun addEntryText(text: String, author: String, timestamp: Long)

Convenience method to add a lore entry from raw values.

Link copied to clipboard
fun addEntryTextChunked(text: String, author: String, timestamp: Long, maxChunkLength: Int)

Adds a long text as multiple chunked entries.

Link copied to clipboard
fun addEntryTextChunkedWithResult(text: String, author: String, timestamp: Long, maxChunkLength: Int): List<LoreStorage.LoreEntry>

Adds a long text as multiple chunked entries and returns the created entries.

Link copied to clipboard

Adds a lore entry and returns the created entry.

Link copied to clipboard
fun addReputationEvent(event: LoreStorage.ReputationMemoryEvent, maxEventsPerPlayer: Int = 200)

Records a reputation memory event for later profile generation and narrative grounding.

Link copied to clipboard
fun addReputationProfile(profile: LoreStorage.ReputationProfile, maxProfilesPerPlayer: Int = 1)

Stores the active archived reputation profile for a player.

Link copied to clipboard

Stores an accepted player-submitted book for Lorekeeper resale.

Link copied to clipboard
fun attachNotionMetadata(text: String, author: String, timestamp: Long, notionId: String, notionLastEdited: Long): Boolean

Updates a local entry with Notion metadata after creating a page.

Link copied to clipboard
fun clearAll()

Clears all entries and snapshots.

Link copied to clipboard

Clears the news snapshot and AI summary for the given week.

Link copied to clipboard
fun findSubmittedBook(title: String, author: String, submittedById: String, timestamp: Long): LoreStorage.SubmittedBook?

Finds a submitted book by stable identifiers for resale-volume delivery.

Link copied to clipboard

Returns the published edition number of the history book.

Link copied to clipboard

Returns the AI-generated history summary, or empty string if none exists.

Link copied to clipboard

Returns the timestamp when the AI history summary was last generated.

Link copied to clipboard

Returns the AI-generated summary for the given week, or null if none exists.

Link copied to clipboard

Returns all stored AI weekly summaries (one per week).

Link copied to clipboard

Returns a copy of all stored entries in chronological order.

Link copied to clipboard

Returns all canonical memory records sorted oldest-to-newest by timestamp.

Link copied to clipboard

Returns all recorded reputation memory events.

Link copied to clipboard

Returns all archived reputation profiles.

Link copied to clipboard

Returns the current number of stored entries.

Link copied to clipboard

Returns the most recent entries up to the specified limit.

Link copied to clipboard

Returns the timestamp of the most recent entry, or 0 if no entries exist.

Link copied to clipboard

Returns latest canonical memory records in chronological order.

Link copied to clipboard

Returns the latest archived reputation profile for a player.

Link copied to clipboard

Returns the most recent submitted books up to the specified limit.

Link copied to clipboard

Returns completed memory-index backfill version for this world.

Link copied to clipboard

Returns current canonical memory record count.

Link copied to clipboard

Returns an existing news snapshot for the given week, or null if none exists.

Link copied to clipboard

Returns the last time Notion sync completed, or 0 if never synced.

Link copied to clipboard

Gets or creates a weekly news snapshot.

Link copied to clipboard

Returns the version of completed pagination republish backfills for this world.

Link copied to clipboard

Returns recent reputation memory events for the given player, newest-first.

Link copied to clipboard

Returns the current number of stored submitted books.

Link copied to clipboard

Returns true if a news snapshot exists for the given week.

Link copied to clipboard

Marks the memory-index backfill version when a migration run completes.

Link copied to clipboard

Marks the pagination republish backfill version when a one-time migration completes.

Link copied to clipboard

Removes an entry at the specified index.

Link copied to clipboard
fun removeMemoryRecords(source: String, sourceRef: String? = null): Int

Removes memory records by source and optional source reference.

Link copied to clipboard
fun setAiHistorySummary(summary: String, timestamp: Long)

Stores an AI-generated history summary with its generation timestamp.

Link copied to clipboard
fun setAiNewsSummary(week: Long, summary: String)

Stores an AI-generated summary for the given week.

Link copied to clipboard
fun setNotionLastSync(timestamp: Long)

Updates the last Notion sync timestamp.

Link copied to clipboard
fun updateEntryQuality(text: String, author: String, timestamp: Long, qualityScore: Int, qualityTags: List<String>, qualitySummary: String): Boolean

Updates quality metadata for a specific entry.

Link copied to clipboard

Upserts a canonical memory record by deterministic MemoryRecord.recordId.

Link copied to clipboard

Upserts a batch of memory records and returns the number of changed rows.

Link copied to clipboard
fun upsertNotionEntry(notionId: String, text: String, author: String, timestamp: Long, notionLastEdited: Long): Boolean

Updates or inserts a lore entry based on Notion data.