Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
2cc8bfb
initial commit
Asleeepp Jul 15, 2024
fbdc23f
Merge branch 'dev/feature' into addition-brush-stuff
Asleeepp Jul 15, 2024
977c1c2
syntax change
Asleeepp Jul 15, 2024
4649cf6
remove comment
Asleeepp Jul 15, 2024
42773ae
slight change in test
Asleeepp Jul 15, 2024
a378b9b
forgot these
Asleeepp Jul 15, 2024
bd0f309
changes
Asleeepp Jul 19, 2024
48eb734
Merge branch 'dev/feature' into addition-brush-stuff
Asleeepp Jul 19, 2024
b59c9d2
Merge branch 'dev/feature' into addition-brush-stuff
Asleeepp Jul 19, 2024
23f407c
test
Asleeepp Jul 19, 2024
2b6bd5e
Merge remote-tracking branch 'origin/addition-brush-stuff' into addit…
Asleeepp Jul 19, 2024
5fc7fb4
test
Asleeepp Jul 19, 2024
4299c3e
changes
Asleeepp Jul 19, 2024
9b7a14a
nevermind
Asleeepp Jul 19, 2024
e311c0a
Apply suggestions from code review
Asleeepp Dec 2, 2024
ecf0888
initial commit
Asleeepp Jul 15, 2024
5836857
syntax change
Asleeepp Jul 15, 2024
44f775e
remove comment
Asleeepp Jul 15, 2024
f0f4fac
slight change in test
Asleeepp Jul 15, 2024
e469a9b
forgot these
Asleeepp Jul 15, 2024
ae29f92
changes
Asleeepp Jul 19, 2024
bd4f695
test
Asleeepp Jul 19, 2024
f8eb5b2
test
Asleeepp Jul 19, 2024
05d06bd
changes
Asleeepp Jul 19, 2024
2eb5002
nevermind
Asleeepp Jul 19, 2024
75ecd80
Apply suggestions from code review
Asleeepp Dec 2, 2024
e27b88d
UPDATEEEEEEE
Asleeepp Dec 2, 2024
5797f5c
Merge remote-tracking branch 'origin/addition-brush-stuff' into addit…
Asleeepp Dec 2, 2024
1dd5af1
Merge branch 'dev/feature' into addition-brush-stuff
Moderocky Dec 7, 2024
6dd9152
Suggested changes.
Asleeepp Dec 28, 2024
ab0173b
Merge branch 'dev/feature' into addition-brush-stuff
Asleeepp Dec 28, 2024
adc7842
Merge branch 'dev/feature' into addition-brush-stuff
Efnilite Dec 29, 2024
0bc3528
Apply suggestions from code review
Asleeepp Dec 29, 2024
d1f5187
Suggested Changes
Asleeepp Dec 29, 2024
4eb5719
Apply suggestions from code review
Asleeepp Dec 29, 2024
fe55f97
Suggested Changes
Asleeepp Dec 29, 2024
c87a631
Merge remote-tracking branch 'origin/addition-brush-stuff' into addit…
Asleeepp Dec 29, 2024
efebaed
Update src/test/skript/tests/syntaxes/expressions/ExprDusted.sk
Asleeepp Jan 3, 2025
99ec3a1
Merge remote-tracking branch 'upstream/dev/feature' into addition-bru…
Asleeepp Mar 16, 2025
b76f323
Merge branch 'dev/feature' into addition-brush-stuff
Asleeepp Mar 16, 2025
a1c6260
Suggested
Asleeepp Mar 16, 2025
a272d30
fix: logic error
Asleeepp Mar 16, 2025
befbca9
feat: add blockdata support and multiple changers
Asleeepp Mar 16, 2025
f86eed8
Merge branch 'dev/feature' into addition-brush-stuff
sovdeeth Jun 3, 2025
b8ba1ea
Merge branch 'dev/feature' into addition-brush-stuff
sovdeeth Jun 3, 2025
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
78 changes: 78 additions & 0 deletions src/main/java/ch/njol/skript/expressions/ExprBrushableItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package ch.njol.skript.expressions;

import ch.njol.skript.Skript;
import ch.njol.skript.classes.Changer;
import ch.njol.skript.classes.Changer.ChangeMode;
import ch.njol.skript.doc.*;
import ch.njol.skript.expressions.base.SimplePropertyExpression;
import ch.njol.util.coll.CollectionUtils;
import org.bukkit.block.Block;
import org.bukkit.block.BrushableBlock;
import org.bukkit.block.BlockState;
import org.bukkit.event.Event;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;

@Name("Buried Item")
@Description({
"Represents the item that is uncovered when dusting.",
"The only blocks that can currently be \"dusted\" are Suspicious Gravel and Suspicious Sand."
})
@Examples({
"send target block's brushable item",
"set {_gravel}'s brushable item to emerald"
})
@Since("INSERT VERSION")
@RequiredPlugins("Minecraft 1.20+")
public class ExprBrushableItem extends SimplePropertyExpression<Block, ItemStack> {

private static final boolean SUPPORTS_DUSTING = Skript.classExists("org.bukkit.block.BrushableBlock");

static {
if (SUPPORTS_DUSTING)
register(ExprBrushableItem.class, ItemStack.class,
"(brushable|buried) item",
"blocks");
}

@Override
public @Nullable ItemStack convert(Block block) {
if (block.getState() instanceof BrushableBlock brushableBlock) {
return brushableBlock.getItem();
}
return null;
}

@Override
public Class<?> @Nullable [] acceptChange(ChangeMode mode) {
if (mode == ChangeMode.SET || mode == ChangeMode.DELETE) {
return CollectionUtils.array(ItemStack.class);
}
return null;
}

@Override
public void change(Event event, Object @Nullable [] delta, ChangeMode mode) {
if (mode == ChangeMode.SET || mode == ChangeMode.DELETE) {
ItemStack newItem = (mode == ChangeMode.SET) ? (ItemStack) delta[0] : null;
for (Block block : getExpr().getArray(event)) {
BlockState state = block.getState();
if (state instanceof BrushableBlock brushableBlock) {
brushableBlock.setItem(newItem);
state.update();
}
}
}
}

@Override
public Class<? extends ItemStack> getReturnType() {
return ItemStack.class;
}

@Override
protected String getPropertyName() {
return "brushable item";
}

}
140 changes: 140 additions & 0 deletions src/main/java/ch/njol/skript/expressions/ExprDustedStage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
package ch.njol.skript.expressions;

import ch.njol.skript.Skript;
import ch.njol.skript.classes.Changer.ChangeMode;
import ch.njol.skript.doc.*;
import ch.njol.skript.expressions.base.PropertyExpression;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;
import ch.njol.util.coll.CollectionUtils;
import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Brushable;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;

@Name("Dusted Stage")
@Description({
"Represents how far the block has been uncovered.",
"The only blocks that can currently be \"dusted\" are Suspicious Gravel and Suspicious Sand."
})
@Examples({
"send target block's maximum dusted stage",
"set {_sand}'s dusted stage to 2"
})
@Since("INSERT VERSION")
@RequiredPlugins("Minecraft 1.20+")
public class ExprDustedStage extends PropertyExpression<Object, Integer> {

private static final boolean SUPPORTS_DUSTING = Skript.classExists("org.bukkit.block.data.Brushable");

static {
if (SUPPORTS_DUSTING)
register(ExprDustedStage.class, Integer.class,
"[:max[imum]] dust[ed|ing] (value|stage|progress[ion])",
"blocks/blockdatas");
}

private boolean isMax;

@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
setExpr((Expression<Block>) exprs[0]);
isMax = parseResult.hasTag("max");
return true;
}

@Override
protected Integer @Nullable [] get(Event event, Object[] source) {
return get(source, obj -> {
Brushable brushable = getBrushable(obj);
if (brushable != null) {
return isMax ? brushable.getMaximumDusted() : brushable.getDusted();
}
return null;
});
}

@Override
public Class<?> @Nullable [] acceptChange(ChangeMode mode) {
if (isMax) {
Skript.error("Attempting to modify the max dusted stage is not supported.");
return null;
}

return switch (mode) {
case SET, ADD, REMOVE, RESET -> CollectionUtils.array(Integer.class);
default -> null;
};
}

@Override
public void change(Event event, Object @Nullable [] delta, ChangeMode mode) {
if (isMax) return;
Integer value = (delta != null && delta.length > 0) ? (Integer) delta[0] : null;

for (Object obj : getExpr().getArray(event)) {
Brushable brushable = getBrushable(obj);
if (brushable == null)
continue;

int currentValue = brushable.getDusted();
int maxValue = brushable.getMaximumDusted();
int newValue = currentValue;

switch (mode) {
case SET -> {
if (value != null) {
newValue = value;
}
}
case ADD -> {
if (value != null) {
newValue = currentValue + value;
}
}
case REMOVE -> {
if (value != null) {
newValue = currentValue - value;
}
}
case RESET -> newValue = 0;
default -> {
return;
}
}

newValue = Math.max(0, Math.min(newValue, maxValue));

brushable.setDusted(newValue);
if (obj instanceof Block) {
((Block) obj).setBlockData(brushable);
}
}
}

@Nullable
private Brushable getBrushable(Object obj) {
if (obj instanceof Block block) {
BlockData blockData = block.getBlockData();
if (blockData instanceof Brushable)
return (Brushable) blockData;
} else if (obj instanceof Brushable brushable) {
return brushable;
}
return null;
}


@Override
public Class<? extends Integer> getReturnType() {
return Integer.class;
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return getExpr().toString(event, debug) + "'s " + (isMax ? "maximum " : "") + " dusted stage";
}

}
57 changes: 57 additions & 0 deletions src/test/skript/tests/syntaxes/expressions/ExprDusted.sk
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
test "Dusted Stage" when running minecraft "1.20":
set block 1 block under event-location to stone
set block at event-location to suspicious gravel
set {_block} to block at event-location
set {_blockdata} to block data of {_block}

set dusted stage of {_block} to 2
assert dusted stage of {_block} is 2 with "Failed to set dusted stage to 2"

assert maximum dusted stage of {_block} is 3 with "Maximum dusted stage should be 3"

add 1 to dusted stage of {_block}
assert dusted stage of {_block} is 3 with "Failed to add 1 to dusted stage"

add 5 to dusted stage of {_block}
assert dusted stage of {_block} is 3 with "Dusted stage should be capped at maximum value"

remove 2 from dusted stage of {_block}
assert dusted stage of {_block} is 1 with "Failed to remove 2 from dusted stage"

remove 5 from dusted stage of {_block}
assert dusted stage of {_block} is 0 with "Dusted stage should be capped at minimum value"

set dusted stage of {_block} to 2
reset dusted stage of {_block}
assert dusted stage of {_block} is 0 with "Failed to reset dusted stage"

set dusted stage of {_blockdata} to 2
assert dusted stage of {_blockdata} is 2 with "Failed to set dusted stage on blockdata"

set block at event-location to suspicious sand
set {_sand} to block at event-location

set dusted stage of {_sand} to 1
assert dusted stage of {_sand} is 1 with "Failed to set dusted stage on suspicious sand"
add 1 to dusted stage of {_sand}
assert dusted stage of {_sand} is 2 with "Failed to add to dusted stage on suspicious sand"

set block at event-location to air
set block 1 block under event-location to air

test "Brushable Item" when running minecraft "1.20":
set block 1 block under event-location to stone
set block at event-location to suspicious gravel
set {_block} to block at event-location

set {_block}'s brushable item to gold nugget
assert {_block}'s brushable item is gold nugget with "Failed to set brushable item to gold nugget"

set {_block}'s brushable item to diamond
assert {_block}'s brushable item is diamond with "Failed to set brushable item to diamond"

set {_block}'s brushable item to air
assert {_block}'s brushable item is air with "Failed to clear brushable item"
set block at {_block} to air
set block 1 block under {_block} to air