@@ -128,14 +128,15 @@ public void onSignChange(SignChangeEvent event) {
128128 }
129129
130130 private static boolean isPiston (Block block ) {
131- return block .getType () == Material .PISTON || block .getType () == Material .STICKY_PISTON ;
131+ Material type = block .getType ();
132+ return type == Material .PISTON || type == Material .STICKY_PISTON ;
132133 }
133134
134135 private static ChangedSign getSignOnPiston (Block block ) {
135136 BlockData blockData = block .getBlockData ();
136137 BlockFace facing = BlockFace .SELF ;
137- if (blockData instanceof Directional ) {
138- facing = (( Directional ) blockData ) .getFacing ();
138+ if (blockData instanceof Directional directional ) {
139+ facing = directional .getFacing ();
139140 }
140141
141142 for (BlockFace face : LocationUtil .getDirectFaces ()) {
@@ -166,7 +167,8 @@ private void searchNearbyPipes(Block block, Set<Vector> visitedPipes, List<ItemS
166167 //Use the queue to search blocks.
167168 while (!searchQueue .isEmpty ()) {
168169 Block bl = searchQueue .poll ();
169- if (bl .getType () == Material .PISTON ) {
170+ Material blType = bl .getType ();
171+ if (blType == Material .PISTON ) {
170172 Piston p = (Piston ) bl .getBlockData ();
171173
172174 ChangedSign sign = getSignOnPiston (bl );
@@ -229,7 +231,7 @@ private void searchNearbyPipes(Block block, Set<Vector> visitedPipes, List<ItemS
229231 items .removeAll (filteredItems );
230232 items .addAll (newItems );
231233 }
232- } else if (bl . getType () == Material .DROPPER ) {
234+ } else if (blType == Material .DROPPER ) {
233235 ChangedSign sign = getSignOnPiston (bl );
234236
235237 HashSet <ItemStack > pFilters = new HashSet <>();
@@ -306,33 +308,35 @@ private void searchNearbyPipes(Block block, Set<Vector> visitedPipes, List<ItemS
306308 }
307309
308310 Block off = bl .getRelative (x , y , z );
311+ Material offType = off .getType ();
309312
310- if (!isValidPipeBlock (off )) continue ;
313+ if (!isValidPipeBlock (offType )) continue ;
311314
312315 if (visitedPipes .contains (off .getLocation ().toVector ())) continue ;
313316 visitedPipes .add (off .getLocation ().toVector ());
314317
315- if (ItemUtil .isStainedGlass (bl . getType ()) && ItemUtil .isStainedGlass (off . getType ()) && bl . getType () != off . getType () )
318+ if (ItemUtil .isStainedGlass (blType ) && ItemUtil .isStainedGlass (offType ) && blType != offType )
316319 continue ;
317320
318- if (off . getType () == Material .GLASS || ItemUtil .isStainedGlass (off . getType () )) {
321+ if (offType == Material .GLASS || ItemUtil .isStainedGlass (offType )) {
319322 searchQueue .add (off );
320- } else if (off . getType () == Material .GLASS_PANE || ItemUtil .isStainedGlassPane (off . getType () )) {
323+ } else if (offType == Material .GLASS_PANE || ItemUtil .isStainedGlassPane (offType )) {
321324 Block offsetBlock = off .getRelative (x , y , z );
322- if (! isValidPipeBlock ( offsetBlock )) continue ;
323- if (visitedPipes . contains ( offsetBlock . getLocation (). toVector () ))
325+ Material offsetBlockType = offsetBlock . getType () ;
326+ if (! isValidPipeBlock ( offsetBlockType ))
324327 continue ;
325- if (ItemUtil .isStainedGlassPane (off .getType ())) {
326- if ((ItemUtil .isStainedGlass (bl .getType ())
327- || ItemUtil .isStainedGlassPane (bl .getType ())) && ItemUtil .getStainedColor (off .getType ()) != ItemUtil
328- .getStainedColor (offsetBlock .getType ())
329- || (ItemUtil .isStainedGlass (offsetBlock .getType ())
330- || ItemUtil .isStainedGlassPane (offsetBlock .getType ())) && ItemUtil .getStainedColor (off .getType ()) != ItemUtil
331- .getStainedColor (offsetBlock .getType ())) continue ;
328+ if (visitedPipes .contains (offsetBlock .getLocation ().toVector ())) continue ;
329+ if (ItemUtil .isStainedGlassPane (offType )) {
330+ if ((ItemUtil .isStainedGlass (blType )
331+ || ItemUtil .isStainedGlassPane (blType )) && ItemUtil .getStainedColor (offType ) != ItemUtil
332+ .getStainedColor (offsetBlockType )
333+ || (ItemUtil .isStainedGlass (offsetBlockType )
334+ || ItemUtil .isStainedGlassPane (offsetBlockType )) && ItemUtil .getStainedColor (offType ) != ItemUtil
335+ .getStainedColor (offsetBlockType )) continue ;
332336 }
333337 visitedPipes .add (offsetBlock .getLocation ().toVector ());
334338 searchQueue .add (off .getRelative (x , y , z ));
335- } else if (off . getType () == Material .PISTON )
339+ } else if (offType == Material .PISTON )
336340 searchQueue .addFirst (off ); //Pistons are treated with higher priority.
337341 }
338342 }
@@ -341,19 +345,13 @@ private void searchNearbyPipes(Block block, Set<Vector> visitedPipes, List<ItemS
341345 }
342346 }
343347
344- private static boolean isValidPipeBlock (Block block ) {
345- switch (block .getType ()) {
346- case GLASS :
347- case PISTON :
348- case STICKY_PISTON :
349- case DROPPER :
350- case GLASS_PANE :
351- return true ;
352- default :
353- return ItemUtil .isStainedGlass (block .getType ())
354- || ItemUtil .isStainedGlassPane (block .getType ())
355- || SignUtil .isWallSign (block );
356- }
348+ private static boolean isValidPipeBlock (Material type ) {
349+ return switch (type ) {
350+ case GLASS , PISTON , STICKY_PISTON , DROPPER , GLASS_PANE -> true ;
351+ default -> ItemUtil .isStainedGlass (type )
352+ || ItemUtil .isStainedGlassPane (type )
353+ || SignUtil .isWallSign (type );
354+ };
357355 }
358356
359357 private void startPipe (Block block , List <ItemStack > items , boolean request ) {
@@ -383,17 +381,18 @@ private void startPipe(Block block, List<ItemStack> items, boolean request) {
383381
384382 Piston p = (Piston ) block .getBlockData ();
385383 Block fac = block .getRelative (p .getFacing ());
386-
387- if (fac .getType () == Material .CHEST
388- || fac .getType () == Material .TRAPPED_CHEST
389- || fac .getType () == Material .DROPPER
390- || fac .getType () == Material .DISPENSER
391- || fac .getType () == Material .HOPPER
392- || fac .getType () == Material .BARREL
393- || fac .getType () == Material .CHISELED_BOOKSHELF
394- || fac .getType () == Material .CRAFTER
395- || fac .getType () == Material .DECORATED_POT
396- || Tag .SHULKER_BOXES .isTagged (fac .getType ())) {
384+ Material facType = fac .getType ();
385+
386+ if (facType == Material .CHEST
387+ || facType == Material .TRAPPED_CHEST
388+ || facType == Material .DROPPER
389+ || facType == Material .DISPENSER
390+ || facType == Material .HOPPER
391+ || facType == Material .BARREL
392+ || facType == Material .CHISELED_BOOKSHELF
393+ || facType == Material .CRAFTER
394+ || facType == Material .DECORATED_POT
395+ || Tag .SHULKER_BOXES .isTagged (facType )) {
397396 for (ItemStack stack : ((InventoryHolder ) fac .getState ()).getInventory ().getContents ()) {
398397
399398 if (!ItemUtil .isStackValid (stack ))
@@ -418,7 +417,7 @@ private void startPipe(Block block, List<ItemStack> items, boolean request) {
418417 }
419418
420419 if (!items .isEmpty ()) {
421- if (fac . getType () == Material .CRAFTER ) {
420+ if (facType == Material .CRAFTER ) {
422421 leftovers .addAll (InventoryUtil .addItemsToCrafter ((Crafter ) fac .getState (), items .toArray (new ItemStack [items .size ()])));
423422 } else {
424423 for (ItemStack item : items ) {
@@ -429,7 +428,7 @@ private void startPipe(Block block, List<ItemStack> items, boolean request) {
429428 }
430429 }
431430 }
432- } else if (fac . getType () == Material .FURNACE || fac . getType () == Material .BLAST_FURNACE || fac . getType () == Material .SMOKER ) {
431+ } else if (facType == Material .FURNACE || facType == Material .BLAST_FURNACE || facType == Material .SMOKER ) {
433432
434433 Furnace f = (Furnace ) fac .getState ();
435434
@@ -459,7 +458,7 @@ private void startPipe(Block block, List<ItemStack> items, boolean request) {
459458 leftovers .add (ItemUtil .addToStack (f .getInventory ().getResult (), item ));
460459 }
461460 } else f .getInventory ().setResult (null );
462- } else if (fac . getType () == Material .JUKEBOX ) {
461+ } else if (facType == Material .JUKEBOX ) {
463462
464463 Jukebox juke = (Jukebox ) fac .getState ();
465464
0 commit comments