mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-06 16:51:37 +00:00
Add missing name normalization to lookup plugin
This commit is contained in:
@@ -1,17 +1,24 @@
|
|||||||
import org.apollo.cache.def.*
|
import org.apollo.cache.def.*
|
||||||
|
|
||||||
fun lookup_object(name: String): ObjectDefinition? {
|
fun lookup_object(name: String): ObjectDefinition? {
|
||||||
val definitions = ObjectDefinition.getDefinitions()
|
return find_entity(ObjectDefinition::getDefinitions, ObjectDefinition::getName, name)
|
||||||
return definitions.filter { name.equals(it.name, true) }.firstOrNull()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun lookup_npc(name: String): NpcDefinition? {
|
fun lookup_npc(name: String): NpcDefinition? {
|
||||||
val definitions = NpcDefinition.getDefinitions()
|
return find_entity(NpcDefinition::getDefinitions, NpcDefinition::getName, name)
|
||||||
return definitions.filter { name.equals(it.name, true) }.firstOrNull()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun lookup_item(name: String): ItemDefinition? {
|
fun lookup_item(name: String): ItemDefinition? {
|
||||||
val definitions = ItemDefinition.getDefinitions()
|
return find_entity(ItemDefinition::getDefinitions, ItemDefinition::getName, name)
|
||||||
return definitions.filter { name.equals(it.name, true) }.firstOrNull()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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