Why spade doesn't break (BlockBreakEvent)

Discussion in 'Plugin Development' started by Ibas, Sep 15, 2013.

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

    Ibas

    Hey, I want that if player breaks snow block drop would be snow block not snow balls, I have wrote code and everything seems working only just 1 thing spade doesn't break at the last use, but I hear "breaking" sound and it dissapears and then again appears after 0.1 second. It seems that I shouldn't cancel the event just replace the drop somehow or something, please help.

    Code:java
    1. if(e.getBlock().getType() == Material.SNOW_BLOCK && e.isCancelled() == false && e.getPlayer().getItemInHand().getType().toString().endsWith("SPADE")){
    2. e.setCancelled(true);
    3. e.getBlock().setType(Material.AIR);
    4. e.getPlayer().getItemInHand().setDurability((short) (e.getPlayer().getItemInHand().getDurability()+1));
    5. e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), new ItemStack(Material.SNOW_BLOCK));
    6. }
     
  2. why not use .setDurabillity()
     
  3. Offline

    hanahouhanah

    You should check if the durability is equivalent to the max durability (haven't worked with durability in a while so I'm not exactly sure if I used those terms right), then:
    Code:java
    1. Player player = e.getPlayer();
    2. player.getItemInHand().setType(Material.AIR);
     
  4. Offline

    Ibas


    I'm doing that...


    Isn't there more efficient way than this?
     
  5. Offline

    hanahouhanah

    Ibas
    From what I know, that's the most efficient way- unless someone knows a better one.
     
Thread Status:
Not open for further replies.

Share This Page