Axe problem

Discussion in 'Spigot Plugin Development' started by KyleMan, May 25, 2015.

  1. Ok so this is a wierd bug. My friend asked for a treefarm plugin, because the old one he had stopped working. So after making it, I encountered a problem. Whenever someone chops a tree, when they right-click the axe they were using, it resets the durability. I now find out that the old plugin also did this when it did work. Is there a way to fix this or is this inevitable? Here is some parts of the code to get what I am doing.
    Code (Text):

    else if(block.getType() == Material.LOG && c == true){ //c means that if the block is in the treefarm area
                if((locUnder.getBlock().getType() == Material.DIRT) || (locUnder.getBlock().getType() == Material.GRASS)){
                w.dropItem(block.getLocation(), drop);
                player.getItemInHand().setDurability((new Integer(player.getItemInHand().getDurability() - 10)).shortValue());
                //NEED TO DROP LOG
                    player.getItemInHand().setDurability((new Integer(player.getItemInHand().getDurability() - 10)).shortValue());
                    //if (player.getItemInHand().getType() == Material.DIAMOND_AXE){
    That is onBlockBreakEvent

    Please help and thanks for your time

    P.S. The setDurability does not change anything whether or not its in there. Still does not work
  2. The trick is easy: replace your -10 with +10. The higher the durability, the less uses you got left. Btw. setDurability will never break the axe, you have to break it on your own
  3. Nope dont seem to understand ill put a video of the bug

  4. Look at the axe regenerates when you right click after chopping trees
  5. What @Friwi said is correct. Also you should update the players inventory so that the client takes note of the changes yiu have made.
  6. This is deprecated^^
  7. The axe regenerates because you are decreasing the durability. setDurability should be named setAlreadyUsed