Skip to content

Commit 4874a6d

Browse files
committed
turns out it already existed and it just didn't have the keywords to come up in my search
1 parent 153bd88 commit 4874a6d

File tree

4 files changed

+35
-185
lines changed

4 files changed

+35
-185
lines changed

src/main/java/ch/njol/skript/expressions/ExprDustedStage.java

Lines changed: 35 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,39 @@
1515
import org.jetbrains.annotations.Nullable;
1616

1717
@Name("Dusted Stage")
18-
@Description({
19-
"Represents how far the block has been uncovered.",
20-
"The only blocks that can currently be \"dusted\" are Suspicious Gravel and Suspicious Sand."
21-
})
22-
@Example("send target block's maximum dusted stage")
23-
@Example("set {_sand}'s dusted stage to 2")
18+
@Description("""
19+
Represents how far the block has been uncovered.
20+
The only blocks that can currently be "dusted" are Suspicious Gravel and Suspicious Sand.
21+
0 means the block is untouched, the max (usually 3) means nearly fulled brushed.
22+
Resetting this value will set it to 0.
23+
""")
24+
@Example("""
25+
# prevent dusting past level 1
26+
on player change block:
27+
if dusting progress of future event-blockdata > 1:
28+
cancel event
29+
""")
30+
@Example("""
31+
# draw particles when dusting is complete!
32+
on player change block:
33+
if dusting progress of event-block is max dusting progress of event-block:
34+
draw 20 totem of undying particles at event-block
35+
""")
2436
@Since("2.12")
25-
@RequiredPlugins("Minecraft 1.20+")
37+
@Keywords({"brush", "brushing", "dusting"})
2638
public class ExprDustedStage extends PropertyExpression<Object, Integer> {
2739

28-
private static final boolean SUPPORTS_DUSTING = Skript.classExists("org.bukkit.block.data.Brushable");
29-
3040
static {
31-
if (SUPPORTS_DUSTING)
32-
register(ExprDustedStage.class, Integer.class,
33-
"[:max[imum]] dust[ed|ing] (value|stage|progress[ion])",
34-
"blocks/blockdatas");
41+
register(ExprDustedStage.class, Integer.class,
42+
"[:max[imum]] dust[ed|ing] (value|stage|progress[ion])",
43+
"blocks/blockdatas");
3544
}
3645

3746
private boolean isMax;
3847

3948
@Override
4049
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
41-
setExpr((Expression<Block>) exprs[0]);
50+
setExpr(exprs[0]);
4251
isMax = parseResult.hasTag("max");
4352
return true;
4453
}
@@ -70,7 +79,7 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
7079
@Override
7180
public void change(Event event, Object @Nullable [] delta, ChangeMode mode) {
7281
if (isMax) return;
73-
Integer value = (delta != null && delta.length > 0) ? (Integer) delta[0] : null;
82+
int value = (delta != null && delta.length > 0) ? (Integer) delta[0] : 0;
7483

7584
for (Object obj : getExpr().getArray(event)) {
7685
Brushable brushable = getBrushable(obj);
@@ -79,35 +88,15 @@ public void change(Event event, Object @Nullable [] delta, ChangeMode mode) {
7988

8089
int currentValue = brushable.getDusted();
8190
int maxValue = brushable.getMaximumDusted();
82-
int newValue = currentValue;
83-
84-
switch (mode) {
85-
case SET -> {
86-
if (value != null) {
87-
newValue = value;
88-
}
89-
}
90-
case ADD -> {
91-
if (value != null) {
92-
newValue = currentValue + value;
93-
}
94-
}
95-
case REMOVE -> {
96-
if (value != null) {
97-
newValue = currentValue - value;
98-
}
99-
}
100-
case RESET -> newValue = 0;
101-
default -> {
102-
return;
103-
}
104-
}
105-
106-
newValue = Math.max(0, Math.min(newValue, maxValue));
107-
108-
brushable.setDusted(newValue);
109-
if (obj instanceof Block) {
110-
((Block) obj).setBlockData(brushable);
91+
int newValue = switch (mode) {
92+
case SET, RESET -> value;
93+
case ADD -> currentValue + value;
94+
case REMOVE -> currentValue - value;
95+
default -> throw new IllegalArgumentException("Change mode " + mode + " is not valid for ExprDustedStage!");
96+
};
97+
brushable.setDusted( Math.clamp(newValue, 0, maxValue));
98+
if (obj instanceof Block block) {
99+
block.setBlockData(brushable);
111100
}
112101
}
113102
}
@@ -116,15 +105,14 @@ public void change(Event event, Object @Nullable [] delta, ChangeMode mode) {
116105
private Brushable getBrushable(Object obj) {
117106
if (obj instanceof Block block) {
118107
BlockData blockData = block.getBlockData();
119-
if (blockData instanceof Brushable)
120-
return (Brushable) blockData;
108+
if (blockData instanceof Brushable brushable)
109+
return brushable;
121110
} else if (obj instanceof Brushable brushable) {
122111
return brushable;
123112
}
124113
return null;
125114
}
126115

127-
128116
@Override
129117
public Class<? extends Integer> getReturnType() {
130118
return Integer.class;

src/main/java/org/skriptlang/skript/bukkit/misc/MiscModule.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import org.skriptlang.skript.addon.AddonModule;
44
import org.skriptlang.skript.addon.SkriptAddon;
5-
import org.skriptlang.skript.bukkit.misc.expressions.ExprDustingProgress;
65
import org.skriptlang.skript.bukkit.misc.expressions.ExprWithYawPitch;
76
import org.skriptlang.skript.registration.SyntaxRegistry;
87

@@ -12,7 +11,6 @@ public class MiscModule implements AddonModule {
1211
public void load(SkriptAddon addon) {
1312
SyntaxRegistry registry = addon.syntaxRegistry();
1413
ExprWithYawPitch.register(registry);
15-
ExprDustingProgress.register(registry);
1614
}
1715

1816
@Override

src/main/java/org/skriptlang/skript/bukkit/misc/expressions/ExprDustingProgress.java

Lines changed: 0 additions & 129 deletions
This file was deleted.

src/test/skript/tests/syntaxes/expressions/ExprDustingProgress.sk renamed to src/test/skript/tests/syntaxes/expressions/ExprDustedStage.sk

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,4 @@ test "dusting progress" when running minecraft "1.20":
4343
set dusting progress of {_blockdata} to 2
4444
assert dusting progress of {_blockdata} is 2 with "Failed to set dusting progress on blockdata"
4545

46-
# test alternative syntax (excavation)
47-
set block at test-block to suspicious sand
48-
set {_sand} to block at test-block
49-
set excavation progress of {_sand} to 1
50-
assert excavation progress of {_sand} is 1 with "Failed to set excavation progress"
51-
assert max excavation progress of {_sand} is 3 with "Max excavation progress should be 3"
52-
5346
set block data of test-block to {_old}

0 commit comments

Comments
 (0)