aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/io
diff options
context:
space:
mode:
authornea <romangraef@gmail.com>2022-12-31 19:40:50 +0100
committernea <romangraef@gmail.com>2023-01-11 22:09:21 +0100
commit5190017bc8f7bb1177da239842e4b3a18a888d8c (patch)
tree0486fdc881517ad5da5cf4a24ab24532b6ca7435 /src/main/kotlin/io
parent0134c83fbc02147794e3b7134cff6f9b6dc446f6 (diff)
downloadNotEnoughUpdates-5190017bc8f7bb1177da239842e4b3a18a888d8c.tar.gz
NotEnoughUpdates-5190017bc8f7bb1177da239842e4b3a18a888d8c.tar.bz2
NotEnoughUpdates-5190017bc8f7bb1177da239842e4b3a18a888d8c.zip
EnforcedConfigValues: Allow filtering for mod version
Diffstat (limited to 'src/main/kotlin/io')
-rw-r--r--src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/EnforcedConfigValues.kt32
1 files changed, 21 insertions, 11 deletions
diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/EnforcedConfigValues.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/EnforcedConfigValues.kt
index 50c45832..d5a1260e 100644
--- a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/EnforcedConfigValues.kt
+++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/EnforcedConfigValues.kt
@@ -43,18 +43,27 @@ object EnforcedConfigValues {
var enforcedValues: List<EnforcedValue> = listOf()
var notificationPSA: List<String>? = null
var chatPSA: List<String>? = null
+ lateinit var affectedVersions: List<Int>
}
- var enforcedValues = EnforcedValueData()
+ var enforcedValues: List<EnforcedValueData> = listOf()
@SubscribeEvent
fun onRepoReload(event: RepositoryReloadEvent) {
- val fixedValues = event.repositoryRoot.resolve("constants/enforced_values.json")
+ val fixedValues = event.repositoryRoot.resolve("enforced_values")
enforcedValues = if (fixedValues.exists()) {
- NotEnoughUpdates.INSTANCE.manager.gson.fromJson(fixedValues.readText())
+ fixedValues.listFiles()
+ .filter {
+ it != null && it.isFile && it.canRead()
+ }
+ .map {
+ NotEnoughUpdates.INSTANCE.manager.gson.fromJson<EnforcedValueData>(it.readText())
+ }.filter {
+ NotEnoughUpdates.VERSION_ID in it.affectedVersions
+ }
} else {
- EnforcedValueData()
+ listOf()
}
if (!event.isFirstLoad)
sendPSAs()
@@ -76,20 +85,21 @@ object EnforcedConfigValues {
}
fun sendPSAs() {
- val notification = enforcedValues.notificationPSA
- if (notification != null) {
+ val notification = enforcedValues.flatMap { it.notificationPSA ?: emptyList() }
+ if (notification.isNotEmpty()) {
NotificationHandler.displayNotification(notification, true)
}
- val chat = enforcedValues.chatPSA
- if (chat != null) {
- for (line in chat)
+ val chat = enforcedValues.flatMap { it.chatPSA ?: emptyList() }
+ if (chat.isNotEmpty()) {
+ for (line in chat) {
Utils.addChatMessage(line)
+ }
}
}
fun enforceOntoConfig(config: Any) {
- for (enforcedValue in enforcedValues.enforcedValues) {
+ for (enforcedValue in enforcedValues.flatMap { it.enforcedValues }) {
val shimmy = Shimmy.makeShimmy(config, enforcedValue.path.split("."))
if (shimmy == null) {
println("Could not create shimmy for path ${enforcedValue.path}")
@@ -104,7 +114,7 @@ object EnforcedConfigValues {
}
fun isBlockedFromEditing(optionPath: String): Boolean {
- return enforcedValues.enforcedValues.any { it.path == optionPath }
+ return enforcedValues.flatMap { it.enforcedValues }.any { it.path == optionPath }
}