1.17.x Keeping potion effects after deaths.

Discussion in 'Spigot Plugin Development' started by lauritslayer04, Jun 22, 2021.

  1. Hello. I was wondering if anyone have any idea on how I can make people keep potion effects after death? I have looked through the internet for quite some time now and I have only found methods that are outdated.
     
  2. This seems pretty simple, listen to PlayerDeathEvent and check if the player has potion effects, if so store the players UUID in a map with the value being the potion effects they had when they died then listen to the PlayerRespawnEvent and check if the player respawning is inside the map and if they are delay it by a tick or two and give them back the potion effects you have stored.
     
    • Agree Agree x 7
  3. Bobcatsss already said everything, but I just feel like helping since I don't do it often. So to get the player effects, use Player#getActivePotionEffects() (but check if it's not null). Save them somewhere, you might want to use a Map<Player, Collection<PotionEffect>> to save them. Then on PlayerRespawnEvent just check if the map contains that player, and if it does, iterate through the collection of potion effects and add them to the player one by one.