[Solved] Code disabled on a location?

Discussion in 'Plugin Development' started by BrandonHopkins, Sep 1, 2012.

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

    BrandonHopkins

    I'm adding a way to get bedrock in my MachiDrop plugin. What I was wondering is there a way to disable the code for the very last layer of BedRock? If so how would I go about that? Thank You.

    Code:
    //BedRock Drop
        @EventHandler
        public void onClick(PlayerInteractEvent event)
        {
       Player p = event.getPlayer();
       if(p.getGameMode() == GameMode.CREATIVE)
          return;
            if (event.getAction().equals(Action.LEFT_CLICK_BLOCK))
            if (event.getPlayer().getItemInHand().getType() == Material.GOLD_PICKAXE)
            {
                Block block = event.getClickedBlock();
                if (block.getType().equals(Material.BEDROCK))
                {
               if(p.hasPermission("machidrop.use.bedrock"))
                    {
               ItemStack hand = p.getItemInHand();
               hand.setDurability((short) (p.getItemInHand().getDurability() + 11));
               p.setItemInHand(hand.getDurability() > hand.getType().getMaxDurability() ? null : hand);
                   event.getClickedBlock().getWorld().dropItemNaturally(event.getClickedBlock().getLocation(), new ItemStack(7, 1));
                   event.getClickedBlock().setType(Material.AIR);
                    } else
                    {
                        p.sendMessage(ChatColor.RED + "[MachiDrop] You don't have permission to use this tool");
                    }
                }
            }
        }
     
  2. Offline

    Courier

    Code:
    if(block.getY() == 0)
        return;
     
  3. Offline

    ninja_ace202

    The Y coord of 0 is not always actually a bedrock block. Sometimes the lowest bedrock block is 1 or even 2. It seems like you would have to check what block is under the block you want to check. If the block underneath it is the void then I assume getting that block would return null. Assuming that...
    Code:
    if(event.getPlayer().getWorld().getBlockAt(block.getX(),block.getY()-1,block.getZ()==null)
    return;
    Although even then, if the last layer of bedrock is at 2 Y then the block would still get destroyed. Looks like you would have to tack on a loop or something in case the block under the bedrock is air and go all the way until you can verify the bedrock block has a block between it and the void. Makes sense or am I dumb? :p
     
  4. Offline

    BrandonHopkins

    Thanks :3
     
  5. Offline

    Courier

    I don't think that is a problem anymore.

    The bottom layer has been bedrock for a while. It had gaps in older versions of Minecraft. I can't remember exactly when it was changed.
     
  6. Offline

    ninja_ace202

    If that's the case then please do completely disregard my post. :D
     
Thread Status:
Not open for further replies.

Share This Page