|
16 | 16 | import ch.njol.util.StringUtils; |
17 | 17 | import ch.njol.yggdrasil.Fields; |
18 | 18 | import org.jetbrains.annotations.Contract; |
| 19 | +import org.jetbrains.annotations.NotNull; |
19 | 20 | import org.jetbrains.annotations.Nullable; |
20 | 21 | import org.joml.Quaternionf; |
21 | 22 | import org.joml.Vector3d; |
@@ -312,63 +313,8 @@ public boolean mustSyncDeserialization() { |
312 | 313 | .examples("") |
313 | 314 | .since("2.2-dev23") |
314 | 315 | .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()) |
372 | 318 | .cloner(Vector3d::new)); |
373 | 319 |
|
374 | 320 | // joml type - for display entities |
@@ -941,4 +887,68 @@ protected boolean canBeInstantiated() { |
941 | 887 |
|
942 | 888 | } |
943 | 889 |
|
| 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 | + |
944 | 954 | } |
0 commit comments