From 2922d9a61ffd1cc30d562e10232f6b4ef2125955 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 12 Mar 2022 11:01:25 +0100 Subject: [PATCH] Fix nodepth portal --- src/de/steamwar/lobby/portal/Portal.java | 4 ++++ src/de/steamwar/lobby/portal/TeleportPortal.java | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/de/steamwar/lobby/portal/Portal.java b/src/de/steamwar/lobby/portal/Portal.java index d0ac3c8..197aa84 100644 --- a/src/de/steamwar/lobby/portal/Portal.java +++ b/src/de/steamwar/lobby/portal/Portal.java @@ -145,6 +145,10 @@ public class Portal implements PortalHandler, ConfigurationSerializable { return yRotation; } + public double getDepth() { + return depth; + } + private static Iterable perChunk(int minChunkX, int maxChunkX, int minChunkZ, int maxChunkZ) { return () -> new Iterator() { private int x = minChunkX; diff --git a/src/de/steamwar/lobby/portal/TeleportPortal.java b/src/de/steamwar/lobby/portal/TeleportPortal.java index a06bfa1..48e090a 100644 --- a/src/de/steamwar/lobby/portal/TeleportPortal.java +++ b/src/de/steamwar/lobby/portal/TeleportPortal.java @@ -25,6 +25,7 @@ import de.steamwar.lobby.listener.Portals; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerTeleportEvent; +import org.bukkit.util.Vector; import java.util.*; import java.util.logging.Level; @@ -75,7 +76,11 @@ public class TeleportPortal implements PortalHandler { if(ModifyCommand.modifying(player)) player.sendMessage("teleport " + portal.getId() + " -> " + target.getId()); - player.teleport(target.denormalize(portal.normalize(to).setX(1 - portal.normalize(from).getX())).toLocation(to.getWorld(), (float) (to.getYaw() - Math.toDegrees(target.getYrotation() - portal.getYrotation())), to.getPitch()), PlayerTeleportEvent.TeleportCause.PLUGIN); + Vector normalized = portal.normalize(to); + if (target.getDepth() != 0.0) { + normalized.setX(1 - portal.normalize(from).getX()); + } + player.teleport(target.denormalize(normalized).toLocation(to.getWorld(), (float) (to.getYaw() - Math.toDegrees(target.getYrotation() - portal.getYrotation())), to.getPitch()), PlayerTeleportEvent.TeleportCause.PLUGIN); } @Override