diff --git a/game/src/plugins/util/lookup/src/lookup.kt b/game/src/plugins/util/lookup/src/lookup.kt index c7395e10..637f4fab 100644 --- a/game/src/plugins/util/lookup/src/lookup.kt +++ b/game/src/plugins/util/lookup/src/lookup.kt @@ -1,17 +1,24 @@ import org.apollo.cache.def.* fun lookup_object(name: String): ObjectDefinition? { - val definitions = ObjectDefinition.getDefinitions() - return definitions.filter { name.equals(it.name, true) }.firstOrNull() + return find_entity(ObjectDefinition::getDefinitions, ObjectDefinition::getName, name) } fun lookup_npc(name: String): NpcDefinition? { - val definitions = NpcDefinition.getDefinitions() - return definitions.filter { name.equals(it.name, true) }.firstOrNull() + return find_entity(NpcDefinition::getDefinitions, NpcDefinition::getName, name) } fun lookup_item(name: String): ItemDefinition? { - val definitions = ItemDefinition.getDefinitions() - return definitions.filter { name.equals(it.name, true) }.firstOrNull() + return find_entity(ItemDefinition::getDefinitions, ItemDefinition::getName, name) } +private fun find_entity(definitionsProvider: () -> Array, + nameSupplier: T.() -> String, + name: String): T? { + + val normalizedName = name.replace('_', ' ') + val definitions = definitionsProvider.invoke(); + val matcher: (T) -> Boolean = { it.nameSupplier().equals(normalizedName, true) } + + return definitions.filter(matcher).firstOrNull() +} \ No newline at end of file