Skip to content

Commit

Permalink
Fix npc interact not working
Browse files Browse the repository at this point in the history
  • Loading branch information
gabber235 committed Dec 9, 2023
1 parent 0191bba commit 4e5d98d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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>.soundId() = reference {
Expand All @@ -25,7 +24,7 @@ fun ObjectEditor<SoundId>.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")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 4e5d98d

Please sign in to comment.