mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-04 08:39:27 +00:00
Remove plugins.gradle and factor into common extension
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
apolloPlugin {
|
||||
name = "command utilities"
|
||||
packageName = "org.apollo.game.plugins.util"
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
name = "command utilities"
|
||||
package = "org.apollo.game.plugins.util"
|
||||
|
||||
[config]
|
||||
srcDir = "src/"
|
||||
@@ -0,0 +1,20 @@
|
||||
import org.apollo.game.model.entity.Player
|
||||
|
||||
/**
|
||||
* Checks whether the amount of arguments provided is correct, sending the player the specified
|
||||
* message if not.
|
||||
*/
|
||||
fun valid_arg_length(args: Array<String>, length: IntRange, player: Player, message: String): Boolean {
|
||||
val valid = length.contains(args.size)
|
||||
if (!valid) {
|
||||
player.sendMessage(message)
|
||||
}
|
||||
return valid
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the amount of arguments provided is correct, sending the player the specified
|
||||
* message if not.
|
||||
*/
|
||||
fun valid_arg_length(args: Array<String>, length: Int, player: Player, message: String)
|
||||
= valid_arg_length(args, IntRange(length, length), player, message)
|
||||
@@ -0,0 +1,4 @@
|
||||
apolloPlugin {
|
||||
name = "entity lookup"
|
||||
packageName = "org.apollo.game.plugins.util"
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
name = "entity lookup"
|
||||
package = "org.apollo.game.plugins.util"
|
||||
@@ -0,0 +1,24 @@
|
||||
import org.apollo.cache.def.*
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import org.apollo.cache.def.ItemDefinition
|
||||
import org.apollo.game.plugin.testing.*
|
||||
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