Skip to content

Commit ad3b085

Browse files
committed
Requested changes
1 parent 239793f commit ad3b085

3 files changed

Lines changed: 81 additions & 69 deletions

File tree

src/main/java/ch/njol/skript/classes/data/JavaClasses.java

Lines changed: 67 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import ch.njol.util.StringUtils;
1717
import ch.njol.yggdrasil.Fields;
1818
import org.jetbrains.annotations.Contract;
19+
import org.jetbrains.annotations.NotNull;
1920
import org.jetbrains.annotations.Nullable;
2021
import org.joml.Quaternionf;
2122
import org.joml.Vector3d;
@@ -312,63 +313,8 @@ public boolean mustSyncDeserialization() {
312313
.examples("")
313314
.since("2.2-dev23")
314315
.defaultExpression(new EventValueExpression<>(Vector3d.class))
315-
.parser(new Parser<Vector3d>() {
316-
@Override
317-
@Nullable
318-
public Vector3d parse(final String s, final ParseContext context) {
319-
return null;
320-
}
321-
322-
@Override
323-
public boolean canParse(final ParseContext context) {
324-
return false;
325-
}
326-
327-
@Override
328-
public String toString(final Vector3d vec, final int flags) {
329-
return "x: " + Skript.toString(vec.x()) + ", y: " + Skript.toString(vec.y()) + ", z: " + Skript.toString(vec.z());
330-
}
331-
332-
@Override
333-
public String toVariableNameString(final Vector3d vec) {
334-
return "vector:" + vec.x() + "," + vec.y() + "," + vec.z();
335-
}
336-
337-
@Override
338-
public String getDebugMessage(final Vector3d vec) {
339-
return "(" + vec.x() + "," + vec.y() + "," + vec.z() + ")";
340-
}
341-
})
342-
.serializer(new Serializer<>() {
343-
@Override
344-
public Fields serialize(Vector3d o) {
345-
Fields f = new Fields();
346-
f.putPrimitive("x", o.x());
347-
f.putPrimitive("y", o.y());
348-
f.putPrimitive("z", o.z());
349-
return f;
350-
}
351-
352-
@Override
353-
public void deserialize(Vector3d o, Fields f) {
354-
assert false;
355-
}
356-
357-
@Override
358-
public Vector3d deserialize(final Fields f) throws StreamCorruptedException {
359-
return new Vector3d(f.getPrimitive("x", double.class), f.getPrimitive("y", double.class), f.getPrimitive("z", double.class));
360-
}
361-
362-
@Override
363-
public boolean mustSyncDeserialization() {
364-
return false;
365-
}
366-
367-
@Override
368-
protected boolean canBeInstantiated() {
369-
return false;
370-
}
371-
})
316+
.parser(new Vector3dParser())
317+
.serializer(new Vector3dSerializer())
372318
.cloner(Vector3d::new));
373319

374320
// joml type - for display entities
@@ -941,4 +887,68 @@ protected boolean canBeInstantiated() {
941887

942888
}
943889

