Giving a player an item specified in args

Discussion in 'Plugin Development' started by awesomeness14721, Dec 29, 2014.

Thread Status:
Not open for further replies.
  1. Hello everyone, just a quick question with the onCommand() method. I am creating a plugin that gives the player using the command the item and an amount of that item, specified in the first and second arguments. How would I add the item they specify in args[0] to an ItemStack?

    Thanks in advance.
     
  2. Offline

    mine-care

    This thread belongs on PluginDevelopment section,
    To answer your question, after you have done the proper argument checks, lets asume the command is:
    /i <itemID> ammount
    to turn this^ to a itemstack use:
    ItemStack is = new ItemStack(Material.getMaterial(Integer.parseInt(args[0])),Integer.parseInt(args[1]));
    there you have it.
    Handle properly nulls because given id might not be a material like 08992358 is not a valid id.
     
    Last edited: Dec 29, 2014
  3. Moved to Plugin Development.
     
  4. Offline

    Gamesareme

    @mine-care Hello again, :) . You have made a mistake in your code. You have a "," when you are meant to have a "."
     
  5. Offline

    mine-care

    @Gamesareme code was written on phone. i really mess those buttonz xD
    Thx though, i will fix it :) good catch.
     
  6. Offline

    Gamesareme

  7. Thanks a ton!!!
     
  8. Offline

    mine-care

Thread Status:
Not open for further replies.

Share This Page