PaperMC / PaperMC/Paper

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

Open
#10,249 5 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: blocked type: bug upstream: vanilla
Dominant language
Java
Stars
12.7k
Forks
3.5k
Avg merge
3d 13h
Merged PRs (30d)
11

Description

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.

https://github.com/PaperMC/Paper/assets/16448318/f2fd9157-dab3-40de-a37c-50bc2eebcfe8

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with Player#setSpectatorTarget and reproduce the behavior using the plugin code in the issue on Paper 1.20.4. Compare the API result with selecting a target from the spectator client; done means the spectator camera remains attached to the target rather than merely teleporting to its location.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.