Skip to content

Commit 4533e5d

Browse files
Improve NPC logging and entity validation
Added detailed logging for NPC interactions in NPCEventListener and improved entity validation and logging in NPCImpl's nearby follow task. Removed redundant debug logs and ensured checks use npcEntity directly for consistency.
1 parent 8f2a40b commit 4533e5d

2 files changed

Lines changed: 5 additions & 7 deletions

File tree

src/main/kotlin/cc/modlabs/kpaper/npc/NPCEventListener.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cc.modlabs.kpaper.npc
22

33
import cc.modlabs.kpaper.event.listen
44
import cc.modlabs.kpaper.extensions.timer
5+
import cc.modlabs.kpaper.util.getLogger
56
import org.bukkit.entity.Player
67
import org.bukkit.event.entity.EntityDamageByEntityEvent
78
import org.bukkit.event.player.PlayerAnimationEvent
@@ -41,6 +42,7 @@ object NPCEventListener {
4142
val npc = npcMap[entity] ?: return@listen
4243
val player = event.player
4344
val isSneaking = player.isSneaking
45+
getLogger().info("Interacted with NPC $npc for player $player ($isSneaking) - ${event.hand.name}")
4446

4547
// Check if NPC has a conversation and start it (only on normal right-click, not shift-click)
4648
if (!isSneaking && npc.getConversation() != null) {

src/main/kotlin/cc/modlabs/kpaper/npc/NPCImpl.kt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -640,9 +640,6 @@ class NPCImpl(
640640
// Start monitoring task - this will run continuously every nearbyFollowCheckInterval ticks
641641
logDebug("[NPC] followNearbyPlayers: Starting monitoring task with interval=$nearbyFollowCheckInterval ticks (${nearbyFollowCheckInterval * 50}ms)")
642642
nearbyFollowTask = timer(nearbyFollowCheckInterval, "NPCNearbyFollow") {
643-
// Log every tick to confirm task is running
644-
logDebug("[NPC] NearbyFollow task: [TICK START] isFollowingNearbyPlayers=$isFollowingNearbyPlayers")
645-
646643
// Wrap everything in try-catch to ensure task never stops on error
647644
try {
648645
// Only cancel if explicitly stopped
@@ -653,14 +650,13 @@ class NPCImpl(
653650
return@timer
654651
}
655652

656-
val currentEntity = getMannequin() as? LivingEntity
657-
if (currentEntity == null || !currentEntity.isValid) {
658-
logDebug("[NPC] NearbyFollow task: Entity invalid, but continuing to check")
653+
if (!npcEntity.isValid) {
654+
logDebug("[NPC] NearbyFollow task: Entity for ${npcEntity.name} invalid, but continuing to check")
659655
// Don't stop the task, just skip this tick
660656
return@timer
661657
}
662658

663-
val npcLocation = currentEntity.location
659+
val npcLocation = npcEntity.location
664660
val npcWorld = npcLocation.world
665661
if (npcWorld == null) {
666662
logDebug("[NPC] NearbyFollow task: World is null, but continuing to check")

0 commit comments

Comments
 (0)