Added Entity#setRotation.

Unlike Entity#teleport this can also be used while the entity is inside a vehicle.
This commit is contained in:
blablubbabc 2019-03-26 03:34:56 +01:00 committed by md_5
parent 0bf75bbde2
commit 0e1cea5a4a
2 changed files with 21 additions and 0 deletions

View file

@ -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);
}

View file

@ -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");