mirror of
https://gitlab.com/2009scape/2009scape.git
synced 2025-12-21 09:02:07 -07:00
Listener key sanity
This commit is contained in:
parent
e8813df024
commit
317e229a59
1 changed files with 23 additions and 5 deletions
|
|
@ -2,20 +2,37 @@ package core.game.interaction
|
||||||
|
|
||||||
import core.game.node.Node
|
import core.game.node.Node
|
||||||
import core.game.node.entity.player.Player
|
import core.game.node.entity.player.Player
|
||||||
import core.tools.StringUtils
|
|
||||||
|
|
||||||
object Listeners {
|
object Listeners {
|
||||||
private val listeners = HashMap<Long,(Player, Node) -> Boolean>()
|
private val listeners = HashMap<String,(Player, Node) -> Boolean>()
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun add(id: Int, type: Int, option: String, method: (Player,Node) -> Boolean){
|
fun add(id: Int, type: Int, option: String, method: (Player,Node) -> Boolean){
|
||||||
val key = (StringUtils.stringToLong(option.toLowerCase()) + id) shl type
|
val key = "$id:$type:${option.toLowerCase()}"
|
||||||
|
listeners[key] = method
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun add(ids: IntArray, type: Int, option: String, method: (Player,Node) -> Boolean){
|
||||||
|
for(id in ids){
|
||||||
|
add(id,type,option,method)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun add(option: String,type: Int, method: (Player,Node) -> Boolean){
|
||||||
|
val key = "$type:${option.toLowerCase()}"
|
||||||
listeners[key] = method
|
listeners[key] = method
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun get(id: Int, type: Int, option: String): ((Player,Node) -> Boolean)?{
|
fun get(id: Int, type: Int, option: String): ((Player,Node) -> Boolean)?{
|
||||||
return listeners[(StringUtils.stringToLong(option.toLowerCase()) + id) shl type]
|
return listeners["$id:$type:${option.toLowerCase()}"]
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun get(option: String,type: Int): ((Player,Node) -> Boolean)?{
|
||||||
|
return listeners["$type:${option.toLowerCase()}"]
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
|
|
@ -26,11 +43,12 @@ object Listeners {
|
||||||
else -> DestinationFlag.OBJECT
|
else -> DestinationFlag.OBJECT
|
||||||
}
|
}
|
||||||
|
|
||||||
val method = get(id,type,option) ?: return false
|
val method = get(id,type,option) ?: get(option,type) ?: return false
|
||||||
|
|
||||||
if(type != 0) {
|
if(type != 0) {
|
||||||
player.pulseManager.run(object : MovementPulse(player, node, flag) {
|
player.pulseManager.run(object : MovementPulse(player, node, flag) {
|
||||||
override fun pulse(): Boolean {
|
override fun pulse(): Boolean {
|
||||||
|
player.faceLocation(node.location)
|
||||||
method.invoke(player,node)
|
method.invoke(player,node)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue