RuneHive-Game
Loading...
Searching...
No Matches
ItemOnNpcEvent.kt
Go to the documentation of this file.
1package org.jire.runehiveps.event.npc
2
3import com.runehive.game.event.impl.ItemOnNpcEvent
4import com.runehive.game.plugin.PluginManager
5import com.runehive.game.world.World
6import com.runehive.game.world.entity.mob.player.Player
7import com.runehive.net.packet.out.SendMessage
8import kotlin.jvm.optionals.getOrNull
9
10/**
11 * @author Jire
12 */
13class ItemOnNpcEvent(
14 val itemId: Int,
15 val index: Int,
16 val slot: Int
17) : NpcEvent {
18
19 override fun handle(player: Player) {
20 val used = player.inventory[slot] ?: return
21 if (!used.matchesId(itemId)) return
22
23 val npc = World.getNpcBySlot(index).getOrNull() ?: return
24 if (!npc.isValid) return
25
26 val position = npc.position
27 val region = World.getRegions().getRegion(position)
28 if (!region.containsNpc(position.height, npc)) return
29
30 player.walkTo(npc) {
31 player.face(position)
32 if (!PluginManager.getDataBus().publish(player, ItemOnNpcEvent(npc, used, slot))) {
33 player.send(SendMessage("Nothing interesting happens."))
34 }
35 }
36 }
37
38}