Solved Check if a block is on the right or left of a sign

Discussion in 'Plugin Development' started by Minesuchtiiii, Oct 4, 2017.

Thread Status:
Not open for further replies.
  1. Offline

    Minesuchtiiii

    I want to check if a block is on the right or left of a sign, I already have a code but in the code I have to check 4 times..(for each direction) im using loc.clone().add(x, y, z);
    Is there a way to check only one time? (or less than 4) some method like

    Code:
    public boolean SignOnRight(Location loc) {
    
    if(.... ?) {
    
    return true;
    
    }
    
    return false;
    
    }
     
    Last edited: Oct 4, 2017
  2. Offline

    Caderape2

  3. Offline

    Minesuchtiiii

    I would have to add north, south, west and east, don't I?

    //EDIT:
    fixed it, wasn't easy but if any one needs to check if the left block of a location(sign) is a sign:

    Code:
        public boolean nearLeftBlockIsSign(Location loc) {
           
            Block b = loc.getBlock();
           
            if(b.getType().equals(Material.WALL_SIGN) || b.getType().equals(Material.SIGN_POST)) {
               
                org.bukkit.material.Sign sign = (org.bukkit.material.Sign) loc.getBlock().getState().getData();
                BlockFace anti = sign.getFacing().getOppositeFace();
               
                if(anti.equals(BlockFace.NORTH)) {
                   
                    Location northleft = loc.clone().subtract(1, 0, 0);
                   
                    if(Bukkit.getWorld(loc.getWorld().getName()).getBlockAt(northleft).getType().equals(Material.WALL_SIGN)
                            || Bukkit.getWorld(loc.getWorld().getName()).getBlockAt(northleft).getType().equals(Material.SIGN_POST)) {
                       
                        return true;
                    }
                   
                   
                }
                if(anti.equals(BlockFace.EAST)) {
                   
                    Location eastleft = loc.clone().subtract(0, 0, 1);
                   
                    if(Bukkit.getWorld(loc.getWorld().getName()).getBlockAt(eastleft).getType().equals(Material.WALL_SIGN)
                            || Bukkit.getWorld(loc.getWorld().getName()).getBlockAt(eastleft).getType().equals(Material.SIGN_POST)) {
                       
                        return true;
                    }
                   
                   
                }
                if(anti.equals(BlockFace.SOUTH)) {
                   
                    Location southleft = loc.clone().add(1, 0, 0);
                   
                    if(Bukkit.getWorld(loc.getWorld().getName()).getBlockAt(southleft).getType().equals(Material.WALL_SIGN)
                            || Bukkit.getWorld(loc.getWorld().getName()).getBlockAt(southleft).getType().equals(Material.SIGN_POST)) {
                       
                        return true;
                    }
                   
                   
                }
                if(anti.equals(BlockFace.WEST)) {
                   
                    Location westleft = loc.clone().add(0, 0, 1);
                   
                    if(Bukkit.getWorld(loc.getWorld().getName()).getBlockAt(westleft).getType().equals(Material.WALL_SIGN)
                            || Bukkit.getWorld(loc.getWorld().getName()).getBlockAt(westleft).getType().equals(Material.SIGN_POST)) {
                       
                        return true;
                    }
                   
                   
                }
               
               
            }
           
            return false;
           
        }
     
  4. Offline

    MightyOne

    Yoe can replace all the if statments (in my eyes annoying) with one switch statement
     
Thread Status:
Not open for further replies.

Share This Page