mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 00:38:21 +00:00
Add missing name normalization to lookup plugin
This commit is contained in:
@@ -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 <T : Any> find_entity(definitionsProvider: () -> Array<T>,
|
||||
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()
|
||||
}
|
||||
Reference in New Issue
Block a user