Plugin Help How can i know set a specific durabilty¿?

Discussion in 'Plugin Help/Development/Requests' started by ratg97, Apr 7, 2015.

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

    ratg97

    In this code:

    Code:
      public void run()
          {
            for (Player all : getServer().getOnlinePlayers( ) ) {
              if (all.getGameMode() != GameMode.CREATIVE) {
                if (all.getInventory().getChestplate() != null)
                {
                  if ((all.getInventory().getChestplate().getItemMeta().equals(Main.getJetPack().getItemMeta())) && (all.getInventory().getChestplate().getDurability() < 64))
                  {
                    all.setAllowFlight(true);
                    if (!Main.useJetpack.contains(all)) {
                      Main.useJetpack.add(all);
                    }
                  }
                  else
                  {
                    noJetPack(all);
                  }
                }
                else {
                  noJetPack(all);
                }
              }
            }
          }
         
          private void noJetPack(Player all)
          {
            all.setAllowFlight(false);
            if (Main.useJetpack.contains(all)) {
              Main.useJetpack.remove(all);
            }
          }
        }, 5L, 5L);
       
        Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable()
        {
          public void run()
          {
            for (Player user : Main.useJetpack) {
              if ((user.isFlying()) && (user.getGameMode() != GameMode.CREATIVE)) {
                user.getInventory().getChestplate().setDurability((short)(user.getInventory().getChestplate().getDurability() + 1));
              }
            }
          }
        }, 200L, 200L);
      }
      
    i need how to increase or less

    EDIT by Timtower: merged posts
     
    Last edited by a moderator: Apr 7, 2015
  2. Offline

    BizarrePlatinum

    @ratg97 You should be subtracting from the current durability, not adding to it.
     
  3. Offline

    ratg97

    what i change?
     
  4. Offline

    2008Choco

    What @BizarrePlatinum is saying, is change this:
    Code:
            for (Player user : Main.useJetpack) {
              if ((user.isFlying()) && (user.getGameMode() != GameMode.CREATIVE)) {
                user.getInventory().getChestplate().setDurability((short)(user.getInventory().getChestplate().getDurability() + 1));
              }
            }
    To this:
    Code:
            for (Player user : Main.useJetpack) {
              if ((user.isFlying()) && (user.getGameMode() != GameMode.CREATIVE)) {
                user.getInventory().getChestplate().setDurability((short)(user.getInventory().getChestplate().getDurability() - 1));
              }
            }
    (The change is from +1 to -1. That will decrease the durability)
     
  5. Offline

    pie_flavor

    @2008 Unless Bukkit is being ninja, that's false. A diamond pick with a durability of 0 is unbroken, a diamond pick with a durability of 1559 has 3 uses left in it.
     
    2008Choco likes this.
Thread Status:
Not open for further replies.

Share This Page