From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: MrHua269 Date: Fri, 31 Jan 2025 20:28:47 +0800 Subject: [PATCH] Add missing teleportation apis for folia diff --git a/src/main/java/me/earthme/luminol/api/entity/EntityTeleportAsyncEvent.java b/src/main/java/me/earthme/luminol/api/entity/EntityTeleportAsyncEvent.java new file mode 100644 index 0000000000000000000000000000000000000000..a31c803831dad3d31386924cbe27deff59855fc9 --- /dev/null +++ b/src/main/java/me/earthme/luminol/api/entity/EntityTeleportAsyncEvent.java @@ -0,0 +1,68 @@ +package me.earthme.luminol.api.entity; + +import org.apache.commons.lang3.Validate; +import org.bukkit.Location; +import org.bukkit.entity.Entity; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.bukkit.event.player.PlayerTeleportEvent; +import org.jetbrains.annotations.NotNull; + +/** + * A simple event fired when a teleportAsync was called + * @see org.bukkit.entity.Entity#teleportAsync(org.bukkit.Location, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause) + * @see org.bukkit.entity.Entity#teleportAsync(org.bukkit.Location) + * (Also fired when teleportAsync called from nms) + */ +public class EntityTeleportAsyncEvent extends Event { + private static final HandlerList HANDLERS = new HandlerList(); + + private final Entity entity; + private final PlayerTeleportEvent.TeleportCause teleportCause; + private final Location destination; + + public EntityTeleportAsyncEvent(Entity entity, PlayerTeleportEvent.TeleportCause teleportCause, Location destination) { + Validate.notNull(entity, "entity cannot be a null value!"); + Validate.notNull(teleportCause, "teleportCause cannot be a null value!"); + Validate.notNull(destination, "destination cannot be a null value!"); + + this.entity = entity; + this.teleportCause = teleportCause; + this.destination = destination; + } + + /** + * Get the entity is about to be teleported + * @return that entity + */ + public @NotNull Entity getEntity() { + return this.entity; + } + + /** + * Get the cause of the teleport + * @return the cause + */ + public @NotNull PlayerTeleportEvent.TeleportCause getTeleportCause() { + return this.teleportCause; + } + + /** + * Get the destination of the teleport + * @return the destination + */ + public @NotNull Location getDestination() { + return this.destination; + } + + @Override + public @NotNull HandlerList getHandlers() { + return HANDLERS; + } + + @NotNull + public static HandlerList getHandlerList() { + return HANDLERS; + } +} diff --git a/src/main/java/me/earthme/luminol/api/entity/PostEntityPortalEvent.java b/src/main/java/me/earthme/luminol/api/entity/PostEntityPortalEvent.java new file mode 100644 index 0000000000000000000000000000000000000000..dd3087b407ccf4e96448701e6fbf75705498f982 --- /dev/null +++ b/src/main/java/me/earthme/luminol/api/entity/PostEntityPortalEvent.java @@ -0,0 +1,41 @@ +package me.earthme.luminol.api.entity; + +import org.apache.commons.lang3.Validate; +import org.bukkit.entity.Entity; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +/** + * A simple event created for missing teleport events api of folia + * This event is fired when the entity portal process has been done + */ +public class PostEntityPortalEvent extends Event { + private static final HandlerList HANDLER_LIST = new HandlerList(); + + private final Entity teleportedEntity; + + public PostEntityPortalEvent(Entity teleportedEntity) { + Validate.notNull(teleportedEntity, "teleportedEntity cannot be null!"); + + this.teleportedEntity = teleportedEntity; + } + + /** + * Get the entity which was teleported + * @return the entity which was teleported + */ + public Entity getTeleportedEntity() { + return this.teleportedEntity; + } + + @Override + public @NotNull HandlerList getHandlers() { + return HANDLER_LIST; + } + + @NotNull + public static HandlerList getHandlerList() { + return HANDLER_LIST; + } +} diff --git a/src/main/java/me/earthme/luminol/api/entity/PreEntityPortalEvent.java b/src/main/java/me/earthme/luminol/api/entity/PreEntityPortalEvent.java new file mode 100644 index 0000000000000000000000000000000000000000..fc844429e3ecfe2529c0a49b8a5d958eeb188ad9 --- /dev/null +++ b/src/main/java/me/earthme/luminol/api/entity/PreEntityPortalEvent.java @@ -0,0 +1,78 @@ +package me.earthme.luminol.api.entity; + +import org.apache.commons.lang3.Validate; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.entity.Entity; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +/** + * A simple event created for missing teleport events api of folia + * This event will be fired when a portal teleportation is about to happen + */ +public class PreEntityPortalEvent extends Event implements Cancellable { + private static final HandlerList HANDLERS = new HandlerList(); + + private final Entity entity; + private final Location portalPos; + private final World destination; + + private boolean cancelled = false; + + public PreEntityPortalEvent(Entity entity, Location portalPos, World destination) { + Validate.notNull(entity, "entity cannot be null!"); + Validate.notNull(portalPos, "portalPos cannot be null!"); + Validate.notNull(destination, "destination cannot be null!"); + + this.entity = entity; + this.portalPos = portalPos; + this.destination = destination; + } + + /** + * Get the entity that is about to teleport + * @return the entity + */ + public @NotNull Entity getEntity() { + return this.entity; + } + + /** + * Get the location of the portal + * @return the portal location + */ + public @NotNull Location getPortalPos() { + return this.portalPos; + } + + /** + * Get the destination world + * @return the destination world + */ + public @NotNull World getDestination() { + return this.destination; + } + + @Override + public boolean isCancelled() { + return this.cancelled; + } + + @Override + public void setCancelled(boolean cancel) { + this.cancelled = cancel; + } + + @Override + public @NotNull HandlerList getHandlers() { + return HANDLERS; + } + + @NotNull + public static HandlerList getHandlerList() { + return HANDLERS; + } +} diff --git a/src/main/java/me/earthme/luminol/api/entity/player/PostPlayerRespawnEvent.java b/src/main/java/me/earthme/luminol/api/entity/player/PostPlayerRespawnEvent.java new file mode 100644 index 0000000000000000000000000000000000000000..9a561455560dfeee1d8762297ebf15a7c11de4d1 --- /dev/null +++ b/src/main/java/me/earthme/luminol/api/entity/player/PostPlayerRespawnEvent.java @@ -0,0 +1,40 @@ +package me.earthme.luminol.api.entity.player; + +import org.apache.commons.lang3.Validate; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +/** + * A simple event fired when the respawn process of player is done + */ +public class PostPlayerRespawnEvent extends Event { + private static final HandlerList HANDLERS = new HandlerList(); + + private final Player player; + + public PostPlayerRespawnEvent(Player player) { + Validate.notNull(player, "Player cannot be a null value!"); + + this.player = player; + } + + /** + * Get the respawned player + * @return the player + */ + public @NotNull Player getPlayer() { + return this.player; + } + + @Override + public @NotNull HandlerList getHandlers() { + return HANDLERS; + } + + @NotNull + public static HandlerList getHandlerList() { + return HANDLERS; + } +} diff --git a/src/main/java/me/earthme/luminol/api/portal/EndPlatformCreateEvent.java b/src/main/java/me/earthme/luminol/api/portal/EndPlatformCreateEvent.java new file mode 100644 index 0000000000000000000000000000000000000000..cf87a7cce5d1ebec9709b762595609344807150b --- /dev/null +++ b/src/main/java/me/earthme/luminol/api/portal/EndPlatformCreateEvent.java @@ -0,0 +1,35 @@ +package me.earthme.luminol.api.portal; + +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +/** + * A event fired when an end platform is created. + */ +public class EndPlatformCreateEvent extends Event implements Cancellable { + private static final HandlerList HANDLERS = new HandlerList(); + + private boolean cancelled = false; + + @Override + public boolean isCancelled() { + return this.cancelled; + } + + @Override + public void setCancelled(boolean cancel) { + this.cancelled = cancel; + } + + @Override + public @NotNull HandlerList getHandlers() { + return HANDLERS; + } + + @NotNull + public static HandlerList getHandlerList() { + return HANDLERS; + } +} diff --git a/src/main/java/me/earthme/luminol/api/portal/PortalLocateEvent.java b/src/main/java/me/earthme/luminol/api/portal/PortalLocateEvent.java new file mode 100644 index 0000000000000000000000000000000000000000..e09ffb99aad6f6acca3d6a411877715b90413eb0 --- /dev/null +++ b/src/main/java/me/earthme/luminol/api/portal/PortalLocateEvent.java @@ -0,0 +1,53 @@ +package me.earthme.luminol.api.portal; + +import org.apache.commons.lang3.Validate; +import org.bukkit.Location; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +/** + * A event fired when the portal process started locating the destination position + * Notice: If you changed the destination to an another position in end teleportation.The end platform won't create under the entity and won't create + * if the position is out of current tick region + */ +public class PortalLocateEvent extends Event { + private static final HandlerList HANDLERS = new HandlerList(); + + private final Location original; + private final Location destination; + + public PortalLocateEvent(Location original, Location destination) { + Validate.notNull(original, "original couldn't be null!"); + Validate.notNull(destination, "destination couldn't be null!"); + + this.original = original; + this.destination = destination; + } + + /** + * Get the destination position of this teleportation + * @return the destination position + */ + public Location getDestination() { + return this.destination; + } + + /** + * Get the original portal position of this teleportation + * @return the original portal position + */ + public Location getOriginal() { + return this.original; + } + + @Override + public @NotNull HandlerList getHandlers() { + return HANDLERS; + } + + @NotNull + public static HandlerList getHandlerList() { + return HANDLERS; + } +}