getRelative()

Discussion in 'Plugin Development' started by MattTheBeast, Mar 13, 2017.

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

    MattTheBeast

    Hi so im trying to make a barbed wire plugin and I dont whant to use a block place event, I whant to use the iterract, then get the clicked side then add a web on it, but the problem is that it places 6 webs all around...

    help?

    Code:
    @EventHandler
        public void onWebPlace(PlayerInteractEvent e)
        {
          
            Player p = e.getPlayer();
            final Block b = e.getClickedBlock();
            ItemStack i = e.getItem();
          
            if ((e.getAction() == Action.RIGHT_CLICK_BLOCK) &&
                    (i != null) &&
                    (b.getType() != Material.WATER) &&
                    (i.getType() == Material.WEB))
                    {
                       Location Web = new Location(p.getWorld(), b.getX(), b.getY(), b.getZ());
                      
                       //
                       if(b.getLocation().getBlock().getRelative(BlockFace.EAST, 1) != null)
                       {
                          Web.add(-1, 0, 0).getBlock().setType(Material.WEB);
                          Webs.put(Web, b.getType());
                       }
                       if(b.getLocation().getBlock().getRelative(BlockFace.WEST, 1) != null)
                       {
                          Web.add(2, 0, 0).getBlock().setType(Material.WEB);
                          Webs.put(Web, b.getType());
                       }
                       //
                       if(b.getLocation().getBlock().getRelative(BlockFace.NORTH, 1) != null)
                       {
                          Web.add(-1, 0, -1).getBlock().setType(Material.WEB);
                          Webs.put(Web, b.getType());
                       }
                       if(b.getLocation().getBlock().getRelative(BlockFace.SOUTH, 1) != null)
                       {
                          Web.add(0, 0, 2).getBlock().setType(Material.WEB);
                          Webs.put(Web, b.getType());
                       }
                       //
                       if(b.getLocation().getBlock().getRelative(BlockFace.UP, 1) != null)
                       {
                          Web.add(0, -1, -1).getBlock().setType(Material.WEB);
                          Webs.put(Web, b.getType());
                       }
                       if(b.getLocation().getBlock().getRelative(BlockFace.DOWN, 1) != null)
                       {
                          Web.add(0, 2, 0).getBlock().setType(Material.WEB);
                          Webs.put(Web, b.getType());
                       }
                    
                      
                        p.getWorld().playSound(p.getLocation(), Sound.ANVIL_LAND, 1.0F, 1.0F);
                      
                    }
        }
     
    Last edited by a moderator: Mar 13, 2017
  2. Offline

    MrMinecraft15

    the query "b.getLocation().getBlock().getRelative(BlockFace.NORTH, 1) != null" will never exist, cause a bock on a location is never null. It might be the type (b.getLocation().getBlock().getType()) "Material.AIR".
     
Thread Status:
Not open for further replies.

Share This Page