.getItemId(); replacement?

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

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


    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:
    1. player.getIteminHand().getTypeId();

    However the
    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?
  2. Offline

    Deleted user

    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.


    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


  4. Offline


    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
    1. Material handMat = player.getItemInHand().getType();
  5. Offline


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


    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