package ru.alphach1337.detour.events;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.event.player.PlayerQuitEvent;
import ru.alphach1337.detour.managers.DetourManager;
import ru.alphach1337.detour.models.EventParticipant;
import ru.alphach1337.detour.sqlite.Database;

import java.util.ArrayList;
import java.util.UUID;

class Quit {
    Quit(PlayerQuitEvent event) {
        DetourManager detourManager = DetourManager.getInstance();
        Database database = Database.getInstance();

        boolean allowOffline = detourManager.getConfig().getBoolean("allowOffline");

        ArrayList<EventParticipant> players = database.getPlayers(detourManager.getEventId(), false, false);

//        for (int i = 0; i < players.size(); i++) {
//            if (event.getPlayer().getUniqueId().equals(players.get(i).getUUID())) {
//                if (allowOffline)) {
//                    Database.delete(players.get(i), "players");
//                    Database.delete(ignorePlayers.get(i), "players");
//                } else {
//                    Database.delete(players.get(i), "locations");
//                    Database.insertUuidAndLocation(players.get(i), event.getPlayer().getLocation(), "locations");
//                }
//            }
//            for (int j = 0; j < party.size(); j++) {
//                /*Log.info(event.getPlayer().getName());
//                Log.info(party.get(j));*/
//
//                if (event.getPlayer().getUniqueId().equals(UUID.fromString(party.get(j)))) {
//                    Database.delete(party.get(j), "party");
//
//                    for (String username : party) {
//                        Bukkit.getPlayer(UUID.fromString(username)).sendMessage(ChatColor.RED + "Игрок " + event.getPlayer().getName() + " вышел из группы");
//                    }
//                }
//            }
//
//        }
    }
}

@@ -606,271 +606,13 @@
     
-ArrayList%3CEventParticipant%3E players = database.getPlayers(detourManager.getEventId(), false, false);%0A%0A//        for (int i = 0; i %3C players.size(); i++) %7B%0A//            if (event.getPlayer().getUniqueId().equals(players.get(i).getUUID())) %7B%0A//                
 if (
+!
 allo
@@ -620,23 +620,19 @@
 Offline)
-)
  %7B%0A
-// 
         
@@ -639,346 +639,89 @@
     
-       Database.delete(players.get(i), %22players%22);%0A//                    Database.delete(ignorePlay
+database.removePlayerFromEvent(detourManag
 er
-s
 .get
-(i), %22players%22);%0A//                %7D else %7B%0A//                    Database.delete(players.get(i), %22locations%22);%0A//                    Database.insertUuidAndLocation(players.get(i), event.getPlayer().getLocation(), %22locations%22);%0A//  
+EventId(), new EventParticipant(%0A
     
@@ -734,626 +734,96 @@
     
-%7D%0A//
       
-      %7D%0A//            for (int j = 0; j %3C party.size(); j++) %7B%0A//                /*Log.info(event.getPlayer().getName());%0A//                Log.info(party.get(j));*/%0A//%0A//                if (event.getPlayer().getUniqueId().equals(UUID.fromString(party.get(j)))) %7B%0A//                    Database.delete(party.get(j), %22party%22);%0A//%0A//                    for (String username : party) %7B%0A//                        Bukkit.getPlayer(UUID.fromString(username)).sendMessage(ChatColor.RED + %22%D0%98%D0%B3%D1%80%D0%BE%D0%BA %22 + event.getPlayer().getName() + %22 %D0%B2%D1%8B%D1%88%D0%B5%D0%BB %D0%B8%D0%B7 %D0%B3%D1%80%D1%83%D0%BF%D0%BF%D1%8B%22);%0A//                    %7D%0A//                %7D%0A//            %7D%0A//%0A//
+detourManager.getEventId(),%0A                    event.getPlayer()%0A            ));%0A
     

quit event