Skip to content
Open
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 @@ -1317,7 +1317,19 @@ protected boolean teleport0(Location location, org.bukkit.event.player.PlayerTel
return false;
}

return super.teleport0(location, cause, flags);
Entity camera = this.getHandle().getCamera();
this.getHandle().setCamera(null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like in most cases (except one) where camera is reset it uses setCamera(self), so you may want to setCamera(this.getHandle())

if (this.getHandle() != this.getHandle().getCamera()) {
// If the camera is not the player after setting, the stop spectating event was likely cancelled, so stop the teleport
return false;
}
Comment on lines +1322 to +1325
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kind of prompts additional conversation, but we may want to instead just have some kind of boolean on the set camera to ignore the canceling of those events. As there is a lot of places where this can occur and I don't really think we handle this logic at all (and instead just allow them to be teleported back a tick later or whatever)


boolean teleported = super.teleport0(location, cause, flags);
if (!teleported) {
// If the teleport doesn't go through, restore the original camera
this.getHandle().setCamera(camera);
}
return teleported;
}

@Override
Expand Down
Loading