Skip to content

Commit

Permalink
Add Detonate effect (SkriptLang#6898)
Browse files Browse the repository at this point in the history
* Create EffDetonate.java

* Update EffDetonate.java

now fireworks instantly detonate

* adds support for windcharge and tnt minecart

* Update EffDetonate.java

* adds support for creeper

* adds tests

* fixes test version

ty Sovde and ShaneBee

* Update EffDetonate.sk

* oops

* Update EffDetonate.sk

* Update EffDetonate.sk

* Update EffDetonate.sk

* Update EffDetonate.java

* check descrription

adds support for blocks, and adds tnt as a block

* bandaid fix

* bandaid fix again (I am stupid)

* Update EffDetonate.java

* Update EffDetonate.java

* Update EffDetonate.java

* Update EffDetonate.java

* Requested Changes

* Update EffDetonate.java

* unneeded spacing

* grammatical fixes

* Requested Changes

* Create EffDetonate.java

* Update EffDetonate.java

now fireworks instantly detonate

* adds support for windcharge and tnt minecart

* Update EffDetonate.java

* adds support for creeper

* adds tests

* fixes test version

ty Sovde and ShaneBee

* Update EffDetonate.sk

* oops

* Update EffDetonate.sk

* Update EffDetonate.sk

* Update EffDetonate.sk

* Update EffDetonate.java

* check descrription

adds support for blocks, and adds tnt as a block

* bandaid fix

* bandaid fix again (I am stupid)

* Update EffDetonate.java

* Update EffDetonate.java

* Update EffDetonate.java

* Update EffDetonate.java

* Requested Changes

* Update EffDetonate.java

* unneeded spacing

* grammatical fixes

* Requested Changes

* removes star import and useless spacing

---------

Co-authored-by: Moderocky <admin@moderocky.com>
Co-authored-by: sovdee <10354869+sovdeeth@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 13, 2024
1 parent d763411 commit 8ec8c2c
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 8ec8c2c

Please sign in to comment.