Skip to content

Report the initiating user in PreTeleportEvent for /tp, /tpo, /tpohere and /tpall - #6652

Open
1wairesd wants to merge 1 commit into
EssentialsX:2.xfrom
1wairesd:feat/now-teleporter
Open

1wairesd wants to merge 1 commit into
EssentialsX:2.xfrom
1wairesd:feat/now-teleporter

Conversation

@1wairesd

Copy link
Copy Markdown
Contributor

Information

There is no separate feature request; this is related to #4673 and #6651. TeleportEvent#getTeleporter() is documented as "the user that initiated the teleportation", but for teleports that go through IAsyncTeleport#now it is always the teleportee.

Details

Proposed feature:

/tpo <a> <b>, /tpohere, /tp <a> <b>, /tp <player> <x> <y> <z> and /tpall call target.getAsyncTeleport().now(...) on the teleported player. AsyncTeleport has no way to know who ran the command, so PreTeleportEvent#getTeleporter() reports the teleportee. A listener cannot tell which player to inform or check permissions for.

Changes:

  • IAsyncTeleport: new now(IUser teleporter, Location, ...) and now(IUser teleporter, Player, ...) overloads. They are default methods that delegate to the existing ones, so other implementations do not break.
  • PreTeleportEvent: new constructor with an explicit teleporter (same as TeleportWarmupEvent already has).
  • AsyncTeleport: the existing now(...) methods call the new ones with null; nowAsync gets an overload with the teleporter. When the teleporter is null, the teleportee is reported, as before.
  • AsyncTimedTeleport: when a warmup finishes, the warmup owner is reported as the teleporter (this matters for /tphere once Fix TeleportWarmupEvent teleporter for /tphere, /tpaccept and /warp <player> #6651 is merged).
  • /tp, /tpo, /tpohere, /tpall pass the command sender when it is a player. Console usage still reports the teleportee.

No behaviour changes besides the value of getTeleporter().

Environments tested:

OS: Windows

Java version: OpenJDK 25.0.5 (build), ./gradlew :EssentialsX:build passes (checkstyle and unit tests)

  • Most recent Paper version (XX.YY.Z, git-Paper-BUILD)
  • CraftBukkit/Spigot/Paper 1.12.2
  • CraftBukkit 1.8.8

Demonstration:

Example use: a plugin that blocks teleports into a protected world and tells the player who ran the command.

@EventHandler(ignoreCancelled = true)
public void onPreTeleport(PreTeleportEvent event) {
    Player teleportee = event.getTeleportee().getBase();
    Location to = event.getTarget().getLocation();
    if (to != null && isProtected(to.getWorld()) && !isProtected(teleportee.getWorld())) {
        event.setCancelled(true);
        // before: always the teleportee; after: the player who ran /tpo, /tpohere, /tp a b, /tpall
        event.getTeleporter().getBase().sendMessage("You can't teleport " + teleportee.getName() + " there.");
    }
}

A runs /tpohere B:

  • before: getTeleporter() = B
  • after: getTeleporter() = A

…e, /tpall

Add IAsyncTeleport#now overloads taking the teleporter (default methods, so the API stays
compatible), pass the command sender from /tp <a> <b>, /tp <player> <x y z>, /tpo <a> <b>,
/tpohere and /tpall, and report the warmup owner as teleporter when a timed teleport fires.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant