Can't add items to player inventory [SOLVED]

Discussion in 'Plugin Development' started by SenojLuap, Oct 3, 2011.

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


    I can't figure out what's wrong with this. It builds correctly, and when I test it out in game, it prints the 'bukkit' message correctly. However, it doesn't add the item.
      public void onBlockPlace(BlockPlaceEvent bpe) {
        PlayerInventory inv = bpe.getPlayer().getInventory();
        ItemStack bucket = new ItemStack(Material.ENDER_PEARL, 1);
        HashMap<Integer, ItemStack> leftovers = inv.addItem(bucket);
        bpe.getPlayer().sendMessage(ChatColor.DARK_PURPLE +
                "Haz you seen mah bukkit?");
          bpe.getPlayer().sendMessage(ChatColor.DARK_RED + "Oh noes!");
  2. Offline


    add this:
    It's deprecated for quite some time now, but I don't know any other way.
  3. Offline


    I swear I'd tried that before and it didn't work. But for the sake of eliminating possibilities I tried again and it worked. Very weird. But in running a few tests, I came to another "problem" (not exactly a problem).
    When I try to add a bucket to the players inventory using
    new ItemStack(Material.BUCKET);
    some very funny stuff happens in game. But if I use
    new ItemStack(Material.BUCKET, 1);
    it works just fine. Is this a known problem; is this expected behavior?
  4. Offline


    Giving no amount means both 0 and infinite - it causes "funny stuff".
    Always remember to check if the quantity is greater than 0, or bad things happen.
  5. Offline


    Aight. That makes sense.
    Getting back to the updateInventory() thing: they show it as being deprecated, and yet it seems to be the only way to get this simple command to work. Does anyone know if they plan on making it so that addItem() will force it's own update? Subquestion, if it's deprecated, is there some other method I should be calling instead?
  6. Offline


    player.updateInventory() is deprecated because it's a minecraft doesn't refresh inventories automatically :D
    So they created this,and it's a hacky way of doing it,they're searching for a better way :]
  7. Offline


    Thanks for clarification, I didn't know that. :)
Thread Status:
Not open for further replies.

Share This Page