Player#setSpectatorTarget does not "attach" the spectator to it's target
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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