Files
2009scape/Server/src/main/core/api/ApiExtensions.kt
T
RiL 52633544ff Implemented ::addxp command (admin), add xp to a skill
Implemented ::charge command (admin), get and set the charge of an item
Implemented ::setslayertask command (admin), set the slayer task npc with optional quantity
2023-05-09 00:02:51 +00:00

66 lines
1.5 KiB
Kotlin

package core.api
import core.game.node.item.Item
import java.util.*
import kotlin.collections.ArrayList
fun IntProgression.toIntArray(): IntArray {
val result = IntArray((last - first) / step + 1)
forEachIndexed { index, i -> result[index] = i }
return result
}
fun Int.asItem() : Item {
return Item(this)
}
fun Collection<IntArray>.toIntArray() : IntArray {
val list = ArrayList<Int>()
this.forEach { arr -> arr.forEach { list.add(it) } }
return list.toIntArray()
}
inline fun <reified T> Collection<T>.isLast(element: T) : Boolean {
return this.indexOf(element) == this.size - 1
}
inline fun <reified T> Collection<T>.getNext(element: T) : T {
val idx = this.indexOf(element)
return if (idx < this.size - 1)
this.elementAt(idx + 1)
else
element
}
inline fun <reified T> Collection<T>.isNextLast(element: T) : Boolean {
return this.isLast(this.getNext(element))
}
fun IntArray.isLast(element: Int) : Boolean {
return this.indexOf(element) == this.size - 1
}
fun IntArray.getNext(element: Int) : Int {
val idx = this.indexOf(element)
return if (idx < this.size - 1)
this.elementAt(idx + 1)
else
element
}
fun IntArray.isNextLast(element: Int) : Boolean {
return this.isLast(this.getNext(element))
}
fun <T> LinkedList<T>.tryPop(default: T?) : T? {
this.peek() ?: return default
return this.pop()
}
inline fun <reified E: Enum<E>> parseEnumEntry(name: String) : E? {
return try {
enumValueOf<E>(name)
} catch (e: Exception) {
null
}
}