Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExprExplodedBlocks - fix not being able to remove #6655

Merged
merged 10 commits into from
Jun 1, 2024
36 changes: 31 additions & 5 deletions src/main/java/ch/njol/skript/expressions/ExprExplodedBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import java.util.List;

import ch.njol.skript.classes.Changer.ChangeMode;
import ch.njol.util.coll.CollectionUtils;
import org.bukkit.block.Block;
import org.bukkit.event.Event;
import org.bukkit.event.entity.EntityExplodeEvent;
Expand All @@ -38,12 +40,17 @@
import ch.njol.util.Kleenean;

@Name("Exploded Blocks")
@Description("Get all the blocks that were destroyed in an explode event")
@Examples({"on explode:",
"\tloop exploded blocks:",
"\t\tadd loop-block to {exploded::blocks::*}"})
@Description("Get all the blocks that were destroyed in an explode event. Supports removing blocks.")
@Examples({
"on explode:",
"\tloop exploded blocks:",
"\t\tadd loop-block to {exploded::blocks::*}",
"on explode:",
"\tloop exploded blocks:",
"\t\tif loop-block is grass:",
"\t\t\tremove loop-block from exploded blocks"})
@Events("explode")
@Since("2.5")
@Since("2.5, INSERT VERSION (removing blocks)")
public class ExprExplodedBlocks extends SimpleExpression<Block> {

static {
Expand All @@ -68,6 +75,25 @@ protected Block[] get(Event e) {
List<Block> blockList = ((EntityExplodeEvent) e).blockList();
return blockList.toArray(new Block[blockList.size()]);
}

@Override
public @Nullable Class<?>[] acceptChange(ChangeMode mode) {
if (mode == ChangeMode.REMOVE)
ShaneBeee marked this conversation as resolved.
Show resolved Hide resolved
return CollectionUtils.array(Block[].class);
return null;
}

@Override
public void change(Event event, @Nullable Object[] delta, ChangeMode mode) {
if (!(event instanceof EntityExplodeEvent))
return;

List<Block> blocks = ((EntityExplodeEvent) event).blockList();
for (Object object : delta) {
if (object instanceof Block)
blocks.remove((Block) object);
}
}

@Override
public boolean isSingle() {
Expand Down