package in.twizmwaz.cardinal.module.modules.sound;

import in.twizmwaz.cardinal.event.MatchEndEvent;
import in.twizmwaz.cardinal.event.objective.ObjectiveCompleteEvent;
import in.twizmwaz.cardinal.module.Module;
import in.twizmwaz.cardinal.settings.Settings;
import in.twizmwaz.cardinal.util.Teams;
import org.bukkit.Bukkit;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;

public class SoundModule implements Module {

    protected SoundModule() {
    }

    @Override
    public void unload() {
        HandlerList.unregisterAll(this);
    }

    @EventHandler
    public void onObjectiveComplete(ObjectiveCompleteEvent event) {
        for (Player player : Bukkit.getOnlinePlayers()) {
            if (Settings.getSettingByName("Sounds") != null && Settings.getSettingByName("Sounds").getValueByPlayer(player).getValue().equalsIgnoreCase("on")) {
                player.playSound(player.getLocation(), Sound.PORTAL_TRAVEL, 1, 2);
            }
        }
    }

    @EventHandler
    public void onMatchEnd(MatchEndEvent event) {
        for (Player player : Bukkit.getOnlinePlayers()) {
            if (Settings.getSettingByName("Sounds") != null && Settings.getSettingByName("Sounds").getValueByPlayer(player).getValue().equalsIgnoreCase("on")) {
                if (Teams.getTeamByPlayer(player) == event.getTeam()) {
                    player.playSound(player.getLocation(), Sound.WITHER_DEATH, 1, 1);
                } else {
                    player.playSound(player.getLocation(), Sound.WITHER_SPAWN, 1, 1);
                }
            }
        }
    }

}

@@ -205,16 +205,221 @@
 Module;%0A
+import in.twizmwaz.cardinal.module.modules.cores.CoreObjective;%0Aimport in.twizmwaz.cardinal.module.modules.destroyable.DestroyableObjective;%0Aimport in.twizmwaz.cardinal.module.modules.wools.WoolObjective;%0A
 import i
@@ -457,16 +457,16 @@
 ttings;%0A
-
 import i
@@ -1126,32 +1126,473 @@
 reCase(%22on%22)) %7B%0A
+                if (Teams.getTeamByPlayer(player).get().isObserver() %7C%7C%0A                        (event.getObjective() instanceof WoolObjective && Teams.getTeamByPlayer(player).get().equals(event.getObjective().getTeam())) %7C%7C%0A                        ((event.getObjective() instanceof CoreObjective %7C%7C event.getObjective() instanceof DestroyableObjective) && !Teams.getTeamByPlayer(player).get().equals(event.getObjective().getTeam()))) %7B%0A    
                 
@@ -1655,15 +1655,153 @@
 EL, 
-1
+0.7f
 , 2
+f
 );%0A
+                %7D else %7B%0A                    player.playSound(player.getLocation(), Sound.BLAZE_DEATH, 0.8f, 0.8f);%0A                %7D%0A
     

Fix objective completed sounds