From 0e1cea5a4a4b41004912ab7a8b2871349b1ef4a0 Mon Sep 17 00:00:00 2001 From: blablubbabc Date: Tue, 26 Mar 2019 03:34:56 +0100 Subject: [PATCH] Added Entity#setRotation. Unlike Entity#teleport this can also be used while the entity is inside a vehicle. --- .../bukkit/craftbukkit/entity/CraftEntity.java | 16 ++++++++++++++++ .../bukkit/craftbukkit/entity/CraftPlayer.java | 5 +++++ 2 files changed, 21 insertions(+) diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java index 5f7e0bd2a0..aca4532863 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java @@ -29,6 +29,7 @@ import org.bukkit.permissions.PermissionAttachmentInfo; import org.bukkit.permissions.ServerOperator; import org.bukkit.plugin.Plugin; import org.bukkit.util.BoundingBox; +import org.bukkit.util.NumberConversions; import org.bukkit.util.Vector; public abstract class CraftEntity implements org.bukkit.entity.Entity { @@ -291,6 +292,21 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity { return entity.world.getWorld(); } + @Override + public void setRotation(float yaw, float pitch) { + NumberConversions.checkFinite(pitch, "pitch not finite"); + NumberConversions.checkFinite(yaw, "yaw not finite"); + + yaw = Location.normalizeYaw(yaw); + pitch = Location.normalizePitch(pitch); + + entity.yaw = yaw; + entity.pitch = pitch; + entity.lastYaw = yaw; + entity.lastPitch = pitch; + entity.setHeadRotation(yaw); + } + public boolean teleport(Location location) { return teleport(location, TeleportCause.PLUGIN); } diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index 42e785bfd6..23277f404f 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -566,6 +566,11 @@ public class CraftPlayer extends CraftHumanEntity implements Player { getHandle().playerConnection.sendPacket(packet); } + @Override + public void setRotation(float yaw, float pitch) { + throw new UnsupportedOperationException("Cannot set rotation of players. Consider teleporting instead."); + } + @Override public boolean teleport(Location location, PlayerTeleportEvent.TeleportCause cause) { Preconditions.checkArgument(location != null, "location");