Skip to content

When a player has a bit of delay to the server, MoveEntityEvent.setDestinationPosition teleports the player to the wrong position. #4271

@abola2

Description

@abola2

Affected Product(s)

SpongeVanilla

Version

1.21.10-17.0.0-RC2492

Operating System

Linux

Java Version

21

Plugins/Mods

Test plugin

Describe the bug

private ServerLocation pos = null;
    
    @Listener
    void onMove(MoveEntityEvent event, @Getter("entity") ServerPlayer player) {
        if (player.world().block(event.destinationPosition().toInt()).type() == BlockTypes.WATER.get()) {
            player.sendMessage(Component.text("water hit"));
            event.setDestinationPosition(pos.position());
        }
    }

    @Listener
    public void onRegisterCommands(final RegisterCommandEvent<Command.Parameterized> event) {
        event.register(this.container, Command.builder().permission("teleporttest.command.greet").executor(ctx -> {
            var player = ctx.cause().last(ServerPlayer.class).orElseThrow();
            pos = player.serverLocation();
            ctx.sendMessage(Component.text("true"));


            return CommandResult.success();
        }).build(), "setenable");
        
    }

When a player has a bit of delay to the server, MoveEntityEvent.setDestinationPosition teleports the player to the wrong position. I have tested this on a vanilla client, so it is not caused by client-side mods.

Video_2026-01-10_12-25-08.mp4

Link to logs

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: needs triageThis label is automatically applied to new issues and pull requests to indicate they require triagetype: bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions