Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-7785

Teleporting a player at the right moment can mess up vanilla teleportation

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • None
    • None
    • None
    • Running on windows 10, Java 21 (jbr_jcef-21.0.3-windows-x64-b465).

      Only running with test plugin.

    • This server is running CraftBukkit version 4223-Spigot-146439e-d01c70e (MC: 1.21) (Implementing API version 1.21-R0.1-SNAPSHOT)
    • Yes

      Expected behavior

      The vanilla teleportation behavior should either:

      1. Send the player to a different dimension, and to the right location, as if the player teleported from the location that triggered this event.
      2. Not trigger at all, as the player nolonger is at the original location

      Observed/Actual behavior

      In some cases the player teleports monodimensionally (Race condition?), also generating a destination portal, if necessary.

      Steps/models to reproduce

      Monodimensionall travel can be reproduced with this minimal(ish) reproducible script:

      @EventHandler
          void onPlayerMove(PlayerMoveEvent event) {
              Location to = event.getTo();
              Location from = event.getFrom();
              if (from.getBlockX() == to.getBlockX() &&
                      from.getBlockY() == to.getBlockY() &&
                      from.getBlockZ() == to.getBlockZ()) {
                  return;
              }
              Material toType = to.getBlock().getType();
              if (!Tag.PORTALS.isTagged(toType) || toType == Material.END_GATEWAY) {
                  return;
              }
              World originWorld = to.getWorld();
              World targetWorld = switch (originWorld.getName()) {
                  case "world" -> {
                      if (toType == Material.END_PORTAL) {
                          yield Bukkit.getWorld("world_the_end");
                      }
                      yield Bukkit.getWorld("world_nether");
                  }
                  default -> Bukkit.getWorld("world");
              };
              Bukkit.getScheduler().runTask(this, () -> {
                  event.getPlayer().teleport(new Location(targetWorld, to.getBlockX(), to.getBlockX(), to.getBlockZ()));
              });
          } 

      To reproduce

      1. Start a new server with default world names with a plugin that contains the given script
      2. Make a nether portal
      3. Go through the nether portal in creative mode (not flying)

       

       

      Other

      Probably reproducible for entities as well. Can probably also be reproducible with end portals

            Unassigned Unassigned
            Thorinwasher Hjalmar Gunnarsson
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: