package net.taehui.twilight.system import com.fasterxml.jackson.core.type.TypeReference import com.fasterxml.jackson.databind.ObjectMapper import net.taehui.twilight.Logger import java.io.IOException import java.nio.file.Paths import java.util.concurrent.ConcurrentHashMap object BannedNoteSystem : Logger { private val bannedNoteStore = ConcurrentHashMap<String, String>() private var isLoaded = false fun loadBannedNote() { try { bannedNoteStore.putAll( ObjectMapper().readValue( Paths.get("Banned Note.json").toFile().absoluteFile, object : TypeReference<ConcurrentHashMap<String, String>>() {}) ) isLoaded = true logInfo("Loaded Banned Note") } catch (e: IOException) { logFault(e) } } fun saveBannedNote() { if (isLoaded) { ObjectMapper().writerWithDefaultPrettyPrinter() .writeValue(Paths.get("Banned Note.json").toFile().absoluteFile, bannedNoteStore) logInfo("Saved Banned Note") } } fun putBannedNoteFile(noteID: String, commentary: String) { bannedNoteStore[noteID] = commentary } fun wipeBannedNoteFile(noteID: String) { bannedNoteStore.remove(noteID) } fun isBanned(noteID: String): Boolean { return bannedNoteStore.contains(noteID) } }