Skip to content

Player#setSpectatorTarget does not "attach" the spectator to it's target #10249

@n-aspen

Description

@n-aspen

Expected behavior

Using Player#setSpectatorTarget to target a player would attach the spectator's camera to the player in the same way that the spectator clicking on the player from their client would.

Observed/Actual behavior

Using Player#setSpectatorTarget to target a player teleports the spectator to the target player's location and then will teleport them again when the target player gets too far away. The spectator player isn't following the target's player camera and isn't "attached" to the player.

Steps/models to reproduce

I made a basic plugin that just runs the following code when the target player joins, which uses the Player#setSpectatorTarget method on the spectatorPlayer to target the targetPlayer.

class PlayerJoinEventListener implements Listener {
    UUID spectatorPlayer = UUID.fromString("04fbb67a-02ef-437b-be73-c04fab4f3b43");
    UUID targetPlayer = UUID.fromString("bf8b08a5-714c-4667-8f49-efce56cb7dc5");

    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent event){
        if(event.getPlayer().getUniqueId().equals(targetPlayer)){
            Bukkit.getServer().getPlayer(spectatorPlayer).setSpectatorTarget(event.getPlayer());
        }
    }
}

Attached is a video of this code running with the spectatorPlayer starting in the exact same position that the targetPlayer joins into because of a previously failed spectate.

2024-02-13.19-11-21.mp4

Plugin and Datapack List

Only the above mentioned test plugin

Paper version

This server is running Paper version git-Paper-423 (MC: 1.20.4) (Implementing API version 1.20.4-R0.1-SNAPSHOT) (Git: 31699ae)
You are running the latest version

Other

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: blockedIssue or Request is waiting on some other issue or change.type: bugSomething doesn't work as it was intended to.upstream: vanillaIssue exists in vanilla Minecraft.

    Type

    No fields configured for Bug.

    Projects

    Status

    Needs Work

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions