material problem

Discussion in 'Plugin Development' started by mihalaras11, Jun 26, 2015.

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

    mihalaras11

    hey guys i have a problem with materials i want to give my players for example 5 soups but i want to use Material.getMaterial("282") because i prefer item ids instead of using material.mushroom_soup, 5 but i cant set the amount
    i tried lots of things like 282, 5 but nothing worked
     
  2. Offline

    Totom3

    ...edit the amount of the ItemStack you're giving to the players? The amount is not related to the Material.
     
  3. Offline

    Reynergodoy

    getItemId :)
     
  4. Offline

    mihalaras11

    didn't work
     
  5. Offline

    Zekrom2802

    Use:
    Code:
    player.getInventory().addItem(new ItemStack(Material.getMaterial(id ItemID), int amount));

    So in your case it's:
    Code:
    player.getInventory().addItem(new ItemStack(Material.getMaterial(282), 5));

    But it's deprecated and I highly recommend you to use item names. It's a lot easier and ID's will vanish soon.
     
  6. Offline

    mihalaras11

    yeah but i want to let users edit the plugin via config and its harder to write MUSSROOM_SOUP than writing 282
     
  7. Online

    timtower Administrator Administrator Moderator

    mihalaras11 likes this.
  8. Offline

    mihalaras11

    @Zekrom2802 tried
    if (cmd.getName().equalsIgnoreCase("soup")){
    player.getInventory().addItem(new ItemStack(Material.getMaterial("282"), 5));
    }

    and when i perform /soup ingame and internal error occures . any idea?
     
  9. Online

    timtower Administrator Administrator Moderator

    @mihalaras11 Material.getMaterial("282")
    That won't work, it won't take numbers, you need to type the names.
     
  10. Remove the quotes.

    But like
    @timtower and @Zekrom2802 said, you shouldn't be using item ids. Make the server owners type out the material.
     
    mihalaras11 likes this.
  11. Offline

    Konato_K

    @mihalaras11 Use Material#matchMaterial and make everyone happy.
     
    mihalaras11 likes this.
Thread Status:
Not open for further replies.

Share This Page