Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Citizens NPCs causing error on PlayerTeleportEvent. #5319

Merged
merged 1 commit into from
Sep 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,10 @@ public void onPlayerMove(PlayerMoveEvent event) {
event.setCancelled(true);
return;
}
// Let's ignore Citizens NPCs
if (plugin.isCitizens2() && CitizensAPI.getNPCRegistry().isNPC(event.getPlayer())) {
return;
}
TownyUniverse townyUniverse = TownyUniverse.getInstance();

/*
Expand Down Expand Up @@ -650,7 +654,6 @@ public void onPlayerMove(PlayerMoveEvent event) {

@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerTeleport(PlayerTeleportEvent event) {

if (plugin.isError()) {
// Citizens stores their NPCs at the world spawn and when players load chunks the NPC is teleported there.
// Towny was preventing them being teleported and causing NPCs to be at a world spawn, even after the Safe Mode was cleaned up.
Expand All @@ -659,6 +662,11 @@ public void onPlayerTeleport(PlayerTeleportEvent event) {
event.setCancelled(true);
return;
}

// Let's ignore Citizens NPCs
if (plugin.isCitizens2() && CitizensAPI.getNPCRegistry().isNPC(event.getPlayer())) {
return;
}

Player player = event.getPlayer();
Resident resident = TownyUniverse.getInstance().getResident(player.getUniqueId());
Expand Down Expand Up @@ -724,8 +732,9 @@ public void onPlayerTeleport(PlayerTeleportEvent event) {
/*
* Remove spawn protection if the player is teleporting since spawning.
*/
if (resident.getSpawnProtectionTaskID() != 0)
if (resident != null && resident.getSpawnProtectionTaskID() != 0) {
resident.removeSpawnProtection();
}

onPlayerMove(event);
}
Expand Down