Solved Safely Giving Items To a Player?

Discussion in 'Plugin Development' started by NerdsWBNerds, Apr 18, 2014.

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

    NerdsWBNerds

    How can I give a player items if he has enough room in his inventory, and drop the remaining items on the floor at his feet if he only has enough room for some of the items?
     
  2. Offline

    rfsantos1996

    Inventory.addItem(ItemStack) is a HashMap of Integer and ItemStack.

    The "remaining" that couldn't be given to the player is here. So just:
    Code:java
    1. for(ItemStack is : player.getInventory().addItem(item)) {
    2. player.getWorld().dropItemNaturally(player.getLocation(), is);
    3. }
     
  3. Offline

    NerdsWBNerds


    <3


    Also, how would I make it so that it won't add an itemstack that has more than it's max stack, i.e. only 1 sword to a stack or something?

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

    rfsantos1996

    When dropped you mean? I don't know D; You can change this when using spigot's spigot.yml, but its only for the server owner.
     
Thread Status:
Not open for further replies.

Share This Page