Skip to content

Commit

Permalink
mainly ParticleMotion improvements and CQI
Browse files Browse the repository at this point in the history
  • Loading branch information
sovdeeth committed Nov 24, 2023
1 parent e15db44 commit a62a0f3
Show file tree
Hide file tree
Showing 33 changed files with 140 additions and 152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@ public class ExprCustomParticle extends SimpleExpression<Particle> {
"[with offset %-vector%] [with extra %-number%] [force:with force]");
}

@Nullable
private Expression<Number> count;
private Expression<?> particle;
@Nullable
private Expression<Object> data;
@Nullable
private Expression<Vector> offset;
@Nullable
private Expression<Number> extra;
private boolean force;

Expand All @@ -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) {
Expand All @@ -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 {
Expand All @@ -78,20 +84,20 @@ 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();
}
if (data != null) particle.data(data);
}

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());
}

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

@Override
public String toString(@Nullable Event e, boolean debug) {
public String toString(@Nullable Event event, boolean debug) {
return "custom particle";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@ public class ExprRotation extends SimpleExpression<Quaternion> {
"[the|a] rotation (from|between) %vector% (to|and) %vector%");
}

@Nullable
private Expression<Number> angle;
@Nullable
private Expression<Vector> axis;
@Nullable
private Expression<Vector> from;
@Nullable
private Expression<Vector> to;
private boolean isRadians = false;

Expand All @@ -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)};
}
}
Expand All @@ -84,10 +90,10 @@ public Class<? extends Quaternion> 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");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
public class ExprShapeCopy extends SimpleExpression<Shape> {

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<Shape> shapeExpr;
private Expression<Shape> 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<Shape>) expressions[0];
return true;
}
Expand Down Expand Up @@ -65,7 +65,7 @@ public Class<? extends Shape> getReturnType() {
}

@Override
public String toString(@Nullable Event event, boolean b) {
public String toString(@Nullable Event event, boolean debug) {
return "shape copy";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -38,6 +38,7 @@ public class ExprHelix extends SimpleExpression<Helix> {

private Expression<Number> radius;
private Expression<Number> height;
@Nullable
private Expression<Number> windingRate;
private boolean isClockwise = true;
private Style style;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ public class ExprShapeCutoffAngle extends SimplePropertyExpression<CutoffShape,
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) {
public void change(Event event, Object @Nullable [] delta, ChangeMode mode) {
double angle = 0;
if (delta != null && delta.length != 0)
angle = ((Number) delta[0]).doubleValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -108,7 +108,7 @@ protected String getPropertyName() {
case 0 -> "length";
case 1 -> "width";
case 2 -> "height";
default -> null;
default -> "unknown";
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -35,7 +35,7 @@
public class ExprShapeLocations extends SimpleExpression<Location> {

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<Shape> shapeExpr;
Expand All @@ -44,23 +44,26 @@ public class ExprShapeLocations extends SimpleExpression<Location> {
@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) {
shapeExpr = (Expression<Shape>) exprs[0];
locationExpr = (Expression<Location>) exprs[1];
locationExpr = (Expression<Location>) exprs[2];
if (exprs[1] != null)
locationExpr = Direction.combine((Expression<? extends Direction>) 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<Location> 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]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ public class ExprShapeOffset extends SimplePropertyExpression<Shape, Vector> {
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit a62a0f3

Please sign in to comment.