mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-06 16:51:37 +00:00
Add tests for player actions
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package org.apollo.game.plugin.entity.player_action
|
||||
|
||||
import org.apollo.game.message.impl.SetPlayerActionMessage
|
||||
import org.apollo.game.model.entity.Player
|
||||
import org.apollo.game.model.event.PlayerEvent
|
||||
import java.util.*
|
||||
|
||||
class PlayerActionEvent(player: Player, val target: Player, val action: PlayerActionType) : PlayerEvent(player)
|
||||
|
||||
fun Player.enableAction(action: PlayerActionType) {
|
||||
send(SetPlayerActionMessage(action.displayName, action.slot, action.primary))
|
||||
actions += action
|
||||
}
|
||||
|
||||
fun Player.disableAction(action: PlayerActionType) {
|
||||
send(SetPlayerActionMessage("null", action.slot, action.primary))
|
||||
actions -= action
|
||||
}
|
||||
|
||||
fun Player.actionEnabled(action: PlayerActionType): Boolean {
|
||||
return action in actions
|
||||
}
|
||||
|
||||
fun Player.actionAt(slot: Int): PlayerActionType? {
|
||||
return actions.find { it.slot == slot }
|
||||
}
|
||||
|
||||
private val playerActionsMap = mutableMapOf<Player, EnumSet<PlayerActionType>>()
|
||||
|
||||
private val Player.actions: EnumSet<PlayerActionType>
|
||||
get() = playerActionsMap.computeIfAbsent(this) { EnumSet.noneOf(PlayerActionType::class.java) }
|
||||
Reference in New Issue
Block a user