99import com .sk89q .worldedit .extension .platform .Actor ;
1010import com .sk89q .worldedit .internal .annotation .Selection ;
1111import com .sk89q .worldedit .internal .command .CommandArgParser ;
12+ import com .sk89q .worldedit .internal .util .LogManagerCompat ;
1213import com .sk89q .worldedit .internal .util .Substring ;
1314import com .sk89q .worldedit .math .BlockVector3 ;
1415import com .sk89q .worldedit .regions .Region ;
1516import com .sk89q .worldedit .util .formatting .text .TextComponent ;
17+ import org .apache .logging .log4j .Logger ;
1618import org .enginehub .piston .exception .StopExecutionException ;
1719import org .enginehub .piston .inject .InjectAnnotation ;
1820import org .enginehub .piston .inject .InjectedValueAccess ;
4547 Processor value () default Processor .ALWAYS ;
4648
4749 enum Processor {
50+ NULLABLE_REGION {
51+ @ Override
52+ public boolean passes (Actor actor , InjectedValueAccess context , double value ) {
53+ if (checkExisting (context )) {
54+ return true ;
55+ }
56+ Region region = context
57+ .injectedValue (Key .of (Region .class , Selection .class ))
58+ .orElse (null );
59+ if (region == null ) {
60+ return true ;
61+ }
62+ return handleRegion (region , actor , context , value );
63+ }
64+ },
4865 REGION {
4966 @ Override
5067 public boolean passes (Actor actor , InjectedValueAccess context , double value ) {
@@ -54,18 +71,7 @@ public boolean passes(Actor actor, InjectedValueAccess context, double value) {
5471 Region region = context
5572 .injectedValue (Key .of (Region .class , Selection .class ))
5673 .orElseThrow (IncompleteRegionException ::new );
57- BlockVector3 pos1 = region .getMinimumPoint ();
58- BlockVector3 pos2 = region .getMaximumPoint ();
59- long area = (pos2 .x () - pos1 .x ()) * (pos2 .z () - pos1 .z () + 1 )
60- * (long ) value ;
61- long max = 2 << 18 ;
62- if (max != -1 && area > max ) {
63- actor .print (Caption .of ("fawe.cancel.reason.confirm.region" ,
64- pos1 , pos2 , getArgs (context ), region .getHeight () * area
65- ));
66- return confirm (actor , context );
67- }
68- return true ;
74+ return handleRegion (region , actor , context , value );
6975 }
7076 },
7177 RADIUS {
@@ -111,6 +117,8 @@ public boolean passes(Actor actor, InjectedValueAccess context, double value) {
111117 }
112118 };
113119
120+ private static final Logger LOGGER = LogManagerCompat .getLogger ();
121+
114122 public boolean passes (Actor actor , InjectedValueAccess context , double value ) {
115123 return true ;
116124 }
@@ -171,7 +179,7 @@ private static boolean confirm(Actor actor, InjectedValueAccess context) {
171179 Map <Key <?>, Optional <?>> memory = (Map <Key <?>, Optional <?>>) Reflect .memory .get (memoizingValueAccess );
172180 memory .put (Key .of (InterruptableCondition .class ), Optional .of (wait ));
173181 } catch (IllegalAccessException e ) {
174- e . printStackTrace ( );
182+ LOGGER . error ( "Error confirming command" , e );
175183 }
176184 // Waits till 15 seconds then returns false unless awakened
177185 if (condition .await (15 , TimeUnit .SECONDS )) {
@@ -192,10 +200,27 @@ boolean checkExisting(InjectedValueAccess context) {
192200 // in which case this is the least of our worries...
193201 return lock .isPresent ();
194202 }
203+
204+ private static boolean handleRegion (Region region , Actor actor , InjectedValueAccess context , double value ) {
205+ BlockVector3 pos1 = region .getMinimumPoint ();
206+ BlockVector3 pos2 = region .getMaximumPoint ();
207+ long area = (pos2 .x () - pos1 .x ()) * (pos2 .z () - pos1 .z () + 1 )
208+ * (long ) value ;
209+ long max = 2 << 18 ;
210+ if (max != -1 && area > max ) {
211+ actor .print (Caption .of ("fawe.cancel.reason.confirm.region" ,
212+ pos1 , pos2 , getArgs (context ), region .getHeight () * area
213+ ));
214+ return confirm (actor , context );
215+ }
216+ return true ;
217+ }
195218 }
196219
197220 class Reflect {
198221
222+ private static final Logger LOGGER = LogManagerCompat .getLogger ();
223+
199224 static final Field memory ;
200225 static final Field injectedValues ;
201226
@@ -205,7 +230,7 @@ class Reflect {
205230 memoryField = MemoizingValueAccess .class .getDeclaredField ("memory" );
206231 memoryField .setAccessible (true );
207232 } catch (NoSuchFieldException e ) {
208- e . printStackTrace ( );
233+ LOGGER . error ( "Could not find memory field" , e );
209234 memoryField = null ;
210235 }
211236 memory = memoryField ;
@@ -216,7 +241,7 @@ class Reflect {
216241 injectedValuesField = c .getDeclaredField ("injectedValues" );
217242 injectedValuesField .setAccessible (true );
218243 } catch (NoSuchFieldException | ClassNotFoundException e ) {
219- e . printStackTrace ( );
244+ LOGGER . error ( "Could not find injectedValues field" , e );
220245 injectedValuesField = null ;
221246 }
222247 injectedValues = injectedValuesField ;
0 commit comments