-
-
Notifications
You must be signed in to change notification settings - Fork 370
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev/feature' into remove-test-delay
- Loading branch information
Showing
2 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |