Plugin for finding placed blocks and if they are in a certain sequence This is for a plugin I am making for the game called Minecraft. The code is responsible for finding out the blocks placed by the player and if they are in the following sequence as shown in the picture then create an Antenna. block in block.getType() returns the block placed by the player. Also, it doesn't matter in what order the player places the blocks.



// if block placed was a jukebox and block directly above is a diamond block
// and the block above the diamond block is an iron fence
if(block.getType() == Material.JUKEBOX 
        &amp;&amp; block.getRelative(BlockFace.UP, 1).getType() == Material.DIAMOND_BLOCK
        &amp;&amp; block.getRelative(BlockFace.UP, 2).getType() == Material.IRON_FENCE){
    System.out.println("Antenna Created");
    player.sendMessage("Antenna Created");
}

// if block placed was a diamond block and block directly above is a iron fence
// and the block below is a jukebox
if(block.getType() == Material.DIAMOND_BLOCK 
        &amp;&amp; block.getRelative(BlockFace.UP, 1).getType() == Material.IRON_FENCE
        &amp;&amp; block.getRelative(BlockFace.DOWN, 1).getType() == Material.JUKEBOX){
    System.out.println("Antenna Created");
    player.sendMessage("Antenna Created");
}

// if block placed was an iron fence and the block directly below is a diamond block
// and the block below that is a jukebox
if(block.getType() == Material.IRON_FENCE 
        &amp;&amp; block.getRelative(BlockFace.DOWN, 1).getType() == Material.DIAMOND_BLOCK
        &amp;&amp; block.getRelative(BlockFace.DOWN, 2).getType() == Material.JUKEBOX){
    System.out.println("Antenna Created");
    player.sendMessage("Antenna Created");
}


I am not happy with the following code and I get the feeling there is a better way to do this? I'm also wondering how would I go about designing these if Statements to allow for future extendibility?
As it is mentioned in the comments, It seems your code is exactly same as the below. So that is the first suggestion. 

main = block.getType();
up1 = block.getRelative(BlockFace.UP, 1).getType();
up2 = block.getRelative(BlockFace.UP, 2).getType();
down1 = block.getRelative(BlockFace.DOWN, 1).getType();
down2 = block.getRelative(BlockFace.DOWN, 2).getType();


if ((main == Material.JUKEBOX &amp;&amp; up1 == Material.DIAMOND_BLOCK &amp;&amp; up2 == Material.IRON_FENCE)||
   (main == Material.DIAMOND_BLOCK &amp;&amp; up1 == Material.IRON_FENCE &amp;&amp; down1 == Material.JUKEBOX) ||
   (main == Material.IRON_FENCE &amp;&amp; down1 == Material.DIAMOND_BLOCK &amp;&amp; down2 == Material.JUKEBOX)) {
    System.out.println("Antenna Created");
    player.sendMessage("Antenna Created");
}


Now, as far as extendibility goes, You need to add newer conditions, it is not a good idea. What you have coded here is just an FSM (A state machine).

The easiest method to capture a state machine is to turn that into a regular expression. In this case, Say, the ordering is

up1 up2 main down1 down2


The conditions are

DIJ.. | I.DJ. | ..IDJ


So this captures your state machine fully. Adding future conditions is just as simple as adding to the above regular expression.

The code would look like

first(var) {
  return first_char(var)
}
string = { first(up1.toS()), first(up2.toS()),
           first(main.toS()),
           first(down1.toS()), first(down2.toS())};
re = new Regexp('DIJ..|I.DJ.|..IDJ')
if (re.match(string)) {
  player.send('Antena Created');
}