.getItemId(); replacement?

Discussion in 'Plugin Development' started by Bancey, Jun 16, 2014.

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

    Bancey

    Hello,
    So I have been revisiting my plugins and I have been trying to get the Id of an item in the players hand. Now before I used this:
    Code:java
    1. player.getIteminHand().getTypeId();

    However the
    Code:java
    1. .getTypeId();
    method has been depreciated and I cannot find a suitable replacement that will do the same thing. Has anyone ran into this issue and does anyone know of anyother way to do this?
    Thanks
    -Bancey
     
  2. Offline

    Deleted user

    Bancey
    Plain old getType?

    Bancey Even if it is deprecated it should still work. Have you tested it?

    EDIT: The reason it was deprecated is because the names of blocks are for example minecraft_wool now.

    Bancey

    Switch over to using getType and Material#matchMaterial()

    matchMaterial takes a String, but can parse itemids as well

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Feb 9, 2022
  3. Offline

    Bancey

  4. Offline

    gabizou

    Bancey the reason for it being deprecated is because the entire numerical ID system for blocks and items is being phased out for the like of using a string name system internally in mine craft. Bukkit already has it's Material enum of which you should be using instead of the ID system. If you can, try to migrate from using the ID system to Material enum. It's doable via
    Code:java
    1. Material handMat = player.getItemInHand().getType();
     
  5. Offline

    Evyatar12

    Code:
    int id = player.getItemInHand().getType().getID();
    Doesn't it what you mean?
     
  6. Offline

    1Rogue


    Why even bother, you already have a material type which is unique via .getType(). Why struggle to keep track of arbitrary magic numbers when you can simply use an enum (as the purpose it was made for) via the JLS.
     
Thread Status:
Not open for further replies.

Share This Page