-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Add PlayerPrepareTeleportEvent #14184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ThatTransSky
wants to merge
6
commits into
PaperMC:main
Choose a base branch
from
ThatTransSky:PlayerPrepareTeleportEvent
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+105
−0
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
900e3ea
Add PlayerPrepareTeleportEvent
ThatTransSky 374c195
Added PlayerPrepareTeleportEvent overloads
ThatTransSky 7317109
Ensure Immutability of teleportFlags
ThatTransSky d93cb5c
Replace ImmutableSet with Set
ThatTransSky 9e9ae1e
Merge branch 'PaperMC:main' into PlayerPrepareTeleportEvent
ThatTransSky 2bf8b8f
Merge branch 'PaperMC:main' into PlayerPrepareTeleportEvent
ThatTransSky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
98 changes: 98 additions & 0 deletions
98
paper-api/src/main/java/io/papermc/paper/event/player/PlayerPrepareTeleportEvent.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| package io.papermc.paper.event.player; | ||
|
|
||
| import io.papermc.paper.entity.TeleportFlag; | ||
| import java.util.Collections; | ||
| import java.util.Set; | ||
| import org.bukkit.Location; | ||
| import org.bukkit.entity.Player; | ||
| import org.bukkit.event.HandlerList; | ||
| import org.bukkit.event.player.PlayerEvent; | ||
| import org.bukkit.event.player.PlayerTeleportEvent; | ||
| import org.jetbrains.annotations.ApiStatus; | ||
| import org.jetbrains.annotations.Unmodifiable; | ||
| import org.jspecify.annotations.NullMarked; | ||
|
|
||
| /** | ||
| * Event that is fired before attempting to teleport a player (Allows for pre-teleport handling, such as dismounting passengers if teleporting cross-worlds etc.) | ||
| * <p> | ||
| * After the handling of this event, the player will attempt to teleport to the given location. | ||
| */ | ||
| @NullMarked | ||
| public class PlayerPrepareTeleportEvent extends PlayerEvent { | ||
|
|
||
| private static final HandlerList HANDLER_LIST = new HandlerList(); | ||
|
|
||
| private final Location to; | ||
| private final PlayerTeleportEvent.TeleportCause cause; | ||
| private final Set<TeleportFlag> teleportFlags; | ||
|
|
||
| @ApiStatus.Internal | ||
| public PlayerPrepareTeleportEvent(final Player player, Location to) { | ||
| super(player); | ||
| this.to = to; | ||
| this.cause = PlayerTeleportEvent.TeleportCause.PLUGIN; | ||
| this.teleportFlags = Collections.emptySet(); | ||
| } | ||
|
|
||
| @ApiStatus.Internal | ||
| public PlayerPrepareTeleportEvent(final Player player, Location to, PlayerTeleportEvent.TeleportCause cause) { | ||
| super(player); | ||
| this.to = to; | ||
| this.cause = cause; | ||
| this.teleportFlags = Collections.emptySet(); | ||
| } | ||
|
|
||
| @ApiStatus.Internal | ||
| public PlayerPrepareTeleportEvent(final Player player, Location to, PlayerTeleportEvent.TeleportCause cause, Set<TeleportFlag> teleportFlags) { | ||
| super(player); | ||
| this.to = to; | ||
| this.cause = cause; | ||
| this.teleportFlags = Set.copyOf(teleportFlags); | ||
| } | ||
|
|
||
| /** | ||
| * Gets the location this player is teleporting to | ||
| * | ||
| * @return A copy of the Location the player is teleporting to | ||
| */ | ||
| public Location getTo() { | ||
| return this.to.clone(); | ||
| } | ||
|
|
||
| /** | ||
| * Gets the location this player is teleporting from | ||
| * | ||
| * @return A copy of the Location the player is moving from | ||
| */ | ||
| public Location getFrom() { | ||
| return this.getPlayer().getLocation(); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the relative teleportation flags used in this teleportation. | ||
| * This determines which axis the player will not lose their velocity in. | ||
| * | ||
| * @return an immutable set of relative teleportation flags | ||
| */ | ||
| public @Unmodifiable Set<TeleportFlag> getRelativeTeleportationFlags() { | ||
| return this.teleportFlags; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the cause of this teleportation event | ||
| * | ||
| * @return Cause of the event | ||
| */ | ||
| public PlayerTeleportEvent.TeleportCause getCause() { | ||
| return this.cause; | ||
| } | ||
|
|
||
| @Override | ||
| public HandlerList getHandlers() { | ||
| return HANDLER_LIST; | ||
| } | ||
|
|
||
| public static HandlerList getHandlerList() { | ||
| return HANDLER_LIST; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.