[Solved] Player PotionEffectData Removal

I’ve noticed that there are several posts on how to add potion effects to players. My questions is, how can one remove potion effects from players? I’ve tried the code below, but it doesn’t work. Thanks!

	Optional<PotionEffectData> playerPotionEffects = player.get(PotionEffectData.class);
	
	if(playerPotionEffects.isPresent()){
		
		PotionEffectData potionEffects = playerPotionEffects.get();
		
		for(PotionEffect potionEffect: potionEffects.effects().get()){
			
			player.get(PotionEffectData.class).get().remove(potionEffect);
		}
		
		//potionEffects.effects().get().clear();

this may help:

List<PotionEffect> effects = player.get(Keys.POTION_EFFECTS).get();
effects.clear(); //or remove some of you want to remove
player.offer(Keys.POTION_EFFECTS, effects);
2 Likes

This did the trick! Thank you! :grinning::slight_smile: