Setting a durability for a wood shovel

Discussion in 'Plugin Development' started by Addicted_24_7, Apr 14, 2013.

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

    Addicted_24_7

    I am trying to have my plugin do some durability on a wooden shovel when you right click.
    I have what I had thought i needed, but i keep getting "Incompatible operand types void and Material". Maybe someone in the community can help me :D
    Any ideas?
    The part of the code in question is below.

    Code:
    @EventHandler
          public void playerInteract(PlayerInteractEvent event)
          {
            Player player = event.getPlayer();
                Material gun = Material.WOOD_SPADE;
            if (((event.getAction() == Action.RIGHT_CLICK_AIR) || (event.getAction() == Action.RIGHT_CLICK_BLOCK)) &&
                      (player.getItemInHand().setDurability((short) (player.getItemInHand().getDurability() - 10)) == gun))
     
  2. Offline

    xXMaTTHDXx

    Command stuff.....
    Player p = event.getplayer();
    Material gun = p.getItemInHand(Material.WOOD_SPADE);
    If (event.getAction() == Action.RIGHT_CLICK_AIR) || (event.getAction() == Action.RIGHT_CLICK_BLOCK)){
    gun.setdurablility()// your durability


    It's something like that.
     
  3. Offline

    Addicted_24_7

    When I tried this it didnt like the durability... Heres what i have :/

    Code:
     ItemStack gun = player.getItemInHand();
            if (event.getAction() == Action.RIGHT_CLICK_AIR || (event.getAction() == Action.RIGHT_CLICK_BLOCK)){
                gun.getDurability();
     
  4. Addicted_24_7
    You're not doing anything there, you're getting the durability and that's it, you're not storing it, not checking it, not printing it, not doing anything...
     
  5. Try this:

    Code:
    @EventHandler
          public void playerInteract(PlayerInteractEvent event)
          {
            Player player = event.getPlayer();
                Material gun = Material.WOOD_SPADE;
            if (((event.getAction() == Action.RIGHT_CLICK_AIR) || (event.getAction() == Action.RIGHT_CLICK_BLOCK)) && player.getItemInHand().getType().equals(gun)){
                      player.getItemInHand().setDurability((short) (player.getItemInHand().getDurability()+10)
            }
          }
    Basically, rather than checking a durability and material, you were calculating the durability, and checking it equals the material. So it just needed re-organising :)
     
Thread Status:
Not open for further replies.

Share This Page