Fix Java 8 compat

This commit is contained in:
fullwall 2023-03-13 21:46:52 +08:00
parent f8c8b8af6e
commit b9f10a2e0c
6 changed files with 47 additions and 16 deletions

View File

@ -509,6 +509,7 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
despawnNPCs(false);
ProfileFetcher.reset();
Skin.clearCache();
getServer().getPluginManager().callEvent(new CitizensPreReloadEvent());
saves.reloadFromSource();

View File

@ -226,15 +226,11 @@ public class Settings {
return (List<String>) value;
}
public long asLong() {
return ((Number) value).longValue();
}
public int asSeconds() {
if (duration == null) {
duration = SpigotUtil.parseDuration(asString());
}
return (int) TimeUnit.SECONDS.convert(duration);
return (int) TimeUnit.SECONDS.convert(duration.getNano(), TimeUnit.NANOSECONDS);
}
public String asString() {

View File

@ -704,10 +704,9 @@ public class NPCCommands {
String msg = "Created [[" + npc.getName() + "]] (ID [[" + npc.getId() + "]])";
int age = 0;
if (args.hasFlag('b')) {
age = -24000;
msg += " as a baby";
npc.getOrAddTrait(Age.class).setAge(-24000);
}
if (args.hasFlag('s')) {
@ -810,8 +809,6 @@ public class NPCCommands {
msg += " with templates " + builder.toString();
}
npc.getOrAddTrait(Age.class).setAge(age);
selector.select(sender, npc);
history.add(sender, new CreateNPCHistoryItem(npc));
Messaging.send(sender, msg + '.');

View File

@ -574,7 +574,7 @@ public class CommandTrait extends Trait {
}
public NPCCommandBuilder cooldown(Duration cd) {
return cooldown((int) TimeUnit.SECONDS.convert(cd));
return cooldown((int) TimeUnit.SECONDS.convert(cd.getNano(), TimeUnit.NANOSECONDS));
}
public NPCCommandBuilder cooldown(int cooldown) {
@ -588,7 +588,7 @@ public class CommandTrait extends Trait {
}
public NPCCommandBuilder globalCooldown(Duration cd) {
return globalCooldown((int) TimeUnit.SECONDS.convert(cd));
return globalCooldown((int) TimeUnit.SECONDS.convert(cd.getNano(), TimeUnit.NANOSECONDS));
}
public NPCCommandBuilder globalCooldown(int cooldown) {

View File

@ -36,6 +36,23 @@ public class Quaternion {
return ZERO;
}
public EulerAngle toEuler() {
double w2 = w * w;
double x2 = x * x;
double y2 = y * y;
double z2 = z * z;
double length = x2 + y2 + z2 + w2;
double test = x * y + z * w;
if (test > 0.499 * length) {
return new EulerAngle(0, 2 * Math.atan2(x, w), Math.PI / 2);
} else if (test < -0.499 * length) {
return new EulerAngle(0, -2 * Math.atan2(x, w), -(Math.PI / 2));
} else {
return new EulerAngle(Math.atan2(2 * x * w - 2 * y * z, -x2 + y2 - z2 + w2),
Math.atan2(2 * y * 2 - 2 * x * z, x2 - y2 - z2 + w2), Math.asin(2 * test / length));
}
}
private static double fastisqrt(double x) {
double xhalf = 0.5d * x;
long i = Double.doubleToLongBits(x);
@ -56,16 +73,36 @@ public class Quaternion {
double s1 = Math.sin(x * 0.5);
double s2 = Math.sin(y * 0.5);
double s3 = Math.sin(z * 0.5);
return new Quaternion(s1 * s2 * c3 + c1 * c2 * s3, s1 * c2 * c3 + c1 * s2 * s3, c1 * s2 * c3 - s1 * c2 * s3,
c1 * c2 * c3 - s1 * s2 * s3);
double c1c2 = c1 * c2;
double s1s2 = s1 * s2;
return new Quaternion(s1s2 * c3 + c1c2 * s3, s1 * c2 * c3 + c1 * s2 * s3, c1 * s2 * c3 - s1 * c2 * s3,
c1c2 * c3 - s1s2 * s3);
}
public static Quaternion lerp(Quaternion a, Quaternion b, double t) {
public static Quaternion nlerp(Quaternion a, Quaternion b, double t) {
if (a.dot(b) < 0) {
b = b.mul(-1);
}
return new Quaternion(a.x - t * (a.x - b.x), a.y - t * (a.y - b.y), a.z - t * (a.z - b.z),
a.w - t * (a.w - b.w));
a.w - t * (a.w - b.w)).norm();
}
public static Quaternion slerp(Quaternion a, Quaternion b, double t) {
double len = a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;
if (len < 0) {
b = b.mul(-1);
len = -len;
}
double sa = 1 - t;
double sb = t;
if (0.1 < 1 - len) {
double theta = Math.acos(len);
double itheta = 1 / Math.sin(theta);
sa = Math.sin(theta * (1 - t)) * itheta;
sb = Math.sin(theta * t) * itheta;
}
return new Quaternion(sa * a.x + sb * b.x, sa * a.y + sb * b.y, sa * a.z + sb * b.z, sa * a.w + sb * b.w);
}
private static final Quaternion ZERO = new Quaternion(0, 0, 0, 0);

View File

@ -411,7 +411,7 @@ public class Util {
}
public static int toTicks(Duration delay) {
return (int) TimeUnit.MILLISECONDS.convert(delay) / 50;
return (int) TimeUnit.MILLISECONDS.convert(delay.getNano(), TimeUnit.NANOSECONDS) / 50;
}
private static final Location AT_LOCATION = new Location(null, 0, 0, 0);