Bedrock Mining Help

Discussion in 'Plugin Development' started by xTeCnOxShAdOwZz, Apr 9, 2014.

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

    xTeCnOxShAdOwZz

    Plugin category:​
    Tool Modification​

    Suggested name:​
    MegaPix​

    What I want: ​
    Basically, I have coded 99% of my plugin which allows a player to receive a special plugin which has the ability to mine bedrock. It does work, but I have a problem where the event that causes the bedrock that is being mined to be destroyed even if the player stops mining it.​
    I have a timer where it can take, for example, 5 seconds for the bedrock to be mined, but the event is triggered when a player left-clicks a block of bedrock. This means that even if they tap it with the pickaxe, then wait 5 seconds, it will dissappear. I want the player to have to keep their mouse held on the block, like normal block destruction.​
    I don't know how to code it so that upon cancelling mining the block, it will also cancel the event.​
    Here is some of the code:​
    Code:
    @EventHandler(priority=EventPriority.LOW)
      public void onPlayerInteract(PlayerInteractEvent event)
      {
        final Block block = event.getClickedBlock();
        final Player p = event.getPlayer();
        if ((event.getAction() == Action.RIGHT_CLICK_AIR) ||
          (event.getAction() == Action.RIGHT_CLICK_BLOCK) ||
          (event.getAction() == Action.PHYSICAL)) {
          return;
        }
        if (this.bedrockMiners.contains(p.getName()))
        {
          ItemStack item = p.getItemInHand();
          if ((item.getType() == this.reqItem.getType()) &&
            (event.getItem().getItemMeta().getDisplayName().equals(ChatColor.DARK_AQUA + getConfig().getString("Name"))) &&
            (event.getClickedBlock().getType().equals(Material.BEDROCK)) &&
            (block.getLocation().getY() >= this.minBreakY)) {
            Bukkit.getScheduler().scheduleSyncDelayedTask(this,
              new Runnable()
              {
                public void run()
                {
                  if (p.getLocation().distance(block.getLocation()) < 6.0D)
                  {
                   
                    block.setType(Material.AIR);
                    block.getLocation().getBlock()
                      .setType(Material.AIR);
                    p.playSound(p.getLocation(), Sound.ENDERMAN_TELEPORT, 10, 1);
                    p.getItemInHand().setDurability(
                            (short) (p.getItemInHand().getDurability() + 40));
                    ItemStack bedrock = new ItemStack(
                      Material.BEDROCK, 1);
                    if (Main.this.dropBedrock) {
                      p.getWorld().dropItemNaturally(
                        block.getLocation(),
                        bedrock);
                    }
                  }
                }
              }, this.time * 20);
          }
        }
      }
    }
     
     
    [CENTER]
    [LEFT]If you can see what I'm doing wrong, that would be great! Thanks, xTeCnOxShAdOwZz[/LEFT]
    
    [B][LEFT]When I'd like it by: [/LEFT][/B][LEFT]Soon[/LEFT][/CENTER]
    bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  2. Offline

    Onlineids

    Wrong section and only bump every 24 hours
     
  3. Offline

    Jade Retired Staff

    Moved to correct section and please only bump once every 24 hours.
     
Thread Status:
Not open for further replies.

Share This Page