Keep inventory for one specific player?

Discussion in 'Spigot Plugin Development' started by PretMetInternet, Aug 16, 2018.

  1. Hello,
    There's something I am struggeling with.
    I am making a Custom Plugin, with KitPvP in it. I want the loot on a player's death not to drop, and I want to do this by setting the keep inventory to true for only the players in the arena, and then, when they respawn, clearing their inventory, so that I can give them the item with which they can choose their kit.
    Does someone know another method of not letting the items drop?
    Or does someone know how to let specific players only keep their inventory?
    Every bit of help would be appriciated!
     
  2. Code (Java):
    @EventHandler
    public void onPlayerDeath(PlayerDeathEvent event) {
        Player player = event.getEntity();
        if (isInArena(player)) {
            event.setKeepInventory(true);
            event.setKeepLevel(true);
        }
    }
    Make a method that checks if a player is in the arena or not.
     
    • Agree Agree x 1
  3. You can check for a
    PlayerRespawnEvent and clear their inventory when its called.
    As for item dropping, i will look into my code i have a feature and i will tell you.
     
  4. store players inventory in a hashmap and give those items back on respawn?
     
  5. Umm i dont think he wants to store the inv. He just needs it cleared so he can give the item that selects kits.
     
  6. "Or does someone know how to let specific players only keep their inventory?"
    but now after re reading the post, my bad.

    on deathevent do e.setDrops().clear();
    Code (Text):
    @EventHandler
    public void die(PlayerDeathEvent e){
    e.getDrops().clear();
    }
    Players inventory should already be reset no on playerdeathevent unless you have keepinventory on, if so then you need to clear their inventories on deathevent
    then on respawnevent give them the items
     
    #6 FalconSeeker, Aug 17, 2018
    Last edited: Aug 17, 2018
  7. Ah yes. I thought he wanted to not let players drop items while pvping :3