RuneHive-Game
Loading...
Searching...
No Matches
PlayerRelationEvent.kt
Go to the documentation of this file.
1package org.jire.runehiveps.event.widget
2
3import com.runehive.game.world.World
4import com.runehive.game.world.entity.mob.player.Player
5import com.runehive.game.world.entity.mob.player.relations.PrivateChatMessage
6import com.runehive.net.packet.ClientPackets
7import com.runehive.util.ChatCodec
8import com.runehive.util.Utility
9import kotlin.jvm.optionals.getOrNull
10
11/**
12 * @author Jire
13 */
14class PlayerRelationEvent(
15 val opcode: Int,
16 val username: Long,
17 val input: ByteArray? = null
18) : WidgetEvent {
19
20 override fun handle(player: Player) {
21 when (opcode) {
22 ClientPackets.ADD_FRIEND -> player.relations.addFriend(username)
23 ClientPackets.REMOVE_FRIEND -> player.relations.deleteFriend(username)
24 ClientPackets.ADD_IGNORE -> player.relations.addIgnore(username)
25 ClientPackets.REMOVE_IGNORE -> player.relations.deleteIgnore(username)
26 ClientPackets.PRIVATE_MESSAGE -> {
27 val other = World.search(
28 Utility.formatText(
29 Utility.longToString(username)
30 ).replace('_', ' ')
31 ).getOrNull() ?: return
32
33 val decoded = ChatCodec.decode(input)
34 val compressed = ChatCodec.encode(decoded)
35
36 player.relations.message(other, PrivateChatMessage(decoded, compressed))
37 }
38 }
39 }
40
41}