85 lines
2.2 KiB
Java
85 lines
2.2 KiB
Java
package com.yaohun.enderdragonwars.data;
|
|
|
|
import org.bukkit.Location;
|
|
import org.bukkit.World;
|
|
import org.bukkit.configuration.ConfigurationSection;
|
|
|
|
import java.util.Objects;
|
|
|
|
public class DirectionPoint extends Point {
|
|
|
|
private float yaw;
|
|
private float pitch;
|
|
|
|
public DirectionPoint(int x, int y, int z, float yaw, float pitch) {
|
|
super(x, y, z);
|
|
this.yaw = yaw;
|
|
this.pitch = pitch;
|
|
}
|
|
|
|
public DirectionPoint(double x, double y, double z) {
|
|
this(x, y, z, 0f, 0f);
|
|
}
|
|
|
|
public DirectionPoint(double x, double y, double z, float yaw, float pitch) {
|
|
super(x, y, z);
|
|
this.yaw = yaw;
|
|
this.pitch = pitch;
|
|
}
|
|
|
|
public static DirectionPoint of(Location location) {
|
|
return new DirectionPoint(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
|
|
}
|
|
|
|
public static DirectionPoint deserialize(ConfigurationSection section) {
|
|
return new DirectionPoint(section.getDouble("x"), section.getDouble("y"), section.getDouble("z"), (float) section.getDouble("yaw"), (float) section.getDouble("pitch"));
|
|
}
|
|
|
|
public float getPitch() {
|
|
return pitch;
|
|
}
|
|
|
|
public void setPitch(float pitch) {
|
|
this.pitch = pitch;
|
|
}
|
|
|
|
public float getYaw() {
|
|
return yaw;
|
|
}
|
|
|
|
public void setYaw(float yaw) {
|
|
this.yaw = yaw;
|
|
}
|
|
|
|
@Override
|
|
public Location toLocation(World world) {
|
|
return new Location(world, getX(), getY(), getZ(), yaw, pitch);
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
return "DirectionPoint{" +
|
|
"x=" + getX() +
|
|
", y=" + getY() +
|
|
", z=" + getZ() +
|
|
", yaw=" + yaw +
|
|
", pitch=" + pitch +
|
|
'}';
|
|
}
|
|
|
|
@Override
|
|
public boolean equals(Object o) {
|
|
if (this == o) return true;
|
|
if (o == null || getClass() != o.getClass()) return false;
|
|
if (!super.equals(o)) return false;
|
|
DirectionPoint that = (DirectionPoint) o;
|
|
return super.equals(o) && Float.compare(that.yaw, yaw) == 0 && Float.compare(that.pitch, pitch) == 0;
|
|
}
|
|
|
|
@Override
|
|
public int hashCode() {
|
|
return Objects.hash(super.hashCode(), yaw, pitch);
|
|
}
|
|
|
|
}
|