package hdr.glow.commands;

import org.spongepowered.api.command.CommandException;
import org.spongepowered.api.command.CommandResult;
import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.command.args.CommandContext;
import org.spongepowered.api.command.spec.CommandExecutor;
import org.spongepowered.api.data.key.Keys;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.effect.potion.PotionEffect;
import org.spongepowered.api.effect.potion.PotionEffectTypes;
import org.spongepowered.api.data.manipulator.mutable.PotionEffectData;
import org.spongepowered.api.text.chat.ChatTypes;
import org.spongepowered.api.text.format.TextColors;
import org.spongepowered.api.text.format.TextStyles;

import static hdr.glow.playerGlow.glowPot;
import java.util.List;

public class glowToggle implements CommandExecutor {
    @Override
    public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
        if (src instanceof Player) {
            Player player = (Player) src;
            if (player.get(Keys.POTION_EFFECTS).isPresent()) {
                List<PotionEffect> potionEffects = player.get(Keys.POTION_EFFECTS).get();
                for (PotionEffect pot : potionEffects) {
                    if (pot.getType().equals(PotionEffectTypes.GLOWING)) {
                        List<PotionEffect> effects = player.get(Keys.POTION_EFFECTS).get();
                        effects.clear();
                        player.offer(Keys.POTION_EFFECTS, effects);
                        player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, TextStyles.BOLD, "Glow Disabled"));
                    }

                }
            } else {
                PotionEffectData effects = player.getOrCreate(PotionEffectData.class).get();
                effects.addElement(glowPot);
                player.offer(effects);
                player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.GREEN, TextStyles.BOLD, "Glow Enabled"));
            }
        }
        return CommandResult.success();
    }
}
@@ -335,114 +335,44 @@
 ata.
-key.Keys;%0Aimport org.spongepowered.api.entity.living.player.Player;%0Aimport org.spongepowered.api.text.Text
+manipulator.mutable.PotionEffectData
 ;%0Aim
@@ -424,16 +424,21 @@
 onEffect
+Types
 ;%0Aimport
@@ -465,38 +465,34 @@
 pi.e
-ffect.potion.PotionEffectTypes
+ntity.living.player.Player
 ;%0Aim
@@ -522,49 +522,17 @@
 api.
-data.manipulator.mutable.PotionEffectData
+text.Text
 ;%0Aim
@@ -732,31 +732,8 @@
 Pot;
-%0Aimport java.util.List;
 %0A%0Apu
@@ -991,230 +991,143 @@
     
-if (player.get(Keys.POTION_EFFECTS).isPresent()) %7B%0A                List%3CPotionEffect%3E potionEffects = player.get(Keys.POTION_EFFECTS).get();%0A                for (PotionEffect pot : potionEffects) %7B%0A                    if (
+PotionEffectData effects = player.getOrCreate(PotionEffectData.class).get();%0A            if (effects.asList().stream().anyMatch(pot -%3E 
 pot.
@@ -1170,16 +1170,17 @@
 LOWING))
+)
  %7B%0A     
@@ -1194,133 +1194,83 @@
     
-        List%3CPotionEffect%3E effects = player.get(Keys.POTION_EFFECTS).get();%0A                        effects.clear();%0A        
+effects.removeAll(pot -%3E pot.getType().equals(PotionEffectTypes.GLOWING));%0A
     
@@ -1298,29 +1298,8 @@
 fer(
-Keys.POTION_EFFECTS, 
 effe
@@ -1300,32 +1300,24 @@
 r(effects);%0A
-        
             
@@ -1437,150 +1437,16 @@
     
-        %7D%0A%0A                %7D%0A            %7D else %7B%0A                PotionEffectData effects = player.getOrCreate(PotionEffectData.class).get();
+%7D else %7B
 %0A   

Fix toggling glow off removing all potion effects