Skip to content

Commit a62a0f3

Browse files
committed
mainly ParticleMotion improvements and CQI
1 parent e15db44 commit a62a0f3

33 files changed

+140
-152
lines changed

src/main/java/com/sovdee/skriptparticles/SkriptParticle.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ public class SkriptParticle extends JavaPlugin {
2222
// todo, next release
2323
// custom shapes
2424
// icosphere
25+
// expressions for particles
2526
// todo, later versions
2627
// beziers
2728
// better triangle filling (basically allow any 3d model)
2829
// gradients
2930
// text rendering
30-
// animation?
3131

3232
@Nullable
3333
public static SkriptParticle getInstance() {

src/main/java/com/sovdee/skriptparticles/elements/expressions/ExprCustomParticle.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,14 @@ public class ExprCustomParticle extends SimpleExpression<Particle> {
3535
"[with offset %-vector%] [with extra %-number%] [force:with force]");
3636
}
3737

38+
@Nullable
3839
private Expression<Number> count;
3940
private Expression<?> particle;
41+
@Nullable
4042
private Expression<Object> data;
43+
@Nullable
4144
private Expression<Vector> offset;
45+
@Nullable
4246
private Expression<Number> extra;
4347
private boolean force;
4448

@@ -56,7 +60,8 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
5660
@Override
5761
@Nullable
5862
protected Particle[] get(Event event) {
59-
Object particleExpr = this.particle.getSingle(event);
63+
@Nullable Object particleExpr = this.particle.getSingle(event);
64+
6065
if (particleExpr == null) return new Particle[0];
6166
Particle particle;
6267
if (particleExpr instanceof Particle) {
@@ -66,9 +71,10 @@ protected Particle[] get(Event event) {
6671
} else {
6772
return new Particle[0];
6873
}
74+
6975
particle = particle.clone();
7076
if (count != null) {
71-
Number count = this.count.getSingle(event);
77+
@Nullable Number count = this.count.getSingle(event);
7278
if (count != null) {
7379
particle.count(count.intValue());
7480
} else {
@@ -78,20 +84,20 @@ protected Particle[] get(Event event) {
7884
}
7985

8086
if (data != null) {
81-
Object data = this.data.getSingle(event);
87+
@Nullable Object data = this.data.getSingle(event);
8288
if (data instanceof ItemType itemType) {
8389
data = itemType.getRandom();
8490
}
8591
if (data != null) particle.data(data);
8692
}
8793

8894
if (offset != null) {
89-
Vector offset = this.offset.getSingle(event);
95+
@Nullable Vector offset = this.offset.getSingle(event);
9096
if (offset != null) particle.offset(offset.getX(), offset.getY(), offset.getZ());
9197
}
9298

9399
if (extra != null) {
94-
Number extra = this.extra.getSingle(event);
100+
@Nullable Number extra = this.extra.getSingle(event);
95101
if (extra != null) particle.extra(extra.doubleValue());
96102
}
97103

@@ -111,7 +117,7 @@ public Class<? extends Particle> getReturnType() {
111117
}
112118

113119
@Override
114-
public String toString(@Nullable Event e, boolean debug) {
120+
public String toString(@Nullable Event event, boolean debug) {
115121
return "custom particle";
116122
}
117123

src/main/java/com/sovdee/skriptparticles/elements/expressions/ExprLastCreatedParticle.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
3232

3333
@Override
3434
@Nullable
35-
protected Particle[] get(Event evente) {
35+
protected Particle[] get(Event event) {
3636
return new Particle[]{SecParticle.lastCreatedParticle};
3737
}
3838

src/main/java/com/sovdee/skriptparticles/elements/expressions/ExprRotation.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,13 @@ public class ExprRotation extends SimpleExpression<Quaternion> {
3333
"[the|a] rotation (from|between) %vector% (to|and) %vector%");
3434
}
3535

36+
@Nullable
3637
private Expression<Number> angle;
38+
@Nullable
3739
private Expression<Vector> axis;
40+
@Nullable
3841
private Expression<Vector> from;
42+
@Nullable
3943
private Expression<Vector> to;
4044
private boolean isRadians = false;
4145

@@ -55,20 +59,22 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
5559
@Override
5660
@Nullable
5761
protected Quaternion[] get(Event event) {
58-
if (axis != null) {
59-
Vector axis = this.axis.getSingle(event);
60-
Number angle = this.angle.getSingle(event);
62+
if (axis != null && angle != null) {
63+
@Nullable Vector axis = this.axis.getSingle(event);
64+
@Nullable Number angle = this.angle.getSingle(event);
6165
if (axis == null || angle == null)
62-
return null;
66+
return new Quaternion[0];
6367
float angleFloat = angle.floatValue();
6468
if (!isRadians)
6569
angleFloat = (float) Math.toRadians(angleFloat);
6670
return new Quaternion[]{new Quaternion().rotationAxis(angleFloat, axis)};
6771
} else {
68-
Vector from = this.from.getSingle(event);
69-
Vector to = this.to.getSingle(event);
7072
if (from == null || to == null)
71-
return null;
73+
return new Quaternion[0];
74+
@Nullable Vector from = this.from.getSingle(event);
75+
@Nullable Vector to = this.to.getSingle(event);
76+
if (from == null || to == null)
77+
return new Quaternion[0];
7278
return new Quaternion[]{new Quaternion().rotationTo(from, to)};
7379
}
7480
}
@@ -84,10 +90,10 @@ public Class<? extends Quaternion> getReturnType() {
8490
}
8591

8692
@Override
87-
public String toString(@Nullable Event e, boolean debug) {
93+
public String toString(@Nullable Event event, boolean debug) {
8894
if (axis == null)
89-
return "rotation from " + from.toString(e, debug) + " to " + to.toString(e, debug);
90-
return "rotation around " + axis.toString(e, debug) + " by " + angle.toString(e, debug) + (isRadians ? " radians" : " degrees");
95+
return "rotation from " + (from != null ? from.toString(event, debug) : "null") + " to " + (to != null ? to.toString(event, debug) : "null");
96+
return "rotation around " + axis.toString(event, debug) + " by " + (angle != null ? angle.toString(event, debug) : "null") + (isRadians ? " radians" : " degrees");
9197
}
9298

9399
}

src/main/java/com/sovdee/skriptparticles/elements/expressions/ExprShapeCopy.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@
2828
public class ExprShapeCopy extends SimpleExpression<Shape> {
2929

3030
static {
31-
Skript.registerExpression(ExprShapeCopy.class, Shape.class, ExpressionType.SIMPLE, "[a] cop(y|ies) of %shapes%");
31+
Skript.registerExpression(ExprShapeCopy.class, Shape.class, ExpressionType.SIMPLE, "[a] shape cop(y|ies) of %shapes%");
3232
}
3333

34-
Expression<Shape> shapeExpr;
34+
private Expression<Shape> shapeExpr;
3535

3636
@Override
37-
public boolean init(Expression<?>[] expressions, int i, Kleenean kleenean, ParseResult parseResult) {
37+
public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean kleenean, ParseResult parseResult) {
3838
shapeExpr = (Expression<Shape>) expressions[0];
3939
return true;
4040
}
@@ -65,7 +65,7 @@ public Class<? extends Shape> getReturnType() {
6565
}
6666

6767
@Override
68-
public String toString(@Nullable Event event, boolean b) {
68+
public String toString(@Nullable Event event, boolean debug) {
6969
return "shape copy";
7070
}
7171
}

src/main/java/com/sovdee/skriptparticles/elements/expressions/constructors/ExprHelix.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import com.sovdee.skriptparticles.shapes.Shape.Style;
1616
import com.sovdee.skriptparticles.util.MathUtil;
1717
import org.bukkit.event.Event;
18-
import org.jetbrains.annotations.Nullable;
18+
import org.checkerframework.checker.nullness.qual.Nullable;
1919

2020
@Name("Particle Helix / Spiral")
2121
@Description({
@@ -38,6 +38,7 @@ public class ExprHelix extends SimpleExpression<Helix> {
3838

3939
private Expression<Number> radius;
4040
private Expression<Number> height;
41+
@Nullable
4142
private Expression<Number> windingRate;
4243
private boolean isClockwise = true;
4344
private Style style;
@@ -75,11 +76,12 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
7576
@Override
7677
@Nullable
7778
protected Helix[] get(Event event) {
78-
Number radius = this.radius.getSingle(event);
79-
Number height = this.height.getSingle(event);
80-
Number windingRate = this.windingRate == null ? 1 : this.windingRate.getSingle(event);
79+
@Nullable Number radius = this.radius.getSingle(event);
80+
@Nullable Number height = this.height.getSingle(event);
81+
@Nullable Number windingRate = this.windingRate == null ? 1 : this.windingRate.getSingle(event);
8182
if (radius == null || height == null || windingRate == null)
82-
return null;
83+
return new Helix[0];
84+
8385
radius = Math.max(radius.doubleValue(), MathUtil.EPSILON);
8486
height = Math.max(height.doubleValue(), MathUtil.EPSILON);
8587
double slope = 1.0 / Math.max(windingRate.doubleValue(), MathUtil.EPSILON);

src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprHelixWindingRate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public Number convert(Shape shape) {
4242
public Class<?>[] acceptChange(ChangeMode mode) {
4343
return switch (mode) {
4444
case SET, DELETE, ADD, REMOVE, RESET -> new Class[]{Number.class};
45-
default -> null;
45+
default -> new Class[0];
4646
};
4747
}
4848

src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeCutoffAngle.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ public class ExprShapeCutoffAngle extends SimplePropertyExpression<CutoffShape,
3838
public Class<?>[] acceptChange(ChangeMode mode) {
3939
return switch (mode) {
4040
case SET, RESET, DELETE, ADD, REMOVE -> new Class[]{Number.class};
41-
case REMOVE_ALL -> null;
41+
case REMOVE_ALL -> new Class[0];
4242
};
4343
}
4444

4545
@Override
46-
public void change(Event event, @Nullable Object[] delta, ChangeMode mode) {
46+
public void change(Event event, Object @Nullable [] delta, ChangeMode mode) {
4747
double angle = 0;
4848
if (delta != null && delta.length != 0)
4949
angle = ((Number) delta[0]).doubleValue();

src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeLWH.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ public Number convert(LWHShape lwhShape) {
5757
public Class<?>[] acceptChange(ChangeMode mode) {
5858
return switch (mode) {
5959
case SET, DELETE, RESET, ADD, REMOVE -> new Class[]{Number.class};
60-
default -> null;
60+
default -> new Class[0];
6161
};
6262
}
6363

6464
@Override
65-
public void change(Event event, @Nullable Object[] delta, ChangeMode mode) {
65+
public void change(Event event, Object @Nullable [] delta, ChangeMode mode) {
6666
double value = 1;
6767
if (delta != null && delta.length != 0)
6868
value = ((Number) delta[0]).doubleValue();
@@ -108,7 +108,7 @@ protected String getPropertyName() {
108108
case 0 -> "length";
109109
case 1 -> "width";
110110
case 2 -> "height";
111-
default -> null;
111+
default -> "unknown";
112112
};
113113
}
114114

src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeLocations.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
import ch.njol.skript.lang.ExpressionType;
1010
import ch.njol.skript.lang.SkriptParser;
1111
import ch.njol.skript.lang.util.SimpleExpression;
12+
import ch.njol.skript.util.Direction;
1213
import ch.njol.util.Kleenean;
1314
import com.sovdee.skriptparticles.shapes.Shape;
1415
import org.bukkit.Location;
1516
import org.bukkit.event.Event;
1617
import org.checkerframework.checker.nullness.qual.NonNull;
17-
import org.jetbrains.annotations.Nullable;
18+
import org.checkerframework.checker.nullness.qual.Nullable;
1819

1920
import java.util.ArrayList;
20-
import java.util.stream.Collectors;
2121

2222
@Name("Shape Locations")
2323
@Description({
@@ -35,7 +35,7 @@
3535
public class ExprShapeLocations extends SimpleExpression<Location> {
3636

3737
static {
38-
Skript.registerExpression(ExprShapeLocations.class, Location.class, ExpressionType.COMBINED, "[particle] locations of %shapes% [[centered] %direction% %location%]");
38+
Skript.registerExpression(ExprShapeLocations.class, Location.class, ExpressionType.COMBINED, "[particle] locations of %shapes% [[centered] [%-direction%] %location%]");
3939
}
4040

4141
private Expression<Shape> shapeExpr;
@@ -44,23 +44,26 @@ public class ExprShapeLocations extends SimpleExpression<Location> {
4444
@Override
4545
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) {
4646
shapeExpr = (Expression<Shape>) exprs[0];
47-
locationExpr = (Expression<Location>) exprs[1];
47+
locationExpr = (Expression<Location>) exprs[2];
48+
if (exprs[1] != null)
49+
locationExpr = Direction.combine((Expression<? extends Direction>) exprs[1], locationExpr);
4850
return true;
4951
}
5052

5153
@Override
5254
@Nullable
53-
protected Location[] get(@NonNull Event event) {
55+
protected Location[] get(Event event) {
5456
Shape[] shapes = shapeExpr.getAll(event);
55-
if (shapes.length == 0) return null;
57+
if (shapes.length == 0) return new Location[0];
5658

57-
Location center = locationExpr.getSingle(event);
58-
if (center == null) return null;
59+
@Nullable Location center = locationExpr.getSingle(event);
60+
61+
if (center == null) return new Location[0];
5962

6063

6164
ArrayList<Location> locations = new ArrayList<>();
6265
for (Shape shape : shapes) {
63-
locations.addAll(shape.getPoints().stream().map(point -> center.clone().add(point)).collect(Collectors.toList()));
66+
locations.addAll(shape.getPoints().stream().map(point -> center.clone().add(point)).toList());
6467
}
6568
return locations.toArray(new Location[0]);
6669
}

0 commit comments

Comments
 (0)