Closed rossmcnulty closed 11 years ago
Slight correction, as entity isn't a variable here you'd just have to call that from the Player entity.
Are players getting left behind or are they both teleporting all the time? The entity must be a player to go through that method otherwise it would throw a ClassCastExeption. What plugin do you use for the NPC's?
While not occurring all of the time, both the player and their NPC have gone together to the same location. This has occurred with /bn join, /bn leave, and when the battle begins and players go to the spawn point. I use the Citizens2 NPC plugin, and in cases where NPC names match player names Bukkit has been known to mistakenly believe such NPCs are players (this isn't the first plugin to have such an issue). To clarify, this doesn't cause any issues related to BattleNight, as the events still function properly; it's just inconvenient (and a bit odd) to have NPCs joining the party uninvited.
Hmmm, if they are mistaken to be a player how can you tell if they are or not?
Every NPC is created with the metadata "NPC", which can be accessed through Bukkit with the code listed above. All you'd need to do is check for that metadata each time the teleport method is called, and if it's an NPC just return. That way it won't affect anyone not using the Citizens2 plugin, require any significant dependency changes, nor affect performance.
In instances where the SafeTeleporter instance is called, sometimes both players on my server and the NPCs named after them teleport with them. As this is a commonly used plugin, it'd be great to be able to have this be compatible.
Here's the simple fix:
In the safeTp method here: https://github.com/BattleNight/BattleNight-Core/blob/master/src/main/java/me/limebyte/battlenight/core/util/SafeTeleporter.java#L67
Add the statement: if (entity.hasMetadata("NPC")) return; to the very first line. That's it; it'll prevent NPCs from being teleported by the plugin, and you don't even have to reconfigure any dependencies!
Thanks