Giving an item to a player (Help me)

Discussion in 'Plugin Development' started by nanerz_123, Aug 9, 2014.

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

    nanerz_123

    I am creating a plugin, and I was wondering how I could give and item to a player. If they use my command "/givewool (player)" I want to give the target the wool, rather than the sender. Also is there a way I could do this with item ids? Instead of material.Wool? Can I just use the item id 35 rather? Thanks in advance :)
     
  2. Offline

    mythbusterma

    Yes, you can give a player an ItemStack, and set the type of the ItemStack via .setTypeId(int id), using Server#matchPlayer() to get the player to target.
     
  3. Offline

    nanerz_123

  4. Offline

    mythbusterma

  5. Offline

    nanerz_123

  6. Offline

    mythbusterma

    Like..

    Bukkit.getServer().matchPlayer(name).get(0).getInventory().addItem(new ItemStack(Material.getMaterial(id),amount)
     
  7. Offline

    nanerz_123

    Do I just copy and paste that? lol
     
  8. Offline

    pookeythekid

    nanerz_123 Well... Not to give you the answer but...
    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    2. if (label.equalsIgnoreCase("givewool")) {
    3. if (args.length == 1) {
    4. Player p = Bukkit.getServer().getPlayer(args[0]);
    5. PlayerInventory pi = p.getInventory();
    6. ItemStack stack = new ItemStack(Material.WOOL/*or the integer ID for wool*/, 1);
    7. pi.addItem(stack);
    8. }
    9. }
    10. }
     
  9. Offline

    mythbusterma

  10. Offline

    nanerz_123

  11. Offline

    pookeythekid

Thread Status:
Not open for further replies.

Share This Page