PaperMC / PaperMC/Paper

Overriding player movement in PlayerMoveEvent causes a PlayerTeleportEvent

Open
#8,144 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Expected behavior

If I override player movement in a PlayerMoveEvent, it should not call a PlayerTeleportEvent. I believe this is a genuine oversight, while it is niche I do believe it needs to be addressed for consistency

@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
        // Why does this call PlayerTeleportEvent ?
        Location to = event.getFrom();
        to.setPitch(event.getTo().getPitch());
        to.setYaw(event.getTo().getYaw());
        event.setTo(to);
}
Observed/Actual behavior

When using the above logic to override the player movement, it calls PlayerTeleportEvent,

Steps/models to reproduce
public class Main extends JavaPlugin implements Listener {
    private static boolean shouldFreeze = false;

    @Override
    public void onEnable() {
        getServer().getPluginManager().registerEvents(this, this);

        getServer().getScheduler().runTaskTimerAsynchronously(this, () -> {
            shouldFreeze = !shouldFreeze;
        }, 20, 100);
    }

    @EventHandler(priority = EventPriority.MONITOR)
    public void onPlayerTeleport(PlayerTeleportEvent event) {
        getServer().broadcastMessage(event.getCause().toString());
    }

    @EventHandler
    public void onPlayerMove(PlayerMoveEvent event) {
        if(shouldFreeze) {
            // Why does this call a teleport event?
            Location to = event.getFrom();
            to.setPitch(event.getTo().getPitch());
            to.setYaw(event.getTo().getYaw());
            event.setTo(to);
        }
    }

}
Plugin and Datapack List

N/A

Paper version

[01:23:50 INFO]: This server is running Paper version git-Paper-61 (MC: 1.19) (Implementing API version 1.19-R0.1-SNAPSHOT) (Git: cd215af)
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 by reproducing the supplied listener with PlayerMoveEvent and PlayerTeleportEvent on the reported Paper 1.19 version. Trace how changing PlayerMoveEvent#setTo produces the teleport event, then verify that movement overrides no longer emit PlayerTeleportEvent while genuine teleports still do.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, game-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.