Skip to content

Commit 048fb8d

Browse files
Merge pull request #6 from SLNE-Development/fix/add-right-click-interact-function
Fix/add right click interact function
2 parents 0a72a84 + aced4a8 commit 048fb8d

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
kotlin.code.style=official
22
kotlin.stdlib.default.dependency=false
33
org.gradle.parallel=true
4-
version=1.21.7-1.2.0-SNAPSHOT
4+
version=1.21.7-1.2.1-SNAPSHOT

surf-npc-bukkit/src/main/kotlin/dev/slne/surf/npc/bukkit/listener/NpcListener.kt

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package dev.slne.surf.npc.bukkit.listener
33
import com.github.retrooper.packetevents.event.PacketListener
44
import com.github.retrooper.packetevents.event.PacketReceiveEvent
55
import com.github.retrooper.packetevents.protocol.packettype.PacketType
6+
import com.github.retrooper.packetevents.protocol.player.InteractionHand
67
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientInteractEntity
78
import com.github.shynixn.mccoroutine.folia.entityDispatcher
89
import com.github.shynixn.mccoroutine.folia.launch
@@ -59,15 +60,31 @@ class NpcListener : PacketListener {
5960
val packet = WrapperPlayClientInteractEntity(event)
6061
val npc = npcController.getNpc(packet.entityId) ?: return
6162

62-
if (packet.action != WrapperPlayClientInteractEntity.InteractAction.ATTACK) {
63-
return
64-
}
63+
when (packet.action) {
64+
WrapperPlayClientInteractEntity.InteractAction.ATTACK -> {
65+
plugin.launch(plugin.entityDispatcher(player)) {
66+
NpcInteractEvent(
67+
npc,
68+
player
69+
).callEvent()
70+
}
71+
}
72+
73+
WrapperPlayClientInteractEntity.InteractAction.INTERACT -> {
74+
if (packet.hand != InteractionHand.MAIN_HAND) {
75+
return
76+
}
6577

66-
plugin.launch(plugin.entityDispatcher(player)) {
67-
NpcInteractEvent(
68-
npc,
69-
player
70-
).callEvent()
78+
plugin.launch(plugin.entityDispatcher(player)) {
79+
NpcInteractEvent(
80+
npc,
81+
player
82+
).callEvent()
83+
}
84+
}
85+
WrapperPlayClientInteractEntity.InteractAction.INTERACT_AT -> {
86+
// This is already handled by INTERACT action, so we can ignore it.
87+
}
7188
}
7289
}
7390
}

0 commit comments

Comments
 (0)