mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-09 19:49:35 +01:00
Move checkFinite methods to a util class.
By: md_5 <git@md-5.net>
This commit is contained in:
parent
70bfc4d702
commit
55b9c40dda
3 changed files with 16 additions and 20 deletions
|
@ -6,6 +6,7 @@ import java.util.Map;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||||
import org.bukkit.util.NumberConversions;
|
import org.bukkit.util.NumberConversions;
|
||||||
|
import static org.bukkit.util.NumberConversions.checkFinite;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -188,7 +189,7 @@ public class Location implements Cloneable, ConfigurationSerializable {
|
||||||
* @param yaw new rotation's yaw
|
* @param yaw new rotation's yaw
|
||||||
*/
|
*/
|
||||||
public void setYaw(float yaw) {
|
public void setYaw(float yaw) {
|
||||||
checkFiniteFloat(yaw, "yaw must be finite");
|
checkFinite(yaw, "yaw must be finite");
|
||||||
this.yaw = yaw;
|
this.yaw = yaw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,7 +224,7 @@ public class Location implements Cloneable, ConfigurationSerializable {
|
||||||
* @param pitch new incline's pitch
|
* @param pitch new incline's pitch
|
||||||
*/
|
*/
|
||||||
public void setPitch(float pitch) {
|
public void setPitch(float pitch) {
|
||||||
checkFiniteFloat(pitch, "pitch must be finite");
|
checkFinite(pitch, "pitch must be finite");
|
||||||
this.pitch = pitch;
|
this.pitch = pitch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -601,16 +602,4 @@ public class Location implements Cloneable, ConfigurationSerializable {
|
||||||
|
|
||||||
return new Location(world, NumberConversions.toDouble(args.get("x")), NumberConversions.toDouble(args.get("y")), NumberConversions.toDouble(args.get("z")), NumberConversions.toFloat(args.get("yaw")), NumberConversions.toFloat(args.get("pitch")));
|
return new Location(world, NumberConversions.toDouble(args.get("x")), NumberConversions.toDouble(args.get("y")), NumberConversions.toDouble(args.get("z")), NumberConversions.toFloat(args.get("yaw")), NumberConversions.toFloat(args.get("pitch")));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void checkFinite(double d, String message) {
|
|
||||||
if (Double.isNaN(d) || Double.isInfinite(d)) {
|
|
||||||
throw new IllegalArgumentException(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void checkFiniteFloat(float d, String message) {
|
|
||||||
if (Float.isNaN(d) || Float.isInfinite(d)) {
|
|
||||||
throw new IllegalArgumentException(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,4 +101,16 @@ public final class NumberConversions {
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void checkFinite(double d, String message) {
|
||||||
|
if (Double.isNaN(d) || Double.isInfinite(d)) {
|
||||||
|
throw new IllegalArgumentException(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void checkFinite(float d, String message) {
|
||||||
|
if (Float.isNaN(d) || Float.isInfinite(d)) {
|
||||||
|
throw new IllegalArgumentException(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||||
import org.bukkit.configuration.serialization.SerializableAs;
|
import org.bukkit.configuration.serialization.SerializableAs;
|
||||||
|
import static org.bukkit.util.NumberConversions.checkFinite;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a mutable vector. Because the components of Vectors are mutable,
|
* Represents a mutable vector. Because the components of Vectors are mutable,
|
||||||
|
@ -646,10 +647,4 @@ public class Vector implements Cloneable, ConfigurationSerializable {
|
||||||
|
|
||||||
return new Vector(x, y, z);
|
return new Vector(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void checkFinite(double d, String message) {
|
|
||||||
if (Double.isNaN(d) || Double.isInfinite(d)) {
|
|
||||||
throw new IllegalArgumentException(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue