Destroy a block in area automatically

Discussion in 'Plugin Development' started by RockTheFlag, Dec 25, 2017.

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

    RockTheFlag

    Hello,

    So i am trying to make a plugin, that would let players in certain area "Afk mine".
    Here's how it should work:

    If a player is in world guard region AFK1, and he's holding a pickaxe, it should simulate a block destruction in a mine, that is in that area. I have a method of testing if player is in the region, if he's holding a pickaxe, but here comes the problem:
    • How do i simulate the block breaking(including enchants on the pickaxe(for example fortune on block ( for example 7 blocks in 10 seconds ))) in a mine(mineresetlite), that is in that region (the mine is only stone blocks, so it could be easier to test it maybe?)?
    EDIT: current code:
    Code:
          new BukkitRunnable() {
              public void run() {
                timer();
                for (Player p : Bukkit.getOnlinePlayers()) {
                    Material rankoi = p.getItemInHand().getType();
                    for(ProtectedRegion r : WGBukkit.getRegionManager(p.getWorld()).getApplicableRegions(p.getLocation())) {
                        if (r.getId().equalsIgnoreCase("afk1")) {
                            if(!(rankoi == Material.DIAMOND_PICKAXE || rankoi == Material.IRON_PICKAXE || rankoi == Material.GOLD_PICKAXE || rankoi == Material.WOOD_PICKAXE || rankoi == Material.STONE_PICKAXE)) {                    
                            //    p.sendMessage(ChatColor.AQUA + "HOLD UR PICKAXE");
                            } else {
                                //  Bukkit.getServer().broadcastMessage(ChatColor.GRAY + "[" + ChatColor.YELLOW + "GamersPlay" + ChatColor.GRAY + "]" + ChatColor.GREEN + " TESTING (im holding it )");
                            }
                        }
                    }
                }
              }
            }.runTaskTimer(instance, 0, 40);
    Any suggestion / answers would be really appreciated!
    Let's hope for Christmas miracle!

    Got it kinda working: blocks are auto mining, but enchants are not working :/
    also Pickaxe keeps full durability. Code used for breaking the block:

    Code:
    block.breakNaturally(p.getItemInHand()); //BREAK THE BLOCK
    p.getItemInHand().setDurability((short) (p.getItemInHand().getDurability() - 1));
     
    Last edited: Dec 26, 2017
  2. Offline

    leduyquang753

    Maybe you can simulate the enchantments yourself?

    The ItemStacks have durability values: ItemStack.getDurability(); ItemStack.setDurability(short durability);
     
  3. Offline

    ipodtouch0218

    An even easier way would be to call a BlockBreakEvent, as it uses enchantments (afaik)

    Use the Bukkit.getPluginManager().callEvent(Event) method to call the event. All you have to do is fill out the constructor parameters
     
  4. Offline

    RockTheFlag

    I LOVE YOU!
    Thanks for your response <3
     
Thread Status:
Not open for further replies.

Share This Page