Empty Player Inventory AFTER Quit

Discussion in 'Plugin Development' started by alexander_q, Dec 4, 2011.

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

    alexander_q

    I have set up some code to register when the player quits, and now I want to empty their inventory at their location. The code I am using was published by codename_B.


    Code:
    ItemStack[] stacks = player.getInventory().getContents().clone();
    player.getInventory().setContents(new ItemStack[stacks.length]);
    for (ItemStack stack : stacks)
        if (stack != null) player.getWorld().dropItemNaturally(player.getLocation(), stack);
        stacks = null;
    In practice it does not work. Can you see any problem with this code?
     
  2. Offline

    coldandtired

    Don't really understand what player.getInventory().setContents(new ItemStack[stacks.length]); is supposed to do.

    Do you want quitting players to have all their items dropped and their inventory wiped (as if they died )?

    You can use player.getInventory.clear() to do the second part.

    Something like this would probably do it:
    Code:
    for (ItemStack is : player.getInventory().getContents())
    if (is != null) player.getWorld().dropItemNaturally(player.getLocation(), is);
    player.getInventory.clear() ;
    
     
Thread Status:
Not open for further replies.

Share This Page