diff --git a/src/main/java/com/sovdee/skriptparticles/SkriptParticle.java b/src/main/java/com/sovdee/skriptparticles/SkriptParticle.java index 41a451d..3e54386 100644 --- a/src/main/java/com/sovdee/skriptparticles/SkriptParticle.java +++ b/src/main/java/com/sovdee/skriptparticles/SkriptParticle.java @@ -22,12 +22,12 @@ public class SkriptParticle extends JavaPlugin { // todo, next release // custom shapes // icosphere + // expressions for particles // todo, later versions // beziers // better triangle filling (basically allow any 3d model) // gradients // text rendering - // animation? @Nullable public static SkriptParticle getInstance() { diff --git a/src/main/java/com/sovdee/skriptparticles/elements/expressions/ExprCustomParticle.java b/src/main/java/com/sovdee/skriptparticles/elements/expressions/ExprCustomParticle.java index 9f115fd..be98835 100644 --- a/src/main/java/com/sovdee/skriptparticles/elements/expressions/ExprCustomParticle.java +++ b/src/main/java/com/sovdee/skriptparticles/elements/expressions/ExprCustomParticle.java @@ -35,10 +35,14 @@ public class ExprCustomParticle extends SimpleExpression { "[with offset %-vector%] [with extra %-number%] [force:with force]"); } + @Nullable private Expression count; private Expression particle; + @Nullable private Expression data; + @Nullable private Expression offset; + @Nullable private Expression extra; private boolean force; @@ -56,7 +60,8 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye @Override @Nullable protected Particle[] get(Event event) { - Object particleExpr = this.particle.getSingle(event); + @Nullable Object particleExpr = this.particle.getSingle(event); + if (particleExpr == null) return new Particle[0]; Particle particle; if (particleExpr instanceof Particle) { @@ -66,9 +71,10 @@ protected Particle[] get(Event event) { } else { return new Particle[0]; } + particle = particle.clone(); if (count != null) { - Number count = this.count.getSingle(event); + @Nullable Number count = this.count.getSingle(event); if (count != null) { particle.count(count.intValue()); } else { @@ -78,7 +84,7 @@ protected Particle[] get(Event event) { } if (data != null) { - Object data = this.data.getSingle(event); + @Nullable Object data = this.data.getSingle(event); if (data instanceof ItemType itemType) { data = itemType.getRandom(); } @@ -86,12 +92,12 @@ protected Particle[] get(Event event) { } if (offset != null) { - Vector offset = this.offset.getSingle(event); + @Nullable Vector offset = this.offset.getSingle(event); if (offset != null) particle.offset(offset.getX(), offset.getY(), offset.getZ()); } if (extra != null) { - Number extra = this.extra.getSingle(event); + @Nullable Number extra = this.extra.getSingle(event); if (extra != null) particle.extra(extra.doubleValue()); } @@ -111,7 +117,7 @@ public Class getReturnType() { } @Override - public String toString(@Nullable Event e, boolean debug) { + public String toString(@Nullable Event event, boolean debug) { return "custom particle"; } diff --git a/src/main/java/com/sovdee/skriptparticles/elements/expressions/ExprLastCreatedParticle.java b/src/main/java/com/sovdee/skriptparticles/elements/expressions/ExprLastCreatedParticle.java index 123a32f..9df8fb4 100644 --- a/src/main/java/com/sovdee/skriptparticles/elements/expressions/ExprLastCreatedParticle.java +++ b/src/main/java/com/sovdee/skriptparticles/elements/expressions/ExprLastCreatedParticle.java @@ -32,7 +32,7 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye @Override @Nullable - protected Particle[] get(Event evente) { + protected Particle[] get(Event event) { return new Particle[]{SecParticle.lastCreatedParticle}; } diff --git a/src/main/java/com/sovdee/skriptparticles/elements/expressions/ExprRotation.java b/src/main/java/com/sovdee/skriptparticles/elements/expressions/ExprRotation.java index edafec8..a270f41 100644 --- a/src/main/java/com/sovdee/skriptparticles/elements/expressions/ExprRotation.java +++ b/src/main/java/com/sovdee/skriptparticles/elements/expressions/ExprRotation.java @@ -33,9 +33,13 @@ public class ExprRotation extends SimpleExpression { "[the|a] rotation (from|between) %vector% (to|and) %vector%"); } + @Nullable private Expression angle; + @Nullable private Expression axis; + @Nullable private Expression from; + @Nullable private Expression to; private boolean isRadians = false; @@ -55,20 +59,22 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye @Override @Nullable protected Quaternion[] get(Event event) { - if (axis != null) { - Vector axis = this.axis.getSingle(event); - Number angle = this.angle.getSingle(event); + if (axis != null && angle != null) { + @Nullable Vector axis = this.axis.getSingle(event); + @Nullable Number angle = this.angle.getSingle(event); if (axis == null || angle == null) - return null; + return new Quaternion[0]; float angleFloat = angle.floatValue(); if (!isRadians) angleFloat = (float) Math.toRadians(angleFloat); return new Quaternion[]{new Quaternion().rotationAxis(angleFloat, axis)}; } else { - Vector from = this.from.getSingle(event); - Vector to = this.to.getSingle(event); if (from == null || to == null) - return null; + return new Quaternion[0]; + @Nullable Vector from = this.from.getSingle(event); + @Nullable Vector to = this.to.getSingle(event); + if (from == null || to == null) + return new Quaternion[0]; return new Quaternion[]{new Quaternion().rotationTo(from, to)}; } } @@ -84,10 +90,10 @@ public Class getReturnType() { } @Override - public String toString(@Nullable Event e, boolean debug) { + public String toString(@Nullable Event event, boolean debug) { if (axis == null) - return "rotation from " + from.toString(e, debug) + " to " + to.toString(e, debug); - return "rotation around " + axis.toString(e, debug) + " by " + angle.toString(e, debug) + (isRadians ? " radians" : " degrees"); + return "rotation from " + (from != null ? from.toString(event, debug) : "null") + " to " + (to != null ? to.toString(event, debug) : "null"); + return "rotation around " + axis.toString(event, debug) + " by " + (angle != null ? angle.toString(event, debug) : "null") + (isRadians ? " radians" : " degrees"); } } diff --git a/src/main/java/com/sovdee/skriptparticles/elements/expressions/ExprShapeCopy.java b/src/main/java/com/sovdee/skriptparticles/elements/expressions/ExprShapeCopy.java index bc73aa9..9861c9e 100644 --- a/src/main/java/com/sovdee/skriptparticles/elements/expressions/ExprShapeCopy.java +++ b/src/main/java/com/sovdee/skriptparticles/elements/expressions/ExprShapeCopy.java @@ -28,13 +28,13 @@ public class ExprShapeCopy extends SimpleExpression { static { - Skript.registerExpression(ExprShapeCopy.class, Shape.class, ExpressionType.SIMPLE, "[a] cop(y|ies) of %shapes%"); + Skript.registerExpression(ExprShapeCopy.class, Shape.class, ExpressionType.SIMPLE, "[a] shape cop(y|ies) of %shapes%"); } - Expression shapeExpr; + private Expression shapeExpr; @Override - public boolean init(Expression[] expressions, int i, Kleenean kleenean, ParseResult parseResult) { + public boolean init(Expression[] expressions, int matchedPattern, Kleenean kleenean, ParseResult parseResult) { shapeExpr = (Expression) expressions[0]; return true; } @@ -65,7 +65,7 @@ public Class getReturnType() { } @Override - public String toString(@Nullable Event event, boolean b) { + public String toString(@Nullable Event event, boolean debug) { return "shape copy"; } } diff --git a/src/main/java/com/sovdee/skriptparticles/elements/expressions/constructors/ExprHelix.java b/src/main/java/com/sovdee/skriptparticles/elements/expressions/constructors/ExprHelix.java index 72f3280..87ecbef 100644 --- a/src/main/java/com/sovdee/skriptparticles/elements/expressions/constructors/ExprHelix.java +++ b/src/main/java/com/sovdee/skriptparticles/elements/expressions/constructors/ExprHelix.java @@ -15,7 +15,7 @@ import com.sovdee.skriptparticles.shapes.Shape.Style; import com.sovdee.skriptparticles.util.MathUtil; import org.bukkit.event.Event; -import org.jetbrains.annotations.Nullable; +import org.checkerframework.checker.nullness.qual.Nullable; @Name("Particle Helix / Spiral") @Description({ @@ -38,6 +38,7 @@ public class ExprHelix extends SimpleExpression { private Expression radius; private Expression height; + @Nullable private Expression windingRate; private boolean isClockwise = true; private Style style; @@ -75,11 +76,12 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye @Override @Nullable protected Helix[] get(Event event) { - Number radius = this.radius.getSingle(event); - Number height = this.height.getSingle(event); - Number windingRate = this.windingRate == null ? 1 : this.windingRate.getSingle(event); + @Nullable Number radius = this.radius.getSingle(event); + @Nullable Number height = this.height.getSingle(event); + @Nullable Number windingRate = this.windingRate == null ? 1 : this.windingRate.getSingle(event); if (radius == null || height == null || windingRate == null) - return null; + return new Helix[0]; + radius = Math.max(radius.doubleValue(), MathUtil.EPSILON); height = Math.max(height.doubleValue(), MathUtil.EPSILON); double slope = 1.0 / Math.max(windingRate.doubleValue(), MathUtil.EPSILON); diff --git a/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprHelixWindingRate.java b/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprHelixWindingRate.java index 82e8ddf..0ddb67f 100644 --- a/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprHelixWindingRate.java +++ b/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprHelixWindingRate.java @@ -42,7 +42,7 @@ public Number convert(Shape shape) { public Class[] acceptChange(ChangeMode mode) { return switch (mode) { case SET, DELETE, ADD, REMOVE, RESET -> new Class[]{Number.class}; - default -> null; + default -> new Class[0]; }; } diff --git a/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeCutoffAngle.java b/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeCutoffAngle.java index 3069b7c..bde824c 100644 --- a/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeCutoffAngle.java +++ b/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeCutoffAngle.java @@ -38,12 +38,12 @@ public class ExprShapeCutoffAngle extends SimplePropertyExpression[] acceptChange(ChangeMode mode) { return switch (mode) { case SET, RESET, DELETE, ADD, REMOVE -> new Class[]{Number.class}; - case REMOVE_ALL -> null; + case REMOVE_ALL -> new Class[0]; }; } @Override - public void change(Event event, @Nullable Object[] delta, ChangeMode mode) { + public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { double angle = 0; if (delta != null && delta.length != 0) angle = ((Number) delta[0]).doubleValue(); diff --git a/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeLWH.java b/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeLWH.java index 07ea2ee..3c6ea01 100644 --- a/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeLWH.java +++ b/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeLWH.java @@ -57,12 +57,12 @@ public Number convert(LWHShape lwhShape) { public Class[] acceptChange(ChangeMode mode) { return switch (mode) { case SET, DELETE, RESET, ADD, REMOVE -> new Class[]{Number.class}; - default -> null; + default -> new Class[0]; }; } @Override - public void change(Event event, @Nullable Object[] delta, ChangeMode mode) { + public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { double value = 1; if (delta != null && delta.length != 0) value = ((Number) delta[0]).doubleValue(); @@ -108,7 +108,7 @@ protected String getPropertyName() { case 0 -> "length"; case 1 -> "width"; case 2 -> "height"; - default -> null; + default -> "unknown"; }; } diff --git a/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeLocations.java b/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeLocations.java index e9c6ea7..f31e263 100644 --- a/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeLocations.java +++ b/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeLocations.java @@ -9,15 +9,15 @@ import ch.njol.skript.lang.ExpressionType; import ch.njol.skript.lang.SkriptParser; import ch.njol.skript.lang.util.SimpleExpression; +import ch.njol.skript.util.Direction; import ch.njol.util.Kleenean; import com.sovdee.skriptparticles.shapes.Shape; import org.bukkit.Location; import org.bukkit.event.Event; import org.checkerframework.checker.nullness.qual.NonNull; -import org.jetbrains.annotations.Nullable; +import org.checkerframework.checker.nullness.qual.Nullable; import java.util.ArrayList; -import java.util.stream.Collectors; @Name("Shape Locations") @Description({ @@ -35,7 +35,7 @@ public class ExprShapeLocations extends SimpleExpression { static { - Skript.registerExpression(ExprShapeLocations.class, Location.class, ExpressionType.COMBINED, "[particle] locations of %shapes% [[centered] %direction% %location%]"); + Skript.registerExpression(ExprShapeLocations.class, Location.class, ExpressionType.COMBINED, "[particle] locations of %shapes% [[centered] [%-direction%] %location%]"); } private Expression shapeExpr; @@ -44,23 +44,26 @@ public class ExprShapeLocations extends SimpleExpression { @Override public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { shapeExpr = (Expression) exprs[0]; - locationExpr = (Expression) exprs[1]; + locationExpr = (Expression) exprs[2]; + if (exprs[1] != null) + locationExpr = Direction.combine((Expression) exprs[1], locationExpr); return true; } @Override @Nullable - protected Location[] get(@NonNull Event event) { + protected Location[] get(Event event) { Shape[] shapes = shapeExpr.getAll(event); - if (shapes.length == 0) return null; + if (shapes.length == 0) return new Location[0]; - Location center = locationExpr.getSingle(event); - if (center == null) return null; + @Nullable Location center = locationExpr.getSingle(event); + + if (center == null) return new Location[0]; ArrayList locations = new ArrayList<>(); for (Shape shape : shapes) { - locations.addAll(shape.getPoints().stream().map(point -> center.clone().add(point)).collect(Collectors.toList())); + locations.addAll(shape.getPoints().stream().map(point -> center.clone().add(point)).toList()); } return locations.toArray(new Location[0]); } diff --git a/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeNormal.java b/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeNormal.java index dada3c4..c74ad03 100644 --- a/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeNormal.java +++ b/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeNormal.java @@ -41,12 +41,12 @@ public Vector convert(Shape shape) { public Class[] acceptChange(ChangeMode mode) { return switch (mode) { case SET, RESET, DELETE -> new Class[]{Vector.class}; - case ADD, REMOVE, REMOVE_ALL -> null; + case ADD, REMOVE, REMOVE_ALL -> new Class[0]; }; } @Override - public void change(Event event, @Nullable Object[] delta, ChangeMode mode) { + public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { switch (mode) { case SET: if (delta == null || delta.length == 0) return; diff --git a/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeOffset.java b/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeOffset.java index 306f390..5a4ec56 100644 --- a/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeOffset.java +++ b/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeOffset.java @@ -38,12 +38,12 @@ public class ExprShapeOffset extends SimplePropertyExpression { public Class[] acceptChange(ChangeMode mode) { return switch (mode) { case SET, RESET, DELETE -> new Class[]{Vector.class}; - case ADD, REMOVE, REMOVE_ALL -> null; + case ADD, REMOVE, REMOVE_ALL -> new Class[0]; }; } @Override - public void change(Event event, @Nullable Object[] delta, ChangeMode mode) { + public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { switch (mode) { case SET: if (delta == null || delta.length == 0) diff --git a/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeOrientation.java b/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeOrientation.java index 98d4f6c..efe5ed6 100644 --- a/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeOrientation.java +++ b/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeOrientation.java @@ -43,12 +43,12 @@ public Quaternion convert(Shape shape) { public Class[] acceptChange(ChangeMode mode) { return switch (mode) { case SET, RESET, DELETE -> new Class[]{Quaternion.class}; - case ADD, REMOVE, REMOVE_ALL -> null; + case ADD, REMOVE, REMOVE_ALL -> new Class[0]; }; } @Override - public void change(Event event, @Nullable Object[] delta, ChangeMode mode) { + public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { switch (mode) { case SET: if (delta == null || delta.length == 0) return; diff --git a/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeParticle.java b/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeParticle.java index 8d7c3a3..6ff255e 100644 --- a/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeParticle.java +++ b/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeParticle.java @@ -49,12 +49,12 @@ public Particle convert(Shape shape) { public Class[] acceptChange(ChangeMode mode) { return switch (mode) { case SET, RESET, DELETE -> new Class[]{Particle.class}; - case ADD, REMOVE, REMOVE_ALL -> null; + case ADD, REMOVE, REMOVE_ALL -> new Class[0]; }; } @Override - public void change(Event event, @Nullable Object[] delta, ChangeMode mode) { + public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { switch (mode) { case SET: if (delta == null || delta.length == 0) return; diff --git a/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeParticleDensity.java b/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeParticleDensity.java index e87f232..c5bb4f2 100644 --- a/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeParticleDensity.java +++ b/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeParticleDensity.java @@ -65,18 +65,16 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye public Class[] acceptChange(ChangeMode mode) { return switch (mode) { case ADD, REMOVE, SET, RESET, DELETE -> new Class[]{Number.class}; - case REMOVE_ALL -> null; + case REMOVE_ALL -> new Class[0]; }; } @Override - public void change(Event event, @Nullable Object[] delta, ChangeMode mode) { - if (delta == null || delta.length == 0) - return; + public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { Shape[] shapes = getExpr().getArray(event); if (shapes.length == 0) return; - double change = (delta[0] == null) ? 0.25 : ((Number) delta[0]).doubleValue(); + double change = (delta == null) ? 0.25 : ((Number) delta[0]).doubleValue(); switch (mode) { case REMOVE: change = -change; diff --git a/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeRadius.java b/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeRadius.java index 068d3d3..f3cda5e 100644 --- a/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeRadius.java +++ b/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeRadius.java @@ -40,19 +40,17 @@ public Number convert(RadialShape shape) { public Class[] acceptChange(ChangeMode mode) { return switch (mode) { case SET, RESET, DELETE, ADD, REMOVE -> new Class[]{Number.class}; - case REMOVE_ALL -> null; + case REMOVE_ALL -> new Class[0]; }; } @Override - public void change(Event event, @Nullable Object[] delta, ChangeMode mode) { - if ((mode == ChangeMode.ADD || mode == ChangeMode.SET || mode == ChangeMode.REMOVE) && (delta == null || delta.length == 0)) - return; + public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { RadialShape[] radialShapes = getExpr().getArray(event); if (radialShapes.length == 0) return; - double deltaValue = (delta[0] != null) ? ((Number) delta[0]).doubleValue() : 1; + double deltaValue = (delta != null) ? ((Number) delta[0]).doubleValue() : 1; switch (mode) { case REMOVE: deltaValue = -deltaValue; diff --git a/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeRelativeAxis.java b/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeRelativeAxis.java index 75991fc..c856f67 100644 --- a/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeRelativeAxis.java +++ b/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeRelativeAxis.java @@ -43,16 +43,12 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye @Override public @Nullable Vector convert(Shape shape) { - switch (axis) { - case 0: - return shape.getRelativeXAxis(false); - case 1: - return shape.getRelativeYAxis(false); - case 2: - return shape.getRelativeZAxis(false); - default: - return null; - } + return switch (axis) { + case 0 -> shape.getRelativeXAxis(false); + case 1 -> shape.getRelativeYAxis(false); + case 2 -> shape.getRelativeZAxis(false); + default -> null; + }; } @Override diff --git a/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeScale.java b/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeScale.java index 0eac2a0..c386fc1 100644 --- a/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeScale.java +++ b/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeScale.java @@ -39,19 +39,19 @@ public class ExprShapeScale extends SimplePropertyExpression { public @Nullable Class[] acceptChange(ChangeMode mode) { return switch (mode) { case SET, RESET, DELETE, ADD, REMOVE -> new Class[]{Number.class}; - case REMOVE_ALL -> null; + case REMOVE_ALL -> new Class[0]; }; } @Override - public void change(Event event, @Nullable Object[] delta, ChangeMode mode) { + public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { if ((mode == ChangeMode.ADD || mode == ChangeMode.SET || mode == ChangeMode.REMOVE) && (delta == null || delta.length == 0)) return; Shape[] shapes = getExpr().getArray(event); if (shapes.length == 0) return; - double change = (delta[0] != null) ? ((Number) delta[0]).doubleValue() : 1; + double change = (delta != null) ? ((Number) delta[0]).doubleValue() : 1; switch (mode) { case REMOVE: change = -change; diff --git a/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeSideLength.java b/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeSideLength.java index adc73bf..5222127 100644 --- a/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeSideLength.java +++ b/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeSideLength.java @@ -40,16 +40,13 @@ public Number convert(PolyShape polyShape) { public Class[] acceptChange(ChangeMode mode) { return switch (mode) { case SET, ADD, REMOVE, DELETE, RESET -> new Class[]{Number.class}; - case REMOVE_ALL -> null; + case REMOVE_ALL -> new Class[0]; }; } @Override - public void change(Event event, @Nullable Object[] delta, ChangeMode mode) { - if ((mode == ChangeMode.ADD || mode == ChangeMode.SET || mode == ChangeMode.REMOVE) && (delta == null || delta.length == 0)) - return; - - double change = (delta[0] != null) ? ((Number) delta[0]).doubleValue() : 1; + public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { + double change = (delta != null) ? ((Number) delta[0]).doubleValue() : 1; switch (mode) { case REMOVE: diff --git a/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeSides.java b/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeSides.java index 36cca02..aea404d 100644 --- a/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeSides.java +++ b/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeSides.java @@ -40,16 +40,13 @@ public Integer convert(PolyShape polyShape) { public Class[] acceptChange(ChangeMode mode) { return switch (mode) { case SET, RESET, DELETE, ADD, REMOVE -> new Class[]{Number.class}; - case REMOVE_ALL -> null; + case REMOVE_ALL -> new Class[0]; }; } @Override - public void change(Event event, @Nullable Object[] delta, ChangeMode mode) { - if ((mode == ChangeMode.ADD || mode == ChangeMode.SET || mode == ChangeMode.REMOVE) && (delta == null || delta.length == 0)) - return; - - int change = (delta[0] != null) ? ((Number) delta[0]).intValue() : 3; + public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { + int change = (delta != null) ? ((Number) delta[0]).intValue() : 3; switch (mode) { case REMOVE: diff --git a/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeStyle.java b/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeStyle.java index 7134aed..e4f27ec 100644 --- a/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeStyle.java +++ b/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprShapeStyle.java @@ -39,12 +39,12 @@ public Shape.Style convert(Shape shape) { public Class[] acceptChange(ChangeMode mode) { return switch (mode) { case SET -> new Class[]{Shape.Style.class}; - case ADD, REMOVE, REMOVE_ALL, DELETE, RESET -> null; + case ADD, REMOVE, REMOVE_ALL, DELETE, RESET -> new Class[0]; }; } @Override - public void change(Event event, @Nullable Object[] delta, ChangeMode mode) { + public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { if (delta == null || delta.length != 1) return; Shape.Style style = (Shape.Style) delta[0]; for (Shape shape : getExpr().getArray(event)) { diff --git a/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprStarPoints.java b/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprStarPoints.java index 419dae5..9e493e3 100644 --- a/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprStarPoints.java +++ b/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprStarPoints.java @@ -39,12 +39,12 @@ public class ExprStarPoints extends SimplePropertyExpression { public @Nullable Class[] acceptChange(Changer.ChangeMode mode) { return switch (mode) { case SET, ADD, REMOVE -> new Class[]{Number.class}; - default -> null; + default -> new Class[0]; }; } @Override - public void change(Event event, @Nullable Object[] delta, Changer.ChangeMode mode) { + public void change(Event event, Object @Nullable [] delta, Changer.ChangeMode mode) { if (delta == null || delta.length == 0) return; Shape[] shapes = getExpr().getArray(event); diff --git a/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprStarRadii.java b/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprStarRadii.java index 48f99d5..1bb94a9 100644 --- a/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprStarRadii.java +++ b/src/main/java/com/sovdee/skriptparticles/elements/expressions/properties/ExprStarRadii.java @@ -53,12 +53,12 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye public @Nullable Class[] acceptChange(Changer.ChangeMode mode) { return switch (mode) { case SET, ADD, REMOVE -> new Class[]{Number.class}; - default -> null; + default -> new Class[0]; }; } @Override - public void change(Event event, @Nullable Object[] delta, Changer.ChangeMode mode) { + public void change(Event event, Object @Nullable [] delta, Changer.ChangeMode mode) { if (delta == null || delta.length == 0) return; double deltaValue = ((Number) delta[0]).doubleValue(); diff --git a/src/main/java/com/sovdee/skriptparticles/elements/package-info.java b/src/main/java/com/sovdee/skriptparticles/elements/package-info.java new file mode 100644 index 0000000..4786bc5 --- /dev/null +++ b/src/main/java/com/sovdee/skriptparticles/elements/package-info.java @@ -0,0 +1,5 @@ +@DefaultQualifier(NonNull.class) +package com.sovdee.skriptparticles.elements; + +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.framework.qual.DefaultQualifier; diff --git a/src/main/java/com/sovdee/skriptparticles/elements/sections/DrawShapeEffectSection.java b/src/main/java/com/sovdee/skriptparticles/elements/sections/DrawShapeEffectSection.java index 0a586d9..ad80e44 100644 --- a/src/main/java/com/sovdee/skriptparticles/elements/sections/DrawShapeEffectSection.java +++ b/src/main/java/com/sovdee/skriptparticles/elements/sections/DrawShapeEffectSection.java @@ -25,7 +25,7 @@ import org.bukkit.event.HandlerList; import org.bukkit.scheduler.BukkitRunnable; import org.checkerframework.checker.nullness.qual.NonNull; -import org.jetbrains.annotations.Nullable; +import org.checkerframework.checker.nullness.qual.Nullable; import java.util.ArrayList; import java.util.Collection; @@ -47,8 +47,11 @@ public Shape get(DrawEvent event) { } protected Expression shapes; + @Nullable protected Expression directions; + @Nullable protected Expression locations; + @Nullable protected Expression players; @Nullable private Trigger trigger; diff --git a/src/main/java/com/sovdee/skriptparticles/elements/sections/EffSecDrawShape.java b/src/main/java/com/sovdee/skriptparticles/elements/sections/EffSecDrawShape.java index 7135d88..a4f5003 100644 --- a/src/main/java/com/sovdee/skriptparticles/elements/sections/EffSecDrawShape.java +++ b/src/main/java/com/sovdee/skriptparticles/elements/sections/EffSecDrawShape.java @@ -17,7 +17,7 @@ import org.bukkit.event.Event; import org.bukkit.scheduler.BukkitRunnable; import org.checkerframework.checker.nullness.qual.NonNull; -import org.jetbrains.annotations.Nullable; +import org.checkerframework.checker.nullness.qual.Nullable; import java.util.Collection; import java.util.concurrent.atomic.AtomicLong; @@ -66,7 +66,9 @@ public Shape get(EffSecDrawShape.DrawEvent event) { }, EventValues.TIME_NOW); } + @Nullable private Expression duration; + @Nullable private Expression delay; @Override @@ -81,12 +83,12 @@ public boolean init(Expression[] expressions, int matchedPattern, Kleenean is @Override protected void setupAsync(Event event, Collection locations, Collection shapes, Collection recipients) { long period, iterations; - if (duration == null) { + if (this.duration == null) { period = 1; iterations = 1; } else { - Timespan delay = (this.delay == null ? ONE_TICK : this.delay.getSingle(event)); - Timespan duration = this.duration.getSingle(event); + @Nullable Timespan delay = (this.delay == null ? ONE_TICK : this.delay.getSingle(event)); + @Nullable Timespan duration = this.duration.getSingle(event); if (delay == null || duration == null) return; period = Math.max(delay.getTicks_i(), 1); diff --git a/src/main/java/com/sovdee/skriptparticles/elements/sections/EffSecDrawShapeAnimation.java b/src/main/java/com/sovdee/skriptparticles/elements/sections/EffSecDrawShapeAnimation.java index b0e6bb0..ef248b0 100644 --- a/src/main/java/com/sovdee/skriptparticles/elements/sections/EffSecDrawShapeAnimation.java +++ b/src/main/java/com/sovdee/skriptparticles/elements/sections/EffSecDrawShapeAnimation.java @@ -62,7 +62,7 @@ protected void setupAsync(Event event, Collection locations, Co @Override @NonNull public String toString(@Nullable Event event, boolean debug) { - return "draw an animation of the shape of " + shapes.toString(event, debug) + " at " + locations.toString(event, debug) + + return "draw an animation of the shape of " + shapes.toString(event, debug) + " at " + (locations != null ? locations.toString(event, debug) : "shape's location") + " for " + (players == null ? "all players" : players.toString(event, debug) + " over " + duration.toString(event, debug)); } } diff --git a/src/main/java/com/sovdee/skriptparticles/elements/sections/SecParticle.java b/src/main/java/com/sovdee/skriptparticles/elements/sections/SecParticle.java index c2cfeaf..f9adb3c 100644 --- a/src/main/java/com/sovdee/skriptparticles/elements/sections/SecParticle.java +++ b/src/main/java/com/sovdee/skriptparticles/elements/sections/SecParticle.java @@ -18,7 +18,7 @@ import com.sovdee.skriptparticles.util.ParticleUtil; import org.bukkit.event.Event; import org.bukkit.util.Vector; -import org.jetbrains.annotations.Nullable; +import org.checkerframework.checker.nullness.qual.Nullable; import org.skriptlang.skript.lang.entry.EntryContainer; import org.skriptlang.skript.lang.entry.EntryValidator; import org.skriptlang.skript.lang.entry.util.ExpressionEntryData; @@ -56,6 +56,7 @@ }) @Since("1.0.2") public class SecParticle extends Section { + @Nullable public static Particle lastCreatedParticle; private static final EntryValidator validator = EntryValidator.builder() .addEntryData(new ExpressionEntryData<>("count", new SimpleLiteral<>(1, false), false, Number.class)) @@ -76,20 +77,25 @@ public class SecParticle extends Section { //- - if particle is dust, allow "color: color" and "size: double" //- force: boolean static { - Skript.registerSection(SecParticle.class, "create [a] [new] custom %particle% [particle]"); + Skript.registerSection(SecParticle.class, "create [a] [new] custom %particle% [particle] [with]"); } private Expression particle; private Expression count; + @Nullable private Expression offset; + @Nullable private Expression velocity; + @Nullable private Expression extra; + @Nullable private Expression data; + @Nullable private Expression force; @Override public boolean init(Expression[] expressions, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult, SectionNode sectionNode, List triggerItems) { - EntryContainer entryContainer = validator.validate(sectionNode); + @Nullable EntryContainer entryContainer = validator.validate(sectionNode); if (entryContainer == null) return false; @@ -133,21 +139,21 @@ protected TriggerItem walk(Event event) { } private void execute(Event event) { - org.bukkit.Particle bukkitParticle = this.particle.getSingle(event); + org.bukkit. @Nullable Particle bukkitParticle = this.particle.getSingle(event); if (bukkitParticle == null) return; - Number count = this.count.getSingle(event); + @Nullable Number count = this.count.getSingle(event); if (count == null) return; - Vector offset = this.offset != null ? this.offset.getSingle(event) : null; - Number extra = this.extra != null ? this.extra.getSingle(event) : null; - Object data = this.data != null ? this.data.getSingle(event) : null; - Boolean force = this.force != null ? this.force.getSingle(event) : null; + @Nullable Vector offset = this.offset != null ? this.offset.getSingle(event) : null; + @Nullable Number extra = this.extra != null ? this.extra.getSingle(event) : null; + @Nullable Object data = this.data != null ? this.data.getSingle(event) : null; + @Nullable Boolean force = this.force != null ? this.force.getSingle(event) : null; Particle particle = (Particle) new Particle(bukkitParticle).count(count.intValue()); if (velocity != null) { - Object v = velocity.getSingle(event); + @Nullable Object v = velocity.getSingle(event); if (v instanceof ParticleMotion motion) { particle.motion(motion); } else if (v instanceof Vector vector) { diff --git a/src/main/java/com/sovdee/skriptparticles/elements/types/ParticleTypes.java b/src/main/java/com/sovdee/skriptparticles/elements/types/ParticleTypes.java index 687e595..c3e16a9 100644 --- a/src/main/java/com/sovdee/skriptparticles/elements/types/ParticleTypes.java +++ b/src/main/java/com/sovdee/skriptparticles/elements/types/ParticleTypes.java @@ -1,6 +1,7 @@ package com.sovdee.skriptparticles.elements.types; import ch.njol.skript.classes.ClassInfo; +import ch.njol.skript.classes.EnumClassInfo; import ch.njol.skript.classes.Parser; import ch.njol.skript.lang.ParseContext; import ch.njol.skript.lang.function.Functions; @@ -45,7 +46,6 @@ public class ParticleTypes { .since("1.0.0") .parser(new Parser<>() { - @SuppressWarnings("NullableProblems") @Nullable @Override public Particle parse(String s, ParseContext context) { @@ -71,7 +71,6 @@ public Particle parse(String s, ParseContext context) { .description("Represents a particle with extra data, including offset, count, data, and more.") .parser(new Parser<>() { - @SuppressWarnings("NullableProblems") @Nullable @Override public com.sovdee.skriptparticles.particles.Particle parse(String s, ParseContext context) { @@ -96,41 +95,10 @@ public boolean canParse(ParseContext context) { ); // Particle motion class - Classes.registerClass(new ClassInfo<>(ParticleMotion.class, "particlemotion") + Classes.registerClass(new EnumClassInfo<>(ParticleMotion.class, "particlemotion", "particle motions") .user("particle ?motions?") .name("Particle Motion") - .description("Represents the motion of a particle relative to a shape, ie: inwards, outwards, clockwise, etc.") - .parser(new Parser<>() { - - @SuppressWarnings("NullableProblems") - @Nullable - @Override - public ParticleMotion parse(String s, ParseContext context) { - return switch (s.toLowerCase()) { - case "inwards motion" -> ParticleMotion.INWARDS; - case "outwards motion" -> ParticleMotion.OUTWARDS; - case "clockwise motion" -> ParticleMotion.CLOCKWISE; - case "counterclockwise motion" -> ParticleMotion.COUNTERCLOCKWISE; - case "no motion" -> ParticleMotion.NONE; - default -> null; - }; - } - - @Override - public boolean canParse(ParseContext context) { - return true; - } - - @Override - public @NonNull String toString(ParticleMotion particleMotion, int flags) { - return particleMotion.toString(); - } - - @Override - public @NonNull String toVariableNameString(ParticleMotion particle) { - return "particle motion:" + toString(particle, 0); - } - }) + .description("Represents the motion of a particle relative to a shape.") ); Converters.registerConverter(Particle.class, com.sovdee.skriptparticles.particles.Particle.class, (particle) -> (com.sovdee.skriptparticles.particles.Particle) new com.sovdee.skriptparticles.particles.Particle(particle).count(1).extra(0)); @@ -145,7 +113,6 @@ public boolean canParse(ParseContext context) { new Parameter<>("color", DefaultClasses.COLOR, true, null), new Parameter<>("size", DefaultClasses.NUMBER, true, null) }, Classes.getExactClassInfo(DustOptions.class), true) { - @SuppressWarnings("NullableProblems") @Override public DustOptions[] executeSimple(Object[][] params) { org.bukkit.Color color = ((Color) params[0][0]).asBukkitColor(); @@ -170,7 +137,6 @@ public DustOptions[] executeSimple(Object[][] params) { new Parameter<>("toColor", DefaultClasses.COLOR, true, null), new Parameter<>("size", DefaultClasses.NUMBER, true, null) }, Classes.getExactClassInfo(DustTransition.class), true) { - @SuppressWarnings("NullableProblems") @Override public DustTransition[] executeSimple(Object[][] params) { org.bukkit.Color fromColor = ((Color) params[0][0]).asBukkitColor(); @@ -197,11 +163,10 @@ public DustTransition[] executeSimple(Object[][] params) { new Parameter<>("to", DefaultClasses.LOCATION, true, null), new Parameter<>("arrivalTime", DefaultClasses.TIMESPAN, true, null) }, Classes.getExactClassInfo(Vibration.class), true) { - @SuppressWarnings("NullableProblems") @Override public Vibration[] executeSimple(Object[][] params) { if (params[0].length == 0 || params[1].length == 0) { - return null; + return new Vibration[0]; } Location destination = (Location) params[0][0]; int arrivalTime = (int) ((Timespan) params[1][0]).getTicks_i(); diff --git a/src/main/java/com/sovdee/skriptparticles/elements/types/RotationTypes.java b/src/main/java/com/sovdee/skriptparticles/elements/types/RotationTypes.java index 24a142a..2c22bcc 100644 --- a/src/main/java/com/sovdee/skriptparticles/elements/types/RotationTypes.java +++ b/src/main/java/com/sovdee/skriptparticles/elements/types/RotationTypes.java @@ -62,7 +62,6 @@ public String toVariableNameString(Quaternionf quaternion) { new Parameter<>("z", DefaultClasses.NUMBER, true, new SimpleLiteral(0, true)), new Parameter<>("w", DefaultClasses.NUMBER, true, new SimpleLiteral(1, true)) }, Classes.getExactClassInfo(Quaternionf.class), true) { - @SuppressWarnings("NullableProblems") @Override public @Nullable Quaternionf[] executeSimple(Object[][] params) { float w = ((Number) params[0][0]).floatValue(); @@ -84,7 +83,6 @@ public String toVariableNameString(Quaternionf quaternion) { new Parameter<>("y", DefaultClasses.NUMBER, true, null), new Parameter<>("z", DefaultClasses.NUMBER, true, null) }, Classes.getExactClassInfo(Quaternionf.class), true) { - @SuppressWarnings("NullableProblems") @Override public @Nullable Quaternionf[] executeSimple(Object[][] params) { float angle = ((Number) params[0][0]).floatValue(); @@ -107,7 +105,6 @@ public String toVariableNameString(Quaternionf quaternion) { new Parameter<>("y", DefaultClasses.NUMBER, true, null), new Parameter<>("z", DefaultClasses.NUMBER, true, null) }, Classes.getExactClassInfo(Quaternionf.class), true) { - @SuppressWarnings("NullableProblems") @Override public @Nullable Quaternionf[] executeSimple(Object[][] params) { float angle = ((Number) params[0][0]).floatValue() * (float) Math.PI / 180; diff --git a/src/main/java/com/sovdee/skriptparticles/elements/types/ShapeTypes.java b/src/main/java/com/sovdee/skriptparticles/elements/types/ShapeTypes.java index e031dc5..474790f 100644 --- a/src/main/java/com/sovdee/skriptparticles/elements/types/ShapeTypes.java +++ b/src/main/java/com/sovdee/skriptparticles/elements/types/ShapeTypes.java @@ -194,7 +194,7 @@ public String toString(Shape.Style style, int i) { @Override public String toVariableNameString(Shape.Style style) { - return "shapestyle:" + style.toString(); + return "shapestyle:" + style; } })); } diff --git a/src/main/java/com/sovdee/skriptparticles/particles/ParticleMotion.java b/src/main/java/com/sovdee/skriptparticles/particles/ParticleMotion.java index 25c3559..a60efb7 100644 --- a/src/main/java/com/sovdee/skriptparticles/particles/ParticleMotion.java +++ b/src/main/java/com/sovdee/skriptparticles/particles/ParticleMotion.java @@ -23,10 +23,10 @@ public Vector getMotionVector(Vector axis, Vector point) { } private Vector getAntiClockwiseMotion(Vector axis, Vector point) { - return axis.getCrossProduct(point); + return axis.getCrossProduct(point).normalize(); } private Vector getOutwardsMotion(Vector point) { - return point.clone(); + return point.clone().normalize(); } } diff --git a/src/main/resources/lang/english.lang b/src/main/resources/lang/english.lang index ff1f8ff..5f8d858 100644 --- a/src/main/resources/lang/english.lang +++ b/src/main/resources/lang/english.lang @@ -9,3 +9,10 @@ types: cutoffshape: cutoff shape¦s polyshape: polygonal shape¦s shapestyle: shape style¦s + +particle motions: + inwards: inwards, inwards motion, towards center, towards the center + outwards: outwards, outwards motion, away from center, away from the center + clockwise: clockwise, clockwise motion + counterclockwise: anticlockwise, anticlockwise motion, counterclockwise, counterclockwise motion + none: none, no motion