Solved Get item from id

Discussion in 'Plugin Development' started by TFOXTom, Jun 14, 2018.

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


    I've got an int id from my config file, that I want to convert into an itemstack(like the give command did. You pass in an id, and get the corresponding item. But then in code lol).
    The problem is that I don't know how to go about this. Like, which functions do I have to call?
    It would be great if anyone can help me!
  2. Offline


    Material.getMaterial( ID );
  3. Offline


    Here is some code that I think will work:
    ItemStack item;
    int i = getPlugin().getConfig().getInt("entryname");
    item = new ItemStack(Material.getMaterial(i));
    This first grabs the int stored in the configuration file. (You must have a reference to your main plugin class to access it) It then creates a new ItemStack with the material by ID.

    Please note, however, that finding materials by ID is deprecated. Minecraft has moved on from Item IDs and they can be cut completely without notice.
  4. Offline


    Thanks for the note! But how do we do it in the future? Because it would really suck if we have to do minecraft:someitem in the config.
  5. Offline

    timtower Moderator Moderator

    @TFOXTom Material names are pretty common to use with Bukkit
  6. Offline


    Well, that would be long typing for the people that want to change the config :p
  7. Offline

    timtower Moderator Moderator

    Yes, but they won't have to look up the ID's anymore as the names are pretty descriptive.
  8. Offline


    There you have a point :p
  9. Offline


    Try this?
Thread Status:
Not open for further replies.

Share This Page