Making Players Pick Only 1 Item

Discussion in 'Plugin Development' started by lightlord323, Jan 18, 2015.

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

    lightlord323

    So i need to make a player only pick up 1 item at a time, for example, if there was a stack of diamonds on the ground, i want them to only have 1 diamond when they pick it up.
     
  2. Offline

    BurnerDiamond

    Just check if a player has more than 1 diamond in his inventory and if not delete the amount.
     
  3. Offline

    lightlord323

    Figured it out, here's the code for anyone who needs it, and thanks @BurnerDiamond for replying :)


    Code:
    @EventHandler
        public void onPick(PlayerPickupItemEvent e) {
           
            if(e.getItem().getItemStack().getAmount() > 1) {
                e.setCancelled(true);
               
                ItemStack d = new ItemStack(e.getItem().getItemStack());
                d.setAmount(1);
               
                e.getPlayer().getInventory().addItem(d);
                e.getItem().remove();
            }
           
        }
     
Thread Status:
Not open for further replies.

Share This Page