Solved Giving a player an item

Discussion in 'Plugin Development' started by Dolphineer, May 17, 2014.

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

    Dolphineer

    I'm testing out a way to give my players 3 Diamonds so they can craft a new pickaxe since I run a mining server.
    ItemStack itemstack = new ItemStack(Material.DIAMOND, 64); // A stack of diamonds player.getInventory().addItem(Material.DIAMOND);
    But it throws this error for the addItem part: The method addItem(ItemStack...) in the type Inventory is not applicable for the arguments (Material) These are my imports: import org.bukkit.Material; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.plugin.java.JavaPlugin;
     
  2. Offline

    Xyplo

    You need to make a new ItemStack first...
     
  3. Offline

    ImPhantom

    Dolphineer
    If Xyplo solved your question please edit the thread title to "Solved" (Click on the thing that says "Solved")
     
  4. Offline

    JellyYods

    Code:java
    1. @Override
    2. public boolean onCommand(CommandSender sender, Command cmd, String label,
    3. String[] args) {
    4. if(cmd.getName().equalsIgnoreCase("diamondfuel"));
    5. Player player = (Player)sender;
    6. player.getInventory().addItem(new ItemStack(Material.DIAMOND, 3));
    7. return false;
    8. }



    Example

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  5. Offline

    Dolphineer

    I run the command, but it doesn't give my any diamonds, no output in -game, either.
     
  6. Offline

    Mr Burkes

    I believe this is a bukkit bug for the latest beta/development builds; I tried something similar but got nothing. When running in the latest recommended build, however, it works.
     
  7. Offline

    Zupsub

    Maybe you have to set the Inventory after the operation:
    Inventory i = player.getInventory();
    i.add....
    player.setInventory(i);
     
Thread Status:
Not open for further replies.

Share This Page