Remove plugins.gradle and factor into common extension

This commit is contained in:
Gary Tierney
2017-09-16 18:49:06 +01:00
parent d323bcd69c
commit 36282cf81e
104 changed files with 608 additions and 408 deletions
+4
View File
@@ -0,0 +1,4 @@
apolloPlugin {
name = "command utilities"
packageName = "org.apollo.game.plugins.util"
}
+5
View File
@@ -0,0 +1,5 @@
name = "command utilities"
package = "org.apollo.game.plugins.util"
[config]
srcDir = "src/"
+20
View File
@@ -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)
+4
View File
@@ -0,0 +1,4 @@
apolloPlugin {
name = "entity lookup"
packageName = "org.apollo.game.plugins.util"
}
+2
View File
@@ -0,0 +1,2 @@
name = "entity lookup"
package = "org.apollo.game.plugins.util"
+24
View File
@@ -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);
}
}