Skip to content
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

Add PreTeleportEvents #10173

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
170 changes: 170 additions & 0 deletions patches/api/0475-Add-PreTeleportEvents.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: leguan <[email protected]>
Date: Wed, 17 Jan 2024 19:58:51 +0100
Subject: [PATCH] Add PreTeleportEvents


diff --git a/src/main/java/io/papermc/paper/event/entity/EntityPreTeleportEvent.java b/src/main/java/io/papermc/paper/event/entity/EntityPreTeleportEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..fff2baf06a0061d95d382cf25e633ab84a295b51
--- /dev/null
+++ b/src/main/java/io/papermc/paper/event/entity/EntityPreTeleportEvent.java
@@ -0,0 +1,70 @@
+package io.papermc.paper.event.entity;
+
+import io.papermc.paper.entity.TeleportFlag;
+import org.bukkit.Location;
+import org.bukkit.entity.Entity;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.entity.EntityEvent;
+import org.bukkit.event.player.PlayerTeleportEvent;
+import org.jetbrains.annotations.NotNull;
+import java.util.Collections;
+import java.util.Set;
+
+/**
+ * Called before an {@link Entity} is teleported.
+ * This is helpful if certain preparations have to me made in order for the teleport to happen.
+ */
+public class EntityPreTeleportEvent extends EntityEvent {
+
+ private static final HandlerList HANDLER_LIST = new HandlerList();
+
+ private final Location from;
+ private final Location to;
+ private final Set<TeleportFlag> flags;
+
+ public EntityPreTeleportEvent(@NotNull Entity what, @NotNull Location from, @NotNull Location to) {
+ this(what, from, to, Collections.emptySet());
+ }
+
+ public EntityPreTeleportEvent(@NotNull Entity what, @NotNull Location from, @NotNull Location to, @NotNull Set<TeleportFlag> flags) {
+ super(what);
+ this.from = from;
+ this.to = to;
+ this.flags = flags;
+ }
+
+ /**
+ * Returns a clone of the player's current Location.
+ * @return A clone of the player's current location.
+ */
+ public @NotNull Location getFrom() {
+ return from.clone();
+ }
+
+ /**
+ * Returns a clone of the target location.
+ * @return A clone of the target location.
+ */
+ public @NotNull Location getTo() {
+ return to.clone();
+ }
+
+ /**
+ * Returns the provided flags of the teleport call.
+ * @see TeleportFlag
+ * @return The flags of the teleport call.
+ */
+ public @NotNull Set<TeleportFlag> getFlags() {
+ return flags;
+ }
+
+ @Override
+ public @NotNull HandlerList getHandlers() {
+ return HANDLER_LIST;
+ }
+
+ public static @NotNull HandlerList getHandlerList() {
+ return HANDLER_LIST;
+ }
+
+}
diff --git a/src/main/java/io/papermc/paper/event/player/PlayerPreTeleportEvent.java b/src/main/java/io/papermc/paper/event/player/PlayerPreTeleportEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..8dd919ee1b0e4e130f763cd9feeb5257b07efc3c
--- /dev/null
+++ b/src/main/java/io/papermc/paper/event/player/PlayerPreTeleportEvent.java
@@ -0,0 +1,82 @@
+package io.papermc.paper.event.player;
+
+import io.papermc.paper.entity.TeleportFlag;
+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.NotNull;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Set;
+
+/**
+ * Called before a {@link Player} is teleported.
+ * This is helpful if certain preparations have to me made in order for the teleport to happen.
+ */
+public class PlayerPreTeleportEvent extends PlayerEvent {
+
+ private static final HandlerList HANDLER_LIST = new HandlerList();
+
+ private final Location from;
+ private final Location to;
+ private final PlayerTeleportEvent.TeleportCause cause;
+ private final Set<TeleportFlag> flags;
+
+ public PlayerPreTeleportEvent(@NotNull Player who, @NotNull Location from, @NotNull Location to, PlayerTeleportEvent.@NotNull TeleportCause cause) {
+ this(who, from, to, cause, Collections.emptySet());
+ }
+
+ public PlayerPreTeleportEvent(@NotNull Player who, @NotNull Location from, @NotNull Location to, PlayerTeleportEvent.@NotNull TeleportCause cause, java.util.Set<io.papermc.paper.entity.@NotNull TeleportFlag> flags) {
+ super(who);
+ this.from = from;
+ this.to = to;
+ this.cause = cause;
+ this.flags = flags;
+ }
+
+ /**
+ * Returns a clone of the player's current Location.
+ * @return A clone of the player's current location.
+ */
+ public @NotNull Location getFrom() {
+ return from.clone();
+ }
+
+ /**
+ * Returns a clone of the target location.
+ * @return A clone of the target location.
+ */
+ public @NotNull Location getTo() {
+ return to.clone();
+ }
+
+ /**
+ * Returns the initial cause of the location.
+ * @see org.bukkit.event.player.PlayerTeleportEvent.TeleportCause
+ * @return The initial cause of the location.
+ */
+ public PlayerTeleportEvent.@NotNull TeleportCause getCause() {
+ return cause;
+ }
+
+ /**
+ * Returns the provided flags of the teleport call.
+ * @see TeleportFlag
+ * @return The flags of the teleport call.
+ */
+ public @NotNull Collection<TeleportFlag> getFlags() {
+ return flags;
+ }
+
+ @Override
+ public @NotNull HandlerList getHandlers() {
+ return HANDLER_LIST;
+ }
+
+ public static @NotNull HandlerList getHandlerList() {
+ return HANDLER_LIST;
+ }
+
+}
Loading
Loading