890+
private static class Vector3dParser extends Parser<Vector3d> {
891+
892+
@Override
893+
public @Nullable Vector3d parse(String s, ParseContext context) {
894+
return null;
895+
}
896+
897+
@Override
898+
public boolean canParse(ParseContext context) {
899+
return false;
900+
}
901+
902+
@Override
903+
public @NotNull String toString(@NotNull Vector3d vec, int flags) {
904+
return "x: " + Skript.toString(vec.x()) + ", y: " + Skript.toString(vec.y()) + ", z: " + Skript.toString(vec.z());
905+
}
906+
907+
@Override
908+
public @NotNull String toVariableNameString(@NotNull Vector3d vec) {
909+
return "vector:" + vec.x() + "," + vec.y() + "," + vec.z();
910+
}
911+
912+
@Override
913+
public @NotNull String getDebugMessage(@NotNull Vector3d vec) {
914+
return "(" + vec.x() + "," + vec.y() + "," + vec.z() + ")";
915+
}
916+
917+
}
918+
919+
private static class Vector3dSerializer extends Serializer<Vector3d> {
920+
@Override
921+
public Fields serialize(Vector3d vector3d) {
922+
Fields f = new Fields();
923+
f.putPrimitive("x", vector3d.x());
924+
f.putPrimitive("y", vector3d.y());
925+
f.putPrimitive("z", vector3d.z());
926+
return f;
927+
}
928+
929+
@Override
930+
public void deserialize(Vector3d o, Fields f) {
931+
assert false;
932+
}
933+
934+
@Override
935+
public Vector3d deserialize(Fields fields) throws StreamCorruptedException {
936+
return new Vector3d(
937+
fields.getPrimitive("x", double.class),
938+
fields.getPrimitive("y", double.class),
939+
fields.getPrimitive("z", double.class));
940+
}
941+
942+
@Override
943+
public boolean mustSyncDeserialization() {
944+
return false;
945+
}
946+
947+
@Override
948+
protected boolean canBeInstantiated() {
949+
return false;
950+
}
951+
952+
}
953+
944954
}

src/main/java/ch/njol/skript/expressions/ExprYawPitch.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -217,33 +217,25 @@ public static Vector3d fromYawAndPitch(float yaw, float pitch) {
217217
return new Vector3d(x,y,z);
218218
}
219219

220-
// TODO Mark as private next version after VectorMath deletion
221-
@ApiStatus.Internal
222-
public static float getYaw(Vector3d vector) {
220+
private static float getYaw(Vector3d vector) {
223221
if (((Double) vector.x()).equals((double) 0) && ((Double) vector.z()).equals((double) 0)){
224222
return 0;
225223
}
226224
return (float) (Math.atan2(vector.z(), vector.x()) * RAD_TO_DEG);
227225
}
228226

229-
// TODO Mark as private next version after VectorMath deletion
230-
@ApiStatus.Internal
231-
public static float getPitch(Vector3d vector) {
227+
private static float getPitch(Vector3d vector) {
232228
double xy = Math.sqrt(vector.x() * vector.x() + vector.z() * vector.z());
233229
return (float) (Math.atan(vector.y() / xy) * RAD_TO_DEG);
234230
}
235231

236-
// TODO Mark as private next version after VectorMath deletion
237-
@ApiStatus.Internal
238-
public static float skriptYaw(float yaw) {
232+
private static float skriptYaw(float yaw) {
239233
return yaw < 90
240234
? yaw + 270
241235
: yaw - 90;
242236
}
243237

244-
// TODO Mark as private next version after VectorMath deletion
245-
@ApiStatus.Internal
246-
public static float skriptPitch(float pitch) {
238+
private static float skriptPitch(float pitch) {
247239
return -pitch;
248240
}
249241

@@ -256,4 +248,5 @@ public static float fromSkriptYaw(float yaw) {
256248
public static float fromSkriptPitch(float pitch) {
257249
return -pitch;
258250
}
251+
259252
}

src/main/java/ch/njol/util/Math2.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ public static long addClamped(long x, long y) {
150150
return result;
151151
}
152152

153+
/**
154+
* @param x the first value
155+
* @param y the second value
156+
* @return the product of x and y, or {@link Long#MAX_VALUE}, {@link Long#MIN_VALUE} in case of an overflow/underflow.
157+
*/
153158
public static long multiplyClamped(long x, long y) {
154159
long result = x * y;
155160
long ax = Math.abs(x);
@@ -161,6 +166,10 @@ public static long multiplyClamped(long x, long y) {
161166
return result;
162167
}
163168

169+
/**
170+
* @param vector the vector to check
171+
* @return whether the x, y, and z components of the vector are all within {@link Skript#EPSILON} of 0.
172+
*/
164173
public static boolean vectorIsZero(Vector3d vector) {
165174
return Math.abs(vector.x) < Skript.EPSILON &&
166175
Math.abs(vector.y) < Skript.EPSILON &&

0 commit comments

Comments
 (0)