Change the durability of the chestplate while flying?

Discussion in 'Plugin Development' started by Wolftic, Feb 12, 2013.

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

    Wolftic

    How would I lower the durability from the chestplate your wearing while the player is flying? And which event?
     
  2. Offline

    bleachisback

    I assume that you want to be using PlayerMoveEvent. You can check if the player is flying by using event.getPlayer().isFlying() and you can use player.getInventory().getChestplate().setDurability(durability) to change the durability of the chestplate.
     
  3. Offline

    Wolftic

    Thanks this worked, but do you also know how to increase the durability and remove the item, because right now it just gives this long red bar.
     
  4. Offline

    bleachisback

    Do you mean increasing the maximum durability of an item? If so, doing that requires with NMS code, and I'm not sure it will actually work...

    If you just mean that you want to fix the long red bar, then increase the durability to its current durability -1, and it will slowly tick down.

    To get rid of the item, use player.getInventory().setChestPlate(null)
     
  5. Offline

    mb01

    Don't use the PlayerMoveEvent for that, it's "extremely CPU intensive".
    You just have to schedule a task that runs every X ticks (10 represents half a second and is probably enough) and check if a player is flying inside.
     
  6. Offline

    bleachisback

    Wolftic Just a warning, doing this will make the durability decrease, even if they're standing still (in the air).
     
  7. Offline

    Wolftic

    How would I do this? Any samples of codes?
     
  8. Offline

    bleachisback

  9. Offline

    molenzwiebel

    Code:
    Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
    //variables
    public void run() {
    p.getInventory().getChestPlate().setDurability(p.getInventory().getChestPlate().getDurability()-1);
    }
    }, 0L, 20L);
    Not tested
     
  10. Offline

    Wolftic

    It says I have to change the "player"(Player player = getServer().getPlayer(getName()) to an final and i'm not quite sure where I have to put this, since ive never used that before :s
     
  11. Offline

    molenzwiebel

    Code:
    public void startPlayerTracking(final Player p) {
    Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
    //variables
    public void run() {
    p.getInventory().getChestPlate().setDurability(p.getInventory().getChestPlate().getDurability()-1);
    }
    }, 0L, 20L);
    }
    As always, not tested

    EDIT: The schedule event gives a int id which you can use to stop the tracking
     
Thread Status:
Not open for further replies.

Share This Page