Teleportation of a player is not possible if a passenger is set. #352

Closed
opened 2025-04-22 18:52:10 +02:00 by NicklasMatzulla · 1 comment
NicklasMatzulla commented 2025-04-22 18:52:10 +02:00 (Migrated from github.com)

Expected behavior

if I use the normal /teleport command, and the player has a passenger set on which he is sitting, he cannot be teleported. Teleportation with coordinates, in my test with relative coordinates (/teleport ~ ~10 ~) is possible again.

Observed/Actual behavior

The player will not be teleported, if an passenger is set.

Steps/models to reproduce

I have the following code as an example for reconstruction:

/*
 * Copyright (c) 2024-2025 LimitMedia
 */

package net.playunlimited.limitattack.commands;

import com.mojang.brigadier.Command;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.tree.LiteralCommandNode;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.Commands;
import lombok.AllArgsConstructor;
import net.kyori.adventure.text.Component;
import net.playunlimited.limitattack.config.MessagesConfig;
import net.playunlimited.limitcore.api.paper.config.placeholder.IPlaceholderManager;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDismountEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.jetbrains.annotations.NotNull;

@SuppressWarnings({"unused", "UnstableApiUsage", "DuplicatedCode", "SameReturnValue"})
@AllArgsConstructor
public class SitCommand implements Listener {
    private final IPlaceholderManager placeholderManager;
    private final MessagesConfig messagesConfig;

    public @NotNull LiteralCommandNode<CommandSourceStack> createBrigadierCommand() {
        return Commands.literal("sit")
                .executes(this::executeBase)
                .build();
    }

    private int executeBase(final @NotNull CommandContext<CommandSourceStack> context) {
        final CommandSender commandSender = context.getSource().getSender();
        if (!(commandSender instanceof final Player player)) {
            final Component rawOnlyPlayerMessage = Component.text("<only_player>");
            final Component onlyPlayerMessage = this.placeholderManager.process(rawOnlyPlayerMessage);
            commandSender.sendMessage(onlyPlayerMessage);
            return Command.SINGLE_SUCCESS;
        }
        final Entity vehicle = player.getVehicle();
        if (vehicle != null) {
            player.leaveVehicle();
            return Command.SINGLE_SUCCESS;
        }
        final Material groundMaterial = player.getLocation().subtract(0, 0.5, 0).getBlock().getType();
        if (groundMaterial == Material.AIR) {
            final Component notOnGroundMessage = this.messagesConfig.getSitNotOnGroundMessage();
            player.sendMessage(notOnGroundMessage);
            return Command.SINGLE_SUCCESS;
        }
        final Location location = player.getLocation();
        location.setY(location.getY() - 0.9);
        final ArmorStand armorStand = player.getWorld().spawn(location, ArmorStand.class, entity -> {
            entity.setSmall(true);
            entity.setVisible(false);
            entity.setGravity(false);
            entity.addPassenger(player);
        });
        final Component satDownMessage = this.messagesConfig.getSitSatDownMessage();
        player.sendMessage(satDownMessage);
        return Command.SINGLE_SUCCESS;
    }

    @EventHandler
    public void onPlayerQuitEvent(final @NotNull PlayerQuitEvent event) {
        final Player player = event.getPlayer();
        final Entity vehicle = player.getVehicle();
        if (vehicle instanceof final ArmorStand armorStand) {
            armorStand.remove();
            final Location playerLocation = player.getLocation();
            playerLocation.setY(playerLocation.getY() + 0.9);
            player.teleportAsync(playerLocation);
            final Component satUpMessage = this.messagesConfig.getSitSatUpMessage();
            player.sendMessage(satUpMessage);
        }
    }

    @EventHandler
    public void onEntityDismountEvent(final @NotNull EntityDismountEvent event) {
        final Entity playerEntity = event.getEntity();
        final Entity vehicle = event.getDismounted();
        if (playerEntity instanceof final Player player && vehicle instanceof final ArmorStand armorStand) {
            armorStand.remove();
            final Location playerLocation = player.getLocation();
            playerLocation.setY(playerLocation.getY() + 0.9);
            player.teleportAsync(playerLocation);
            final Component satUpMessage = this.messagesConfig.getSitSatUpMessage();
            player.sendMessage(satUpMessage);
        }
    }

}

Plugin and Datapack List

[18:50:59 INFO]: Server Plugins (15):
[18:50:59 INFO]: Paper Plugins:
[18:50:59 INFO]: - LimitAttack, LimitCore, LimitSMP, ServerSystem
[18:50:59 INFO]: Bukkit Plugins:
[18:50:59 INFO]: - CoreProtect, floodgate, FoliaFlow, GrimAC, LuckPerms, Plan, ProtocolLib, SayanVanish, spark, voicechat
[18:50:59 INFO]: WorldEdit

The datapack function is not implemented yet.

Folia version

[18:51:46 INFO]: This server is running Folia version 1.21.4-1-master@8af1aef (2024-12-15T21:04:38Z) (Implementing API version 1.21.4-R0.1-SNAPSHOT)
You are running the latest version
Previous version: 1.21.4-DEV-8af1aef (MC: 1.21.4)

Other

No response

### Expected behavior if I use the normal /teleport <player> <player> command, and the player has a passenger set on which he is sitting, he cannot be teleported. Teleportation with coordinates, in my test with relative coordinates (/teleport <player> ~ ~10 ~) is possible again. ### Observed/Actual behavior The player will not be teleported, if an passenger is set. ### Steps/models to reproduce I have the following code as an example for reconstruction: ```java /* * Copyright (c) 2024-2025 LimitMedia */ package net.playunlimited.limitattack.commands; import com.mojang.brigadier.Command; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.tree.LiteralCommandNode; import io.papermc.paper.command.brigadier.CommandSourceStack; import io.papermc.paper.command.brigadier.Commands; import lombok.AllArgsConstructor; import net.kyori.adventure.text.Component; import net.playunlimited.limitattack.config.MessagesConfig; import net.playunlimited.limitcore.api.paper.config.placeholder.IPlaceholderManager; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.command.CommandSender; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDismountEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerTeleportEvent; import org.jetbrains.annotations.NotNull; @SuppressWarnings({"unused", "UnstableApiUsage", "DuplicatedCode", "SameReturnValue"}) @AllArgsConstructor public class SitCommand implements Listener { private final IPlaceholderManager placeholderManager; private final MessagesConfig messagesConfig; public @NotNull LiteralCommandNode<CommandSourceStack> createBrigadierCommand() { return Commands.literal("sit") .executes(this::executeBase) .build(); } private int executeBase(final @NotNull CommandContext<CommandSourceStack> context) { final CommandSender commandSender = context.getSource().getSender(); if (!(commandSender instanceof final Player player)) { final Component rawOnlyPlayerMessage = Component.text("<only_player>"); final Component onlyPlayerMessage = this.placeholderManager.process(rawOnlyPlayerMessage); commandSender.sendMessage(onlyPlayerMessage); return Command.SINGLE_SUCCESS; } final Entity vehicle = player.getVehicle(); if (vehicle != null) { player.leaveVehicle(); return Command.SINGLE_SUCCESS; } final Material groundMaterial = player.getLocation().subtract(0, 0.5, 0).getBlock().getType(); if (groundMaterial == Material.AIR) { final Component notOnGroundMessage = this.messagesConfig.getSitNotOnGroundMessage(); player.sendMessage(notOnGroundMessage); return Command.SINGLE_SUCCESS; } final Location location = player.getLocation(); location.setY(location.getY() - 0.9); final ArmorStand armorStand = player.getWorld().spawn(location, ArmorStand.class, entity -> { entity.setSmall(true); entity.setVisible(false); entity.setGravity(false); entity.addPassenger(player); }); final Component satDownMessage = this.messagesConfig.getSitSatDownMessage(); player.sendMessage(satDownMessage); return Command.SINGLE_SUCCESS; } @EventHandler public void onPlayerQuitEvent(final @NotNull PlayerQuitEvent event) { final Player player = event.getPlayer(); final Entity vehicle = player.getVehicle(); if (vehicle instanceof final ArmorStand armorStand) { armorStand.remove(); final Location playerLocation = player.getLocation(); playerLocation.setY(playerLocation.getY() + 0.9); player.teleportAsync(playerLocation); final Component satUpMessage = this.messagesConfig.getSitSatUpMessage(); player.sendMessage(satUpMessage); } } @EventHandler public void onEntityDismountEvent(final @NotNull EntityDismountEvent event) { final Entity playerEntity = event.getEntity(); final Entity vehicle = event.getDismounted(); if (playerEntity instanceof final Player player && vehicle instanceof final ArmorStand armorStand) { armorStand.remove(); final Location playerLocation = player.getLocation(); playerLocation.setY(playerLocation.getY() + 0.9); player.teleportAsync(playerLocation); final Component satUpMessage = this.messagesConfig.getSitSatUpMessage(); player.sendMessage(satUpMessage); } } } ``` ### Plugin and Datapack List [18:50:59 INFO]: Server Plugins (15): [18:50:59 INFO]: Paper Plugins: [18:50:59 INFO]: - LimitAttack, LimitCore, LimitSMP, ServerSystem [18:50:59 INFO]: Bukkit Plugins: [18:50:59 INFO]: - CoreProtect, floodgate, FoliaFlow, GrimAC, LuckPerms, Plan, ProtocolLib, SayanVanish, spark, voicechat [18:50:59 INFO]: WorldEdit The datapack function is not implemented yet. ### Folia version [18:51:46 INFO]: This server is running Folia version 1.21.4-1-master@8af1aef (2024-12-15T21:04:38Z) (Implementing API version 1.21.4-R0.1-SNAPSHOT) You are running the latest version Previous version: 1.21.4-DEV-8af1aef (MC: 1.21.4) ### Other _No response_
MiniDigger commented 2025-04-29 11:30:26 +02:00 (Migrated from github.com)
you have to set teleport flags https://jd.papermc.io/paper/1.21.5/org/bukkit/entity/Entity.html#teleportAsync(org.bukkit.Location,org.bukkit.event.player.PlayerTeleportEvent.TeleportCause,io.papermc.paper.entity.TeleportFlag...)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Minecraft/Folia#352
No description provided.