Skip to content

Commit

Permalink
Feature/pathfinding to be double (SkriptLang#4915)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLimeGlass authored Jul 18, 2022
1 parent baccca9 commit 7186ed1
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/main/java/ch/njol/skript/effects/EffPathfind.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.RequiredPlugins;
import ch.njol.skript.doc.Since;
import ch.njol.skript.lang.Effect;
import ch.njol.skript.lang.Expression;
Expand All @@ -40,9 +41,10 @@
@Examples({
"make all creepers pathfind towards player",
"make all cows stop pathfinding",
"make event-entity pathfind towards player"
"make event-entity pathfind towards player at speed 1"
})
@Since("INSERT VERSION")
@RequiredPlugins("Paper")
public class EffPathfind extends Effect {

static {
Expand Down Expand Up @@ -72,7 +74,7 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
@Override
protected void execute(Event event) {
Object target = this.target != null ? this.target.getSingle(event) : null;
int speed = this.speed != null ? this.speed.getSingle(event).intValue() : 1;
double speed = this.speed != null ? this.speed.getOptionalSingle(event).orElse(1).doubleValue() : 1;
for (LivingEntity entity : entities.getArray(event)) {
if (!(entity instanceof Mob))
continue;
Expand All @@ -87,13 +89,12 @@ protected void execute(Event event) {
}

@Override
public String toString(@Nullable Event e, boolean debug) {
public String toString(@Nullable Event event, boolean debug) {
if (target == null)
return "make " + entities.toString(e, debug) + " stop pathfinding";

String repr = "make " + entities.toString(e, debug) + " pathfind towards " + target.toString(e, debug);
return "make " + entities.toString(event, debug) + " stop pathfinding";
String repr = "make " + entities.toString(event, debug) + " pathfind towards " + target.toString(event, debug);
if (speed != null)
repr += " at speed " + speed.toString(e, debug);
repr += " at speed " + speed.toString(event, debug);
return repr;
}

Expand Down

0 comments on commit 7186ed1

Please sign in to comment.