Skip to content

Commit

Permalink
Change setting blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAbsolutionism committed Sep 29, 2024
1 parent 8cccf59 commit c06cacf
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/main/java/ch/njol/skript/effects/EffBlockUpdate.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
})
@Examples({
"update {_blocks::*} as gravel",
"force update {_blocks::*} to be sand without physics updates",
"update {_blocks::*} to be sand without physics updates",
"update {_blocks::*} as stone without neighbouring updates"
})
@Since("INSERT VERSION")
Expand All @@ -33,17 +33,16 @@ public class EffBlockUpdate extends Effect {

static {
Skript.registerEffect(EffBlockUpdate.class,
"[:force] update %blocks% (as|to be) %blockdata% [physics:without [neighbo[u]r[ing]|adjacent] [physic[s]] update[s]]");
"update %blocks% (as|to be) %blockdata% [physics:without [neighbo[u]r[ing]|adjacent] [physic[s]] update[s]]");
}

private boolean force, physics;
private boolean physics;
private Expression<Block> blocks;
private Expression<BlockData> blockData;

@Override
@SuppressWarnings("unchecked")
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
this.force = parseResult.hasTag("force");
this.physics = !parseResult.hasTag("physics");
this.blocks = (Expression<Block>) exprs[0];
this.blockData = (Expression<BlockData>) exprs[1];
Expand All @@ -53,16 +52,15 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
@Override
protected void execute(Event event) {
BlockData data = this.blockData.getSingle(event);
assert data != null;
for (Block block : this.blocks.getArray(event)) {
BlockState state = block.getState();
state.setBlockData(data);
state.update(this.force, this.physics);
block.setBlockData(data, this.physics);
}
}

@Override
public @NotNull String toString(@Nullable Event event, boolean debug) {
return (this.force ? "force " : "") + "update " + this.blocks.toString(event, debug) + " as " +
return "update " + this.blocks.toString(event, debug) + " as " +
this.blockData.toString(event, debug) + (this.physics ? "without neighbour updates" : "");
}

Expand Down

0 comments on commit c06cacf

Please sign in to comment.