1515import 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" } )
2638public 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 ;
0 commit comments