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

EffBlockUpdate #7065

Open
wants to merge 18 commits into
base: dev/feature
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions src/main/java/ch/njol/skript/effects/EffBlockUpdate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package ch.njol.skript.effects;

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;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.data.BlockData;
import org.bukkit.event.Event;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

@Name("Update Block")
@Description({
"Updates the blocks to a selected block",
"`force`: Will force the update of the block",
"`without physics`: Does not send updates to surrounding blocks"
})
@Examples({
"update {_blocks::*} as gravel",
"update {_blocks::*} to be sand without physics updates",
"update {_blocks::*} as stone without neighbouring updates"
})
@Since("INSERT VERSION")
// Originally sourced from SkBee by ShaneBee (https://github.com/ShaneBeee/SkBee/blob/master/src/main/java/com/shanebeestudios/skbee/elements/other/effects/EffBlockstateUpdate.java)
public class EffBlockUpdate extends Effect {

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

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.physics = !parseResult.hasTag("physics");
this.blocks = (Expression<Block>) exprs[0];
this.blockData = (Expression<BlockData>) exprs[1];
return true;
}

@Override
protected void execute(Event event) {
BlockData data = this.blockData.getSingle(event);
assert data != null;
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
for (Block block : this.blocks.getArray(event)) {
block.setBlockData(data, this.physics);
}
}

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

}
8 changes: 8 additions & 0 deletions src/test/skript/tests/syntaxes/effects/EffBlockUpdate.sk
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
test "block update":
set {_loc} to spawn of world "world" ~ vector(10,10,10)
set {_blocks::*} to blocks in radius 2 of block at {_loc}

update blocks at {_blocks::*} as sand without physics updates
assert blocks at {_blocks::*} is sand with "1 or more block did not update with or without physics"
update blocks at {_blocks::*} as air without physics updates
assert blocks at {_blocks::*} is air with "1 or more block did not update to air"
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved