mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-05 08:40:08 +00:00
Remove util:lookup plugin
Behaviour moved into the api plugin.
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
plugin {
|
||||
name = "entity_lookup"
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package org.apollo.game.plugin.util.lookup
|
||||
|
||||
import org.apollo.cache.def.ItemDefinition
|
||||
import org.apollo.cache.def.NpcDefinition
|
||||
import org.apollo.cache.def.ObjectDefinition
|
||||
|
||||
fun lookup_object(name: String): ObjectDefinition? {
|
||||
return find_entity(ObjectDefinition::getDefinitions, ObjectDefinition::getName, name)
|
||||
}
|
||||
|
||||
fun lookup_npc(name: String): NpcDefinition? {
|
||||
return find_entity(NpcDefinition::getDefinitions, NpcDefinition::getName, name)
|
||||
}
|
||||
|
||||
fun lookup_item(name: String): ItemDefinition? {
|
||||
return find_entity(ItemDefinition::getDefinitions, ItemDefinition::getName, name)
|
||||
}
|
||||
|
||||
/**
|
||||
* The [Regex] used to match 'names' that have an id attached to the end.
|
||||
*/
|
||||
private val ID_REGEX = Regex(".+_[0-9]+$")
|
||||
|
||||
private fun <T : Any> find_entity(definitionsProvider: () -> Array<T>,
|
||||
nameSupplier: T.() -> String,
|
||||
name: String): T? {
|
||||
val definitions = definitionsProvider.invoke()
|
||||
|
||||
if (ID_REGEX matches name) {
|
||||
val id = name.substring(name.lastIndexOf('_') + 1, name.length).toInt()
|
||||
return definitions.getOrNull(id)
|
||||
}
|
||||
|
||||
val normalizedName = name.replace('_', ' ')
|
||||
|
||||
return definitions.firstOrNull { it.nameSupplier().equals(normalizedName, true) }
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
import org.apollo.cache.def.ItemDefinition
|
||||
import org.apollo.game.plugin.testing.KotlinPluginTest
|
||||
import org.apollo.game.plugin.util.lookup.lookup_item
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.Test
|
||||
|
||||
class LookupTests : KotlinPluginTest() {
|
||||
@Test
|
||||
fun itemLookup() {
|
||||
val testItem = ItemDefinition(0)
|
||||
testItem.name = "sword"
|
||||
|
||||
ItemDefinition.init(arrayOf(testItem))
|
||||
|
||||
assertThat(lookup_item("sword")).isEqualTo(testItem)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user