From 4e5d98de9b731aefe14e3d0f775f57782703f970 Mon Sep 17 00:00:00 2001 From: Gabber235 Date: Sat, 9 Dec 2023 10:40:30 +0100 Subject: [PATCH] Fix npc interact not working --- .../gabber235/typewriter/adapters/editors/SoundIdEditor.kt | 3 +-- .../kotlin/me/gabber235/typewriter/entry/EntryDatabase.kt | 7 +++++-- .../kotlin/me/gabber235/typewriter/entry/EntryListeners.kt | 6 ++++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/editors/SoundIdEditor.kt b/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/editors/SoundIdEditor.kt index 8b6f6b11e6..07c76382f8 100644 --- a/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/editors/SoundIdEditor.kt +++ b/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/editors/SoundIdEditor.kt @@ -6,7 +6,6 @@ import me.gabber235.typewriter.adapters.ObjectEditor import me.gabber235.typewriter.utils.DefaultSoundId import me.gabber235.typewriter.utils.EntrySoundId import me.gabber235.typewriter.utils.SoundId -import org.bukkit.NamespacedKey @CustomEditor(SoundId::class) fun ObjectEditor.soundId() = reference { @@ -25,7 +24,7 @@ fun ObjectEditor.soundId() = reference { val value = obj.get("value").asString when (type) { - "default" -> DefaultSoundId(NamespacedKey.fromString(value)) + "default" -> DefaultSoundId(value) "entry" -> EntrySoundId(value) else -> throw IllegalArgumentException("Invalid sound id type: $type") } diff --git a/plugin/src/main/kotlin/me/gabber235/typewriter/entry/EntryDatabase.kt b/plugin/src/main/kotlin/me/gabber235/typewriter/entry/EntryDatabase.kt index dd6b879cc7..0b235f7f10 100644 --- a/plugin/src/main/kotlin/me/gabber235/typewriter/entry/EntryDatabase.kt +++ b/plugin/src/main/kotlin/me/gabber235/typewriter/entry/EntryDatabase.kt @@ -7,7 +7,10 @@ import com.google.gson.stream.JsonReader import lirand.api.extensions.events.listen import me.gabber235.typewriter.adapters.AdapterLoader import me.gabber235.typewriter.adapters.customEditors -import me.gabber235.typewriter.entry.entries.* +import me.gabber235.typewriter.entry.entries.CustomCommandEntry +import me.gabber235.typewriter.entry.entries.EventEntry +import me.gabber235.typewriter.entry.entries.FactEntry +import me.gabber235.typewriter.entry.entries.ReadableFactEntry import me.gabber235.typewriter.events.PublishedBookEvent import me.gabber235.typewriter.events.TypewriterReloadEvent import me.gabber235.typewriter.logger @@ -167,7 +170,7 @@ private fun JsonReader.parseEntry(gson: Gson): Entry? { ) null } catch (e: Exception) { - logger.warning("Failed to parse entry: ${e.message}") + logger.warning("Failed to parse entry: ${e.message} (${this})") null } } diff --git a/plugin/src/main/kotlin/me/gabber235/typewriter/entry/EntryListeners.kt b/plugin/src/main/kotlin/me/gabber235/typewriter/entry/EntryListeners.kt index aaf27b121b..9b6694e106 100644 --- a/plugin/src/main/kotlin/me/gabber235/typewriter/entry/EntryListeners.kt +++ b/plugin/src/main/kotlin/me/gabber235/typewriter/entry/EntryListeners.kt @@ -71,8 +71,10 @@ class EntryListeners : KoinComponent { val entryListeners = adapterLoader.adapters.flatMap { it.eventListeners } - entryDatabase.events.map { it::class }.distinct().mapNotNull { klass -> - entryListeners.firstOrNull { it.entry.isSuperclassOf(klass) } + val activeEventEntries = entryDatabase.events.map { it::class }.distinct() + + entryListeners.filter { + activeEventEntries.any { activeEventEntry -> it.entry.isSuperclassOf(activeEventEntry) } }.forEach { val eventClass = findEventFromMethod(it.method) ?: return@forEach