1111import ch .njol .skript .lang .parser .ParserInstance ;
1212import ch .njol .skript .registrations .EventValues ;
1313import ch .njol .skript .util .Direction ;
14- import ch .njol .skript .util .Getter ;
1514import ch .njol .skript .util .Timespan ;
1615import ch .njol .skript .util .Timespan .TimePeriod ;
1716import ch .njol .skript .variables .Variables ;
@@ -40,12 +39,7 @@ public abstract class DrawShapeEffectSection extends EffectSection {
4039 public static final Timespan ONE_TICK = new Timespan (TimePeriod .TICK , 1 );
4140
4241 static {
43- EventValues .registerEventValue (DrawEvent .class , Shape .class , new Getter <Shape , DrawEvent >() {
44- @ Override
45- public Shape get (DrawEvent drawEvent ) {
46- return drawEvent .getShape ();
47- }
48- }, EventValues .TIME_NOW );
42+ EventValues .registerEventValue (DrawEvent .class , Shape .class , DrawEvent ::getShape , EventValues .TIME_NOW );
4943 }
5044
5145 protected Expression <Shape > shapes ;
@@ -82,7 +76,7 @@ public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean is
8276 AtomicBoolean delayed = new AtomicBoolean (false );
8377 Runnable afterLoading = () -> delayed .set (!getParser ().getHasDelayBefore ().isFalse ());
8478 assert sectionNode != null ;
85- trigger = loadCode (sectionNode , "draw" , afterLoading , DrawEvent .class );
79+ trigger = loadCode (sectionNode , "draw" , null , afterLoading , DrawEvent .class );
8680 if (delayed .get ()) {
8781 Skript .error ("Delays can't be used within a Draw Shape Effect Section" );
8882 return false ;
@@ -144,10 +138,7 @@ protected TriggerItem walk(Event event) {
144138 if (trigger != null ) {
145139 consumer = shape -> {
146140 DrawEvent drawEvent = new DrawEvent (shape );
147- Variables .setLocalVariables (drawEvent , localVars );
148- TriggerItem .walk (trigger , drawEvent );
149- Variables .setLocalVariables (event , Variables .copyLocalVariables (drawEvent ));
150- Variables .removeLocals (drawEvent );
141+ Variables .withLocalVariables (event , drawEvent , () -> TriggerItem .walk (trigger , drawEvent ));
151142 };
152143 } else {
153144 consumer = null ;
@@ -216,11 +207,9 @@ protected void executeSync(Event event, Collection<DynamicLocation> locations, @
216207 for (DynamicLocation dynamicLocation : locations ) {
217208 for (Shape shape : shapes .getArray (event )) {
218209 if (consumer != null ) {
219- // copy the shape so that it can be modified by the consumer without affecting the original
220- shapeCopy = shape .clone ();
221- shapeCopy .draw (dynamicLocation , consumer , recipients );
210+ shape .clone ().draw (dynamicLocation , consumer , recipients );
222211 } else {
223- shape .draw (dynamicLocation , recipients );
212+ shape .clone (). draw (dynamicLocation , recipients );
224213 }
225214 }
226215 }
@@ -237,7 +226,7 @@ protected void executeAsync(Collection<DynamicLocation> locations, Collection<Sh
237226 try {
238227 for (DynamicLocation dynamicLocation : locations ) {
239228 for (Shape shape : shapes ) {
240- shape .draw (dynamicLocation , recipients );
229+ shape .clone (). draw (dynamicLocation , recipients );
241230 }
242231 }
243232 } catch (IllegalArgumentException exception ) {
0 commit comments