Skip to content

Commit

Permalink
Merge branch 'dev/feature' into remove-test-delay
Browse files Browse the repository at this point in the history
  • Loading branch information
Efnilite authored Oct 14, 2024
2 parents 995873e + 8ec8c2c commit c676542
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
63 changes: 63 additions & 0 deletions src/main/java/ch/njol/skript/effects/EffDetonate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package ch.njol.skript.effects;

import org.bukkit.entity.Entity;
import org.bukkit.entity.WindCharge;
import org.bukkit.entity.minecart.ExplosiveMinecart;
import org.bukkit.entity.Firework;
import org.bukkit.entity.Creeper;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;
import ch.njol.skript.Skript;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.lang.Effect;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;

@Name("Detonate Entities")
@Description("Immediately detonates an entity. Accepted entities are fireworks, TNT minecarts, primed TNT, wind charges and creepers.")
@Examples("detonate last launched firework")
@Since("INSERT VERSION")
public class EffDetonate extends Effect {

private static final boolean HAS_WINDCHARGE = Skript.classExists("org.bukkit.entity.WindCharge");

static {
Skript.registerEffect(EffDetonate.class, "detonate %entities%");
}

private Expression<Entity> entities;

@Override
@SuppressWarnings("unchecked")
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
entities = (Expression<Entity>) exprs[0];
return true;
}

@Override
protected void execute(Event event) {
for (Entity entity : entities.getArray(event)) {
if (entity instanceof Firework firework) {
firework.detonate();
} else if (HAS_WINDCHARGE && entity instanceof WindCharge windCharge) {
windCharge.explode();
} else if (entity instanceof ExplosiveMinecart explosiveMinecart) {
explosiveMinecart.explode();
} else if (entity instanceof Creeper creeper) {
creeper.explode();
} else if (entity instanceof TNTPrimed tntPrimed) {
tntPrimed.setFuseTicks(0);
}
}
}

public String toString(@Nullable Event event, boolean debug) {
return "detonate " + entities.toString(event, debug);
}

}
21 changes: 21 additions & 0 deletions src/test/skript/tests/syntaxes/effects/EffDetonate.sk
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
test "detonate entity effect":
spawn a creeper at event-location
assert last spawned entity is valid with "creepers should not detonate when they are first spawned"
detonate last spawned entity
assert last spawned entity isn't valid with "creepers should instantly detonate when spawned"

test "detonate explosive minecart" when running minecraft "1.19":
spawn a minecart with tnt at event-location
assert last spawned entity is valid with "minecarts with tnt should not detonate when they are first spawned"
detonate last spawned entity
assert last spawned entity isn't valid with "minecarts with tnt should instantly detonate when they are first spawned"

test "detonate wind charge" when running minecraft "1.21":
spawn a wind charge at event-location
assert last spawned entity is valid with "wind charges should not detonate when they are first spawned"
detonate last spawned entity
assert last spawned entity isn't valid with "wind charges should instantly detonate when spawned"



# The fireworks test cannot be added as fireworks are despawned a tick later and tests are instant

0 comments on commit c676542

Please sign in to comment.