Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-3210

Giving a player an itemstack in PlayerItemConsume event shows incorrect amount in hotbar

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Minor Minor
    • None
    • None
    • 29.04 11:11:52 [Server] INFO This server is running CraftBukkit version git-Spigot-28463de-a2af8f0 (MC: 1.11.2) (Implementing API version 1.11.2-R0.1-SNAPSHOT)

    • custom code

      The following code causes the bug.

       

      @EventHandler
      public void onPlayerEat(PlayerItemConsumeEvent e)
      {
      
      
      
          if (e.getItem().getType() == Material.GOLDEN_APPLE && e.getItem().getData().getData() == (byte) 1) {
              Player plr = e.getPlayer();
      
              ItemStack is = e.getItem().clone();
              is.setAmount(1);
      
      //        ItemStack is = new ItemStack(Material.GOLDEN_APPLE);
      //        is.setDurability((short)1);
      
              plr.getInventory().addItem(is);
              plr.updateInventory();
      
          }
      
      }
      
      

      If you eat a god apple this code gives the player a replacement God apple.   If you do this with one apple in your hotbar, upon replacement the amount in the bar shows that you have TWO apples.   Dropping the item and picking it up, or clicking on it in your inventory instantly updates the amount to the correct number so it is purely a visual bug.

      Likewise if you create a new item stack and set the data the same issue arises.  If you have 17 apples and eat one, after the code executes it shows that you have 18 apples, picking up the apples or dropping them fixes the number back to 17.

       

      Oddly enough if you eat 1 gapple then eat a second the issue does not repeat itself, it stays at the +1 number until you mess with the item in your inventory.

      The code commented was another method I tried which produces the same result.

            Unassigned Unassigned
            whoolieshop Shane Martin
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: