From b8b594d6108c23edcc83bdaf458f77e534435be6 Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Sat, 11 Jan 2020 19:09:58 +0100 Subject: [PATCH] PortalEvent additions This re-adds some of the functionality that the TravelAgent API provided previously By: Phoenix616 --- .../event/entity/EntityPortalEvent.java | 25 ++++++ .../event/player/PlayerPortalEvent.java | 83 +++++++++++++++++++ 2 files changed, 108 insertions(+) diff --git a/paper-api/src/main/java/org/bukkit/event/entity/EntityPortalEvent.java b/paper-api/src/main/java/org/bukkit/event/entity/EntityPortalEvent.java index 7fdfe3c5a3..67fb9d93e8 100644 --- a/paper-api/src/main/java/org/bukkit/event/entity/EntityPortalEvent.java +++ b/paper-api/src/main/java/org/bukkit/event/entity/EntityPortalEvent.java @@ -14,11 +14,36 @@ import org.jetbrains.annotations.Nullable; */ public class EntityPortalEvent extends EntityTeleportEvent { private static final HandlerList handlers = new HandlerList(); + private int searchRadius = 128; public EntityPortalEvent(@NotNull final Entity entity, @NotNull final Location from, @Nullable final Location to) { super(entity, from, to); } + public EntityPortalEvent(@NotNull Entity entity, @NotNull Location from, @Nullable Location to, int searchRadius) { + super(entity, from, to); + this.searchRadius = searchRadius; + } + + /** + * Set the Block radius to search in for available portals. + * + * @param searchRadius the radius in which to search for a portal from the + * location + */ + public void setSearchRadius(int searchRadius) { + this.searchRadius = searchRadius; + } + + /** + * Gets the search radius value for finding an available portal. + * + * @return the currently set search radius + */ + public int getSearchRadius() { + return searchRadius; + } + @NotNull @Override public HandlerList getHandlers() { diff --git a/paper-api/src/main/java/org/bukkit/event/player/PlayerPortalEvent.java b/paper-api/src/main/java/org/bukkit/event/player/PlayerPortalEvent.java index 5b7550781b..a6f91166a3 100644 --- a/paper-api/src/main/java/org/bukkit/event/player/PlayerPortalEvent.java +++ b/paper-api/src/main/java/org/bukkit/event/player/PlayerPortalEvent.java @@ -14,6 +14,9 @@ import org.jetbrains.annotations.Nullable; */ public class PlayerPortalEvent extends PlayerTeleportEvent { private static final HandlerList handlers = new HandlerList(); + private int getSearchRadius = 128; + private boolean canCreatePortal = true; + private int creationRadius = 16; public PlayerPortalEvent(@NotNull final Player player, @NotNull final Location from, @Nullable final Location to) { super(player, from, to); @@ -23,6 +26,86 @@ public class PlayerPortalEvent extends PlayerTeleportEvent { super(player, from, to, cause); } + public PlayerPortalEvent(@NotNull Player player, @NotNull Location from, @Nullable Location to, @NotNull TeleportCause cause, int getSearchRadius, boolean canCreatePortal, int creationRadius) { + super(player, from, to, cause); + this.getSearchRadius = getSearchRadius; + this.canCreatePortal = canCreatePortal; + this.creationRadius = creationRadius; + } + + /** + * Set the Block radius to search in for available portals. + * + * @param searchRadius the radius in which to search for a portal from the + * location + */ + public void setSearchRadius(int searchRadius) { + this.getSearchRadius = searchRadius; + } + + /** + * Gets the search radius value for finding an available portal. + * + * @return the currently set search radius + */ + public int getSearchRadius() { + return getSearchRadius; + } + + /** + * Returns whether the server will attempt to create a destination portal or + * not. + * + * @return whether there should create be a destination portal created + */ + public boolean getCanCreatePortal() { + return canCreatePortal; + } + + /** + * Sets whether the server should attempt to create a destination portal or + * not. + * + * @param canCreatePortal Sets whether there should be a destination portal + * created + */ + public void setCanCreatePortal(boolean canCreatePortal) { + this.canCreatePortal = canCreatePortal; + } + + /** + * Sets the maximum radius the world is searched for a free space from the + * given location. + * + * If enough free space is found then the portal will be created there, if + * not it will force create with air-space at the target location. + * + * Does not apply to end portal target platforms which will always appear at + * the target location. + * + * @param creationRadius the radius in which to create a portal from the + * location + */ + public void setCreationRadius(int creationRadius) { + this.creationRadius = creationRadius; + } + + /** + * Gets the maximum radius the world is searched for a free space from the + * given location. + * + * If enough free space is found then the portal will be created there, if + * not it will force create with air-space at the target location. + * + * Does not apply to end portal target platforms which will always appear at + * the target location. + * + * @return the currently set creation radius + */ + public int getCreationRadius() { + return creationRadius; + } + @NotNull @Override public HandlerList getHandlers() {