diff --git a/paper/src/main/java/com/hpfxd/spectatorplus/paper/SpectatorWorkarounds.java b/paper/src/main/java/com/hpfxd/spectatorplus/paper/SpectatorWorkarounds.java index fecb9d3..b81ce74 100644 --- a/paper/src/main/java/com/hpfxd/spectatorplus/paper/SpectatorWorkarounds.java +++ b/paper/src/main/java/com/hpfxd/spectatorplus/paper/SpectatorWorkarounds.java @@ -6,6 +6,7 @@ import io.papermc.paper.event.player.PlayerTrackEntityEvent; import io.papermc.paper.event.player.PlayerUntrackEntityEvent; import org.bukkit.Bukkit; +import org.bukkit.Location; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -41,9 +42,11 @@ private void updateSpectatorPositions() { if (target != null) { if (spectator.getWorld().equals(target.getWorld())) { + final Location targetLocation = target.getLocation(); + if (!this.directTeleportFailed) { try { - ReflectionUtil.directTeleport(spectator, target.getLocation()); + ReflectionUtil.directTeleport(spectator, targetLocation); } catch (Throwable e) { this.directTeleportFailed = true; this.plugin.getSLF4JLogger().warn("auto-update-position workaround: Failed to call directTeleport, will not try again", e); @@ -57,6 +60,8 @@ private void updateSpectatorPositions() { spectator.setSpectatorTarget(null); spectator.setSpectatorTarget(target); } + + spectator.setRotation(targetLocation.getYaw(), targetLocation.getPitch()); } } } @@ -140,6 +145,14 @@ public void onStartSpectating(PlayerStartSpectatingEntityEvent event) { final Player spectator = event.getPlayer(); final Entity target = event.getNewSpectatorTarget(); + final Location targetLocation = target.getLocation(); + + if (!spectator.getWorld().equals(target.getWorld())) { + spectator.teleport(targetLocation, PlayerTeleportEvent.TeleportCause.SPECTATE); + } + + spectator.setRotation(targetLocation.getYaw(), targetLocation.getPitch()); + if (!target.getTrackedBy().contains(spectator)) { this.tempTargets.put(spectator.getUniqueId(), target.getUniqueId()); }