CommandHelper

CommandHelper

46.5k Downloads

Citizens NPCs triggering player_teleport events

LadyCailinBot opened this issue ยท 6 comments

commented

CMDHELPER-3140 - Reported by Murreey

When the server loads up, console gets spammed with "PlayerOfflineException" errors from NPCs that are triggering player_teleport events. The error only comes from events that immediately use pworld() to check where a player is so they throw the PlayerOfflineException, but presumably it is also triggering every other teleport event and they're just exiting safely.

I know I could solve it by just checking the player is online first (or using the 'from' in the event data), but it still seems like a bug that NPCs should be triggering that event at all.

Using CH build #3152, Citizens2 build #1420 and Spigot git-Spigot-f9671b8-48b88ed.

commented

Comment by PseudoKnight

Ya, I noticed this too. I just stopped using Citizens player NPCs instead of modifying my code. I believe you can also check the Bukkit metadata for the player to see if they're an NPC.

This is not a bug in CH. Whether it's a bug in Spigot or Citizens I can't tell you. It could just be intentional or a necessary byproduct of how they fake players.

commented

Comment by Murreey

@PseudoKnight Damn. Would a solution then possibly be to check the Bukkit metadata in CH, or is that too specific a fix?

commented

Comment by PseudoKnight

That's typically the recommended solution. Most plugins that want to consider NPCs do that, including WorldGuard.

https://github.com/sk89q/WorldGuard/blob/master/worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/util/Entities.java#L169

commented

Comment by PseudoKnight

So I finally got around to doing more thorough tests of this and Player NPCs trigger a ton of events with players in them. I'd probably need to add this check to ~10 locations, just in case a server is using Player NPCs. The metadata check DOES seem to work, though. There were reports that it didn't, but I think that might only happen on reload or something. In any case, I couldn't reproduce that.

commented

This has been fixed on the CH side by just removing the error message.

commented

To put it simply, it ignores events where a Player NPC would be the player().

For example, an entity_damage event won't fire if the damaged entity is a Player NPC. However, a player_interact_entity event will still fire if the interacting player is an online player and the interacted entity is a Player NPC. (ponline() return false for Player NPCs, and they do not get returned in all_players())