getItemInHand() Method Deprecated as of 1.9 (Also 1.10)

Discussion in 'Plugin Help/Development/Requests' started by JohnCollin, Jul 24, 2016.

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

    JohnCollin

    As soon as 1.9 came out, with it came the new feature of duel wielding. I'd like to help anyone who has not discovered that the method we're used to is now, unfortunately deprecated!

    Previously, it was easily done.
    Code:
    public ItemStack getItem(Player player) {
        return player.getItemInHand();
    }
    Now, with the duel wielding feature that has come with 1.9, we have to use the player.getInventory() method to access the sub-methods we're looking for.

    For Example:

    For Getting the Main Hand:
    Code:
    public ItemStack getItem(Player player) {
        return player.getInventory().getItemInMainHand();
    }
    For Getting the Off (Secondary) Hand:
    Code:
    public ItemStack getItem(Player player) {
        return player.getInventory().getItemInOffHand();
    }
    If this helped, make sure to let me know!
     
    DaniroCraft likes this.
  2. This is the place for questions on help/development/requests. You might want to move this somewhere else
     
Thread Status:
Not open for further replies.

Share This Page