using System;
using System.Collections.Generic;
using System.Linq;
using GTANetworkAPI;
using Newtonsoft.Json;
using ReallifeGamemode.Server.Entities;
using ReallifeGamemode.Server.Extensions;
using ReallifeGamemode.Server.Services;
using ReallifeGamemode.Server.Util;
using ReallifeGamemode.Server.Managers;
using ReallifeGamemode.Server.Inventory.Interfaces;
using ReallifeGamemode.Server.Business;
using System.Text.RegularExpressions;
using ReallifeGamemode.Server.Classes;
using ReallifeGamemode.Server.Factions.Medic;
using ReallifeGamemode.Server.Models;
using ReallifeGamemode.Server.Job;
using ReallifeGamemode.Server.Finance;

/**
* @overview Life of German Reallife - Admin Commands (Admin.cs)
* @author VegaZ, hydrant, xSprite, balbo, kookroach
* @copyright (c) 2008 - 2018 Life of German
*/

namespace ReallifeGamemode.Server.Commands
{
    public class AdminCommands : Script
    {
        #region Test
        [Command("eat", "~m~Benutzung: ~s~/eat [Item]")]
        public void CmdAdminEat(Client player, string item)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.SUPPORTER) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            IItem iItem = InventoryManager.GetItemByName(item);

            if (iItem == null)
            {
                ChatService.SendMessage(player, "Dieses Essen existiert nicht.");
                return;
            }

            List<UserItem> itemList = player.GetUser().GetItems();
            UserItem eatItem = itemList.FirstOrDefault(i => i.ItemId == iItem.Id);

            if (eatItem == null)
            {
                ChatService.SendMessage(player, "Du hast dieses Item nicht");
                return;
            }

            if (iItem is IUsableItem usableItemObj)
            {
                usableItemObj.Use(eatItem);
            }
        }

        [Command("myvehicles")]
        public void CmdAdminMyVehicles(Client player)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }
            ChatService.SendMessage(player, "Deine Fahrzeuge: ");

            int userID = player.GetUser().Id;
            using (var loadData = new DatabaseContext())
            {
                foreach (UserVehicle v in loadData.UserVehicles)
                {
                    if (v.UserId == userID)
                    {
                        ChatService.SendMessage(player, "~b~" + v.Model);
                    }
                }
            }
        }

        //TODO
        [Command("fpay")]
        public void FPay(Client player, string receiver, int amount)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }
            using (var getFaction = new DatabaseContext())
            {
                Faction receiverUser = getFaction.Factions.FirstOrDefault(u => u.Name == receiver);

                if (receiverUser == null)
                {
                    ChatService.ErrorMessage(player, "Diese Fraktion existiert nicht");
                    return;
                }

                BankManager.TransferMoney(player.GetUser(), receiverUser, amount, "/FPAY");
            }
        }

        [Command("saveall")]
        public void SaveAll(Client player)
        {
            SaveManager.SaveAllOnSave();
        }

        [Command("hash")]
        public void CmdHash(Client player, string toHash)
        {
            string msg = $"{toHash} => {NAPI.Util.GetHashKey(toHash)}";
            NAPI.Util.ConsoleOutput(msg);
            ChatService.SendMessage(player, msg);
        }

        #endregion
        #region Support
        [Command("o", "~m~Benutzung: ~s~/o [Nachricht]", GreedyArg = true)]
        public void CmdAdminO(Client player, string message)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.SUPPORTER) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }
            message = Regex.Replace(message, "(~[a-zA-Z]~)|(!{(.*)})", "");
            message = Regex.Replace(message, "#([0-9A-Fa-f]{6})", m => "!{" + m.Groups[0].Value + "}");

            string publicMessage = "~b~(( " + player.GetUser().AdminLevel.GetName() + " " + player.Name + ": " + message + " ~b~))";
            ChatService.Broadcast(publicMessage);
        }

        [Command("team", "~m~Benutzung: ~s~/team")]
        public void CmdAdminTeam(Client player)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.SUPPORTER) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            ChatService.SendMessage(player, "Online Teammitglieder:");

            List<Client> playerlist = NAPI.Pools.GetAllPlayers().FindAll(c => c.GetUser()?.IsAdmin(AdminLevel.SUPPORTER) ?? false).OrderByDescending(c => c.GetUser().AdminLevel).ToList();
            foreach (Client currentPlayer in playerlist)
            {
                ChatService.SendMessage(player, currentPlayer.GetUser().AdminLevel.GetName() + " | " + currentPlayer.Name);
            }
        }

        [Command("dimension", "~m~Benutzung: ~s~/dimension")]
        public void CmdAdminDimension(Client player)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.SUPPORTER) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }
            ChatService.SendMessage(player, "Deine Dimension ist ~g~" + player.Dimension);
        }

        [Command("to", "~m~Benutzung: ~s~/to [Name]")]
        public void CmdAdminGoto(Client player, string name)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.SUPPORTER) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            Client target = ClientService.GetClientByNameOrId(name);

            if (target == null || !target.IsLoggedIn())
            {
                ChatService.PlayerNotFound(player);
                return;
            }
            //TODO: Als Supporter nur, wenn mit dem Ziel ein offenes Ticket besteht. Ansonsten kein Teleport
            if (player.IsInVehicle && player.VehicleSeat == -1)
            {
                player.Vehicle.Position = target.Position;
                NAPI.Entity.SetEntityVelocity(player.Vehicle, new Vector3());
            }
            else player.Position = target.Position;
        }

        [Command("position", "~m~Benutzung: ~s~/position")]
        public void CmdAdminShowPos(Client player)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.SUPPORTER) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            ChatService.SendMessage(player, "Position: X Y Z: " + player.Position);
        }

        [Command("gh", "~m~Benutzung: ~s~/gh [Name]")]
        public void CmdAdminGethere(Client player, string name)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.SUPPORTER) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            Client target = ClientService.GetClientByNameOrId(name);

            if (target == null || !target.IsLoggedIn())
            {
                ChatService.PlayerNotFound(player);
                return;
            }

            if (target.IsInVehicle && target.VehicleSeat == -1)
            {
                target.Vehicle.Position = player.Position;
                NAPI.Entity.SetEntityVelocity(target.Vehicle, new Vector3());
            }
            else target.Position = player.Position;
            ChatService.SendMessage(target, "Du wurdest von " + player.Name + " teleportiert.");
        }

        [Command("aw", "~m~Benutzung: ~s~/aw [Spieler] [Nachricht]", GreedyArg = true)]
        public void CmdAdminMsg(Client player, string name, string msg)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.SUPPORTER) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            Client target = ClientService.GetClientByNameOrId(name);
            if (target == null || !target.IsLoggedIn())
            {
                ChatService.PlayerNotFound(player);
                return;
            }

            if (target == player)
            {
                ChatService.ErrorMessage(player, "Du kannst dir nicht selber zuflüstern");
                return;
            }

            msg = Regex.Replace(msg, "(~[a-zA-Z]~)|(!{(.*)})", "");

            ChatService.SendMessage(player, "~y~PM an " + target.Name + ": " + msg + " ");
            string Message = "~y~PM von " + player.GetUser().AdminLevel.GetName() + " " + player.Name + ": " + msg + "";
            ChatService.SendMessage(target, Message);
        }

        [Command("factionlist", "~m~Benutzung: ~s~/factionlist")]
        public void CmdAdminFactionlist(Client player)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.SUPPORTER) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            using (var dbContext = new DatabaseContext())
            {
                ChatService.SendMessage(player, "~m~__________ ~s~Fraktionen ~m~__________");
                foreach (Entities.Faction f in dbContext.Factions)
                {
                    ChatService.SendMessage(player, f.Id.ToString().PadRight(3) + " | " + f.Name);
                }
            }
        }

        [Command("businesslist", "~m~Benutzung: ~s~/businesslist")]
        public void CmdAdminBusinessList(Client player)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.SUPPORTER) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            ChatService.SendMessage(player, "~m~__________ ~s~Businesses ~m~__________");
            foreach (BusinessBase b in BusinessManager.Businesses.OrderBy(b => b.Id))
            {
                ChatService.SendMessage(player, b.Id.ToString().PadRight(3) + " | " + b.Name + (b is CarDealerBusinessBase ? " | Autohaus" : ""));
            }
        }

        [Command("joblist", "~m~Benutzung: ~s~/joblist")]
        public void CmdAdminJoblist(Client player)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.SUPPORTER) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            ChatService.SendMessage(player, "~m~__________ ~s~Jobs ~m~__________");
            foreach (JobBase job in JobManager.GetJobs())
            {
                ChatService.SendMessage(player, job.Id.ToString().PadRight(3) + " | " + job.Name);
            }
        }
        #endregion

        #region ALevel1
        [Command("a", "~m~Benutzung: ~s~/a [Nachricht]", GreedyArg = true)]
        public void CmdAdminA(Client player, string message)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            message = Regex.Replace(message, "(~[a-zA-Z]~)|(!{(.*)})", "");

            ChatService.BroadcastAdmin("~r~[ADMINCHAT]~s~ " + player.GetUser().AdminLevel.GetName() + " " + player.Name + "~w~: " + message, AdminLevel.ADMIN);
        }

        [Command("freeze", "~m~Benutzung: ~s~/freeze [Spieler]")]
        public void CmdAdminFreeze(Client player, string targetname)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            Client target = ClientService.GetClientByNameOrId(targetname);
            if (target == null || !target.IsLoggedIn())
            {
                ChatService.PlayerNotFound(player);
                return;
            }
            ChatService.SendMessage(player, "Du hast ~y~" + target.Name + " ~s~gefreezed.");
            ChatService.SendMessage(target, "Du wurdest von ~y~" + player.Name + "~s~ gefreezed.");
            target.Freeze(true);
        }

        [Command("unfreeze", "~m~Benutzung: ~s~/unfreeze [Spieler]")]
        public void CmdAdminUnfreeze(Client player, string targetname)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            Client target = ClientService.GetClientByNameOrId(targetname);
            if (target == null || !target.IsLoggedIn())
            {
                ChatService.PlayerNotFound(player);
                return;
            }
            ChatService.SendMessage(player, "Du hast ~y~" + target.Name + " ~s~unfreezed.");
            ChatService.SendMessage(target, "Du wurdest von ~y~" + player.Name + "~s~ unfreezed.");
            target.Freeze(false);
        }

        [Command("gotolist", "~m~Benutzung: ~s~/gotolist")]         //TODO Als Browser anzeigeN??
        public void CmdAdminGotoList(Client player)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }
            var gotoString = "";
            using (var dbContext = new DatabaseContext())
            {
                foreach (GotoPoint point in dbContext.GotoPoints)
                {
                    if (point.Active)
                    {
                        gotoString += point.Description + ", ";
                    }
                }
            }
            ChatService.SendMessage(player, gotoString);
        }

        [Command("mark", "~m~Benutzung: ~s~/mark")]
        public void CmdAdminMark(Client player)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }
            player.SetData("mark", player.Position);
            player.SendNotification("~y~Mark ~s~gespeichert", true);
        }

        [Command("gotomark", "~m~Benutzung: ~s~/gotomark")]
        public void CmdAdminGotoMark(Client player)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            if (!player.HasData("mark"))
            {
                ChatService.ErrorMessage(player, "Du hast noch keine Markierung gesetzt. ~m~(/mark)");
                return;
            }

            if (player.IsInVehicle && player.VehicleSeat == -1) player.Vehicle.Position = player.GetData("mark");
            else player.Position = player.GetData("mark");
        }

        [Command("clearchat", "~m~Benutzung: ~s~/clearchat")]
        public void CmdAdminClearchat(Client player)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            for (int i = 0; i < 20; i++)
            {
                ChatService.Broadcast("");
            }
        }

        [Command("up", "~m~Benutzung: ~s~/up [Wert]")]
        public void CmdAdminUp(Client player, int value = 5)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            if (player.IsInVehicle)
            {
                player.Vehicle.Position = new Vector3(player.Vehicle.Position.X, player.Vehicle.Position.Y, player.Vehicle.Position.Z + value);
            }
            else
            {
                player.Position = new Vector3(player.Position.X, player.Position.Y, player.Position.Z + value);
            }
        }

        [Command("dn", "~m~Benutzung: ~s~/dn [Wert]")]
        public void CmdAdminDn(Client player, int value = 5)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            if (player.IsInVehicle)
            {
                player.Vehicle.Position = new Vector3(player.Vehicle.Position.X, player.Vehicle.Position.Y, player.Vehicle.Position.Z - value);
            }
            else
            {
                player.Position = new Vector3(player.Position.X, player.Position.Y, player.Position.Z - value);
            }
        }

        [Command("rt", "~m~Benutzung: ~s~/rt [Wert]")]
        public void CmdAdminRt(Client player, int value = 5)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            float playerHeading = player.Heading;

            if (playerHeading < 45 || playerHeading >= 315)
            {
                Vector3 playerPosition = new Vector3(player.Position.X + value, player.Position.Y, player.Position.Z);
                if (player.IsInVehicle && player.VehicleSeat == -1) player.Vehicle.Position = playerPosition;
                else player.Position = playerPosition;
            }
            else if (playerHeading < 315 && playerHeading >= 225)
            {
                Vector3 playerPosition = new Vector3(player.Position.X, player.Position.Y - value, player.Position.Z);
                if (player.IsInVehicle && player.VehicleSeat == -1) player.Vehicle.Position = playerPosition;
                else player.Position = playerPosition;
            }
            else if (playerHeading >= 135 && playerHeading < 225)
            {
                Vector3 playerPosition = new Vector3(player.Position.X - value, player.Position.Y, player.Position.Z);
                if (player.IsInVehicle && player.VehicleSeat == -1) player.Vehicle.Position = playerPosition;
                else player.Position = playerPosition;
            }
            else if (playerHeading >= 45 && playerHeading < 135)
            {
                Vector3 playerPosition = new Vector3(player.Position.X, player.Position.Y + value, player.Position.Z);
                if (player.IsInVehicle && player.VehicleSeat == -1) player.Vehicle.Position = playerPosition;
                else player.Position = playerPosition;
            }
        }

        [Command("lt", "~m~Benutzung: ~s~/lt [Wert]")]
        public void CmdAdminLt(Client player, int value = 5)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            float playerHeading = player.Heading;

            if (playerHeading < 45 || playerHeading >= 315)
            {
                Vector3 playerPosition = new Vector3(player.Position.X - value, player.Position.Y, player.Position.Z);
                if (player.IsInVehicle && player.VehicleSeat == -1) player.Vehicle.Position = playerPosition;
                else player.Position = playerPosition;
            }
            else if (playerHeading < 315 && playerHeading >= 225)
            {
                Vector3 playerPosition = new Vector3(player.Position.X, player.Position.Y + value, player.Position.Z);
                if (player.IsInVehicle && player.VehicleSeat == -1) player.Vehicle.Position = playerPosition;
                else player.Position = playerPosition;
            }
            else if (playerHeading >= 135 && playerHeading < 225)
            {
                Vector3 playerPosition = new Vector3(player.Position.X + value, player.Position.Y, player.Position.Z);
                if (player.IsInVehicle && player.VehicleSeat == -1) player.Vehicle.Position = playerPosition;
                else player.Position = playerPosition;
            }
            else if (playerHeading >= 45 && playerHeading < 135)
            {
                Vector3 playerPosition = new Vector3(player.Position.X, player.Position.Y - value, player.Position.Z);
                if (player.IsInVehicle && player.VehicleSeat == -1) player.Vehicle.Position = playerPosition;
                else player.Position = playerPosition;
            }
        }

        [Command("setdimension", "~m~Benutzung: ~s~/setdimension [Spieler] [Dimension]")]
        public void CmdAdminSetDimension(Client player, string targetname, uint dimension)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            Client target = ClientService.GetClientByNameOrId(targetname);
            if (target == null || !target.IsLoggedIn())
            {
                ChatService.PlayerNotFound(player);
                return;
            }
            target.Dimension = dimension;
            ChatService.SendMessage(target, "~s~Deine Dimension wurde auf ~g~" + dimension + "~s~ geändert.");
            ChatService.SendMessage(player, "~s~Die Dimension von ~y~" + target.Name + " ~s~wurde auf ~g~" + dimension + "~s~ geändert.");
        }

        [Command("kick", "~m~Benutzung: ~s~/kick [Player] [Grund]", GreedyArg = true)]
        public void CmdAdminKick(Client player, string targetname, string reason)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            Client target = ClientService.GetClientByNameOrId(targetname);
            if (target == null || !target.IsLoggedIn())
            {
                ChatService.PlayerNotFound(player);
                return;
            }

            string targetPlayername = NAPI.Player.GetPlayerName(target);
            string adminPlayername = NAPI.Player.GetPlayerName(player);

            ChatService.SendMessage(target, "~r~KICKINFO: ~w~Du wurdest von " + adminPlayername + " vom Server gekickt: " + reason);
            target.Kick();
            ChatService.Broadcast("~y~INFO: ~w~" + targetPlayername + " wurde von " + player.GetUser().AdminLevel.GetName() + " " + adminPlayername + " gekickt: " + reason);
        }

        [Command("ip", "~m~Benutzung: ~s~/ip [Spieler]")]
        public void CmdAdminIp(Client player, string targetname)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            Client target = ClientService.GetClientByNameOrId(targetname);
            if (target == null || !target.IsLoggedIn())
            {
                ChatService.PlayerNotFound(player);
                return;
            }
            ChatService.SendMessage(player, "IP von ~y~" + NAPI.Player.GetPlayerName(target) + ": ~g~" + target.Address);
        }

        [Command("ban", "~m~Benutzung: ~s~/ban [User] [Zeit in Minuten(0 für Permanent)] [Grund] ", GreedyArg = true)]
        public void CmdAdminBan(Client admin, string user, int mins, string reason)
        {
            if (!admin.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
            {
                ChatService.NotAuthorized(admin);
                return;
            }

            Client target = ClientService.GetClientByNameOrId(user);

            if (target == null || !target.IsLoggedIn())
            {
                ChatService.PlayerNotFound(admin);
                return;
            }

            reason = Regex.Replace(reason, "(~[a-zA-Z]~)|(!{(.*)})", "");

            target.GetUser().BanPlayer(admin, reason, mins);
        }

        [Command("unban", "~m~Benutzung: ~s~/unban [Name] ")]
        public void CmdAdminUnban(Client admin, string userName)
        {
            if (!admin.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
            {
                ChatService.NotAuthorized(admin);
                return;
            }

            User user;

            using (var dbContext = new DatabaseContext())
            {
                user = dbContext.Users.FirstOrDefault(u => u.Name == userName);
                if (user == null)
                {
                    ChatService.ErrorMessage(admin, "Dieser Spieler existiert nicht");
                    return;
                }

                if (user.BanId == null)
                {
                    ChatService.ErrorMessage(admin, "Dieser Spieler ist nicht gebannt");
                    return;
                }

                Ban ban = dbContext.Bans.FirstOrDefault(b => b.Id == user.BanId);
                if (ban == null)
                {
                    ChatService.ErrorMessage(admin, "Dieser Spieler ist nicht gebannt");
                    return;
                }

                if (ban.Applied == ban.UntilDateTime)
                {
                    user.UnbanPlayer();
                }
                else
                {
                    int currentTimestamp = (int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
                    if (ban.UntilDateTime < currentTimestamp)
                    {
                        ChatService.ErrorMessage(admin, "Dieser Spieler ist nicht gebannt");
                        return;
                    }
                }
                user.UnbanPlayer();
            }

            string message = "~b~[ADMIN] ~s~Der Spieler ~y~" + user.Name + " ~s~wurde von ~y~" + admin.Name + " ~s~entbannt.";
            ChatService.BroadcastAdmin(message, AdminLevel.ADMIN);
        }

        [Command("goto", "~m~Benutzung: ~s~/goto [Ort]")]
        public void CmdAdminGotoPoint(Client player, string location)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }
            using (var dbContext = new DatabaseContext())
            {
                GotoPoint p = dbContext.GotoPoints.FirstOrDefault(x => x.Description == location);

                if (p == null)
                {
                    ChatService.ErrorMessage(player, "Dieser Goto-Punkt existiert nicht");
                    return;
                }

                if (player.IsInVehicle && player.VehicleSeat == -1) player.Vehicle.Position = new Vector3(p.X, p.Y, p.Z);
                else player.Position = new Vector3(p.X, p.Y, p.Z);

            }
        }

        [Command("spec", "~m~Benutzung: ~s~/spec [Player]")]
        public void CmdAdminSpectate(Client player, string name)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }
            Client target = ClientService.GetClientByNameOrId(name);
            if (target == null || !target.IsLoggedIn())
            {
                ChatService.PlayerNotFound(player);
                return;
            }
            if (target == player)
            {
                ChatService.ErrorMessage(player, "Du kannst dich nicht selber spectaten");
                return;
            }

            bool spec = player.GetData("spec");

            if (spec == false)
            {
                NAPI.Player.SetPlayerToSpectatePlayer(player, target);
                player.SetData("spec", true);
            }
            else
            {
                NAPI.Player.UnspectatePlayer(player);
                player.SetData("spec", false);
            }

        }

        [Command("slap", "~m~Benutzung: ~s~/slap [Spieler] (Höhe)")]
        public void CmdAdminSlap(Client player, string name, int wert = 5)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            Client target = ClientService.GetClientByNameOrId(name);
            if (target == null || !target.IsLoggedIn())
            {
                ChatService.PlayerNotFound(player);
                return;
            }

            Vector3 oldPos = target.Position;

            target.Position = new Vector3(oldPos.X, oldPos.Y, oldPos.Z + wert);
            ChatService.SendMessage(player, "Du hast " + target.Name + " geslappt. Höhe: " + wert + "");
        }

        [Command("takeweapon", "~m~Benutzung: ~s~/takeweapon [Spieler]")]
        public void CmdAdminTakeWeapon(Client player, string name)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }
            Client target = ClientService.GetClientByNameOrId(name);
            if (target == null || !target.IsLoggedIn())
            {
                ChatService.PlayerNotFound(player);
                return;
            }
            target.RemoveAllWeapons();
            ChatService.SendMessage(target, "~b~Deine Waffen wurden dir von " + player.Name + "(Admin) abgenommen");
            ChatService.SendMessage(player, "~b~Dem Spieler " + target.Name + " wurden erfolgreich alle Waffen abgenommen ");
        }

        [Command("tov", "~m~Benutzung: ~s~/tov [Fahrzeug ID]")]
        public void CmdAdminTov(Client player, int vehid)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            Vehicle v = VehicleManager.GetVehicleFromId(vehid);
            if (v == null)
            {
                ChatService.ErrorMessage(player, "Dieses Fahrzeug existiert nicht");
                return;
            }

            player.Position = v.Position.Add(new Vector3(0, 0, 2));
        }

        [Command("ghv", "~m~Benutzung: ~s~/ghv [Fahrzeug ID]")]
        public void CmdAdminGhv(Client player, int vehid)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            Vehicle v = VehicleManager.GetVehicleFromId(vehid);
            if (v == null)
            {
                ChatService.ErrorMessage(player, "Dieses Fahrzeug existiert nicht");
                return;
            }

            v.Position = player.Position;
            player.Position = player.Position.Add(new Vector3(0, 0, 2));
        }
        #endregion
        #region ALevel2
        [Command("sethp", "~m~Benutzung: ~s~/sethp [Spieler] (Hp)")]
        public void CmdAdminSetHp(Client player, string name, int hp = 100)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN2) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            Client target = ClientService.GetClientByNameOrId(name);
            if (target == null || !target.IsLoggedIn())
            {
                ChatService.PlayerNotFound(player);
                return;
            }

            target.Health = hp;
            ChatService.SendMessage(target, "~b~Deine HP wurden von " + player.Name + " auf " + hp + " gesetzt.");
            ChatService.SendMessage(player, "~b~Du hast die HP von " + target.Name + " auf " + hp + " gesetzt.");
        }

        [Command("clothes", "~m~Benutzung: ~s~/clothes [Spieler] [Component ID] [Drawable] (Textur)")]
        public void CmdAdminClothes(Client player, string name, int component, int drawable, int texture = 0)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN2) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            Client target = ClientService.GetClientByNameOrId(name);
            if (target == null || !target.IsLoggedIn())
            {
                ChatService.PlayerNotFound(player);
                return;
            }

            using (var dbContext = new DatabaseContext())
            {
                User user = target.GetUser(dbContext);
                bool duty = user.GetData<bool>("duty");
                CharacterCloth cloth = dbContext.CharacterClothes.Where(c => c.UserId == user.Id && c.SlotId == component && c.SlotType == 0 && c.Duty == duty).FirstOrDefault();
                if (cloth == null)
                {
                    cloth = new CharacterCloth()
                    {
                        Duty = duty,
                        ClothId = drawable,
                        SlotId = component,
                        SlotType = 0,
                        Texture = texture,
                        UserId = user.Id,
                    };
                    dbContext.CharacterClothes.Add(cloth);
                }
                else
                {
                    cloth.ClothId = drawable;
                    cloth.Texture = texture;
                }
                dbContext.SaveChanges();
                target.SetClothes(component, drawable, texture);
            }
        }

        [Command("props", "~m~Benutzung: ~s~/props [Spieler] [Component ID] [Drawable] (Textur)")]
        public void CmdAdminProps(Client player, string name, int slot, int component, int texture = 0)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN2) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            Client target = ClientService.GetClientByNameOrId(name);
            if (target == null || !target.IsLoggedIn())
            {
                ChatService.PlayerNotFound(player);
                return;
            }

            if (component == -1)
            {
                target.ClearAccessory(slot);
                return;
            }
            target.SetAccessories(slot, component, texture);
        }

        [Command("gotox", "~m~Benutzung: ~s~/gotox [X] [Y] [Z]")]
        public void CmdAdminGotoxyz(Client player, float x, float y, float z)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN2) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }
            if (player.IsInVehicle && player.VehicleSeat == -1) player.Vehicle.Position = new Vector3(x, y, z);
            else player.Position = new Vector3(x, y, z);
        }
        #endregion
        #region ALevel3

        [Command("veh", "~m~Benutzung: ~s~/veh [Fahrzeug] (Farbe 1) (Farbe 2)")]
        public void CmdAdminVeh(Client player, string hash, int color1 = 111, int color2 = 111)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN3) ?? true)
            //TODO: Bestimmte Autos nur ab Adminlevel 1337, "normale Fahrzeuge" schon ab Adminlevel 3.
            {
                ChatService.NotAuthorized(player);
                return;
            }

            if (player.IsInVehicle) // Man darf keine Autos erstellen, wenn man selbst in einem sitzt (verhindert Bugs)
            {
                ChatService.ErrorMessage(player, "Du sitzt momentan schon in einem Fahrzeug");
                return;
            }

            if (!uint.TryParse(hash, out uint uHash))
                uHash = NAPI.Util.GetHashKey(hash);

            if (!VehicleManager.IsValidHash(uHash))
            {
                ChatService.ErrorMessage(player, "Dieses Fahrzeug existiert nicht");
                return;
            }

            Vehicle v = NAPI.Vehicle.CreateVehicle(uHash, player.Position, player.Rotation.Z, color1, color2, engine: false);
            VehicleStreaming.SetEngineState(v, true);
            VehicleStreaming.SetLockStatus(v, false);
            player.SetIntoVehicle(v.Handle, -1);
        }

        [Command("fv", "~m~Benutzung: ~s~/fv")]
        public void CmdAdminFixveh(Client player)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN3) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            if (!player.IsInVehicle)
            {
                ChatService.ErrorMessage(player, "Du sitzt momentan nicht in einem Fahrzeug");
                return;
            }
            player.Vehicle.Repair();
        }

        [Command("vdestroy", "~m~Benutzung: ~s~/vdestroy (ID)")]
        public void CmdAdminVdestroy(Client player, int vid = -1)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN3) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            Vehicle targetVeh;

            if (vid == -1)
            {
                if (!player.IsInVehicle)
                {
                    ChatService.SendMessage(player, "~m~Benutzung: ~s~/vdestroy (ID)");
                    return;
                }
                targetVeh = player.Vehicle;
            }
            else
            {
                targetVeh = VehicleManager.GetVehicleFromId(vid);
                if (targetVeh == null)
                {
                    ChatService.ErrorMessage(player, "Dieses Fahrzeug existiert nicht");
                    return;
                }
            }

            ServerVehicle veh = VehicleManager.GetServerVehicleFromVehicle(targetVeh);
            if (veh != null)
            {
                ChatService.ErrorMessage(player, "Dieses Fahrzeug wird von einem Server-System benutzt: ~m~" + veh.GetType().Name);
                return;
            }

            VehicleManager.DeleteVehicle(targetVeh);
            targetVeh.Trailer?.Delete();
        }

        [Command("vlivery", "~m~Benutzung: ~s~/vlivery [Livery]")]
        public void CmdAdminVlivery(Client player, int livery)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN3) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            if (!player.IsInVehicle)
            {
                ChatService.ErrorMessage(player, "Du sitzt momentan nicht in einem Fahrzeug");
                return;
            }

            Vehicle playerVeh = player.Vehicle;

            playerVeh.Livery = livery;
        }

        [Command("vcolor", "~m~Benutzung: ~s~/vcolor [Farb-ID1] [Farb-ID2]")]
        public void CmdAdminColor(Client player, int color1, int color2)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN3) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            if (!player.IsInVehicle)
            {
                ChatService.ErrorMessage(player, "Du sitzt momentan in keinem Fahrzeug");
                return;
            }

            player.Vehicle.PrimaryColor = color1;
            player.Vehicle.SecondaryColor = color2;
            ChatService.SendMessage(player, "Farb-ID1 " + color1 + ", Farb-ID2 " + color2 + "");
        }

        [Command("giveweapon", "~m~Benutzung: ~s~/giveweapon [Spieler] [Waffe] [Munition]")]
        public void CmdAdminGiveweapon(Client player, string name, string hash, int ammo)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN3) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            if (ammo <= 0)
            {
                ChatService.ErrorMessage(player, "Es muss mindestens 1 Munition vergeben werden");
                return;
            }

            hash = hash.ToLower();

            Client target = ClientService.GetClientByNameOrId(name);
            if (target == null || !target.IsLoggedIn())
            {
                ChatService.PlayerNotFound(player);
                return;
            }

            if (!uint.TryParse(hash, out uint uHash))
            {
                if (hash.Contains("mk2") && !hash.Contains("_mk2")) hash = hash.Replace("mk2", "_mk2");
                uHash = NAPI.Util.GetHashKey($"weapon_{hash}");
            }

            if (!WeaponManager.IsValidHash(uHash))
            {
                ChatService.ErrorMessage(player, "Diese Waffe existiert nicht");
                return;
            }

            target.GiveWeapon((WeaponHash)uHash, ammo);
            ChatService.SendMessage(target, "~b~Du hast von " + player.Name + " eine/n " + hash + " mit einer Munition von " + ammo + " erhalten.");
            ChatService.SendMessage(player, "~b~Du hast " + target.Name + " eine/n " + hash + " mit einer Munition von " + ammo + " gegeben.");
        }

        [Command("arevive", "~m~Benutzung: ~s~/arevive [Spieler]")]
        public void CmdAdminRevive(Client player, string name)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN3) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            Client target = ClientService.GetClientByNameOrId(name);
            if (target == null || !target.IsLoggedIn())
            {
                ChatService.PlayerNotFound(player);
                return;
            }
            if (target.Health != 0)
            {
                ChatService.ErrorMessage(player, "Der Spieler ist nicht tot");
                return;
            }
            target.TriggerEvent("onPlayerRevived");
            target.SendNotification("Du wurdest von Admin ~y~" + player.Name + "~s~ wiederbelebt.");
            target.SetData("isDead", false);
            NAPI.Player.SpawnPlayer(target, target.Position);
            target.Health = 100;

            MedicTask task = Medic.ReviveTasks.FirstOrDefault(t => t.Victim == target.Name);
            Medic.RemoveTaskFromList(task);
        }

        [Command("setarmor", "~m~Benutzung: ~s~/setarmor [Spieler] (Armor)")]
        public void CmdAdminSetArmor(Client player, string name, int armor = 100)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN3) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            Client target = ClientService.GetClientByNameOrId(name);
            if (target == null || !target.IsLoggedIn())
            {
                ChatService.PlayerNotFound(player);
                return;
            }

            target.Armor = armor;
            ChatService.SendMessage(target, "~b~Deine Rüstung wurde von " + player.Name + " auf " + armor + " gesetzt.");
            ChatService.SendMessage(player, "~b~Du hast die Rüstung von " + target.Name + " auf " + armor + " gesetzt.");
        }
        #endregion
        #region ALevel1337
        [Command("sethandmoney", "~m~Benutzung: ~s~/sethandmoney [Target] [Geld]")]
        public void CmdAdminSetUserHandMoney(Client admin, string targetname, int amount)
        {
            if (!admin.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
            {
                ChatService.NotAuthorized(admin);
                return;
            }

            Client target = ClientService.GetClientByNameOrId(targetname);
            if (target == null || !target.IsLoggedIn())
            {
                ChatService.PlayerNotFound(target);
                return;
            }
            using (var context = new DatabaseContext())
            {
                var user = target.GetUser(context);
                user.Handmoney = amount;
                context.SaveChanges();
            }
            target.TriggerEvent("SERVER:SET_HANDMONEY", amount);
        }

        [Command("givehandmoney", "~m~Benutzung: ~s~/givehandmoney [Target] [Geld]")]
        public void CmdAdminGiveUserHandMoney(Client admin, string targetname, int amount)
        {
            if (!admin.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
            {
                ChatService.NotAuthorized(admin);
                return;
            }

            Client target = ClientService.GetClientByNameOrId(targetname);
            if (target == null || !target.IsLoggedIn())
            {
                ChatService.PlayerNotFound(target);
                return;
            }
            using (var context = new DatabaseContext())
            {
                var user = target.GetUser(context);
                user.Handmoney += amount;
                context.SaveChanges();
                target.TriggerEvent("SERVER:SET_HANDMONEY", user.Handmoney);
            }
        }

        [Command("quicksavemode", "~m~Benutzung: ~s~/quicksavemode [Modus]: ~g~blip, ~g~atm")]
        public void CmdAdminSetQuickSaveMode(Client player, string mode)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.SUPPORTER) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }
            player.SetData("quicksavemode", mode.ToLower());
        }

        [Command("giveitem", "~m~Benutzung: ~s~/giveitem [Target] [Item ID] [Anzahl]")]
        public void CmdAdminGiveItem(Client player, string targetname, int itemId, int amount)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            Client target = ClientService.GetClientByNameOrId(targetname);
            if (target == null || !target.IsLoggedIn())
            {
                ChatService.PlayerNotFound(player);
                return;
            }

            var invWeight = 0;

            using (var context = new DatabaseContext())
            {
                List<UserItem> userItems = context.UserItems.ToList().FindAll(i => i.UserId == target.GetUser().Id);
                foreach (var uItem in userItems)
                {
                    invWeight += uItem.Amount * InventoryManager.GetItemById(uItem.ItemId).Gewicht;
                }
            }

            if (invWeight + (amount * InventoryManager.GetItemById(itemId).Gewicht) > 40000)
            {
                ChatService.SendMessage(player, "~y~" + target.Name + " ~s~hat nicht mehr genug Platz in seinem Inventar.");
            }
            else
            {
                UserItem item = new UserItem() { ItemId = itemId, UserId = target.GetUser().Id, Amount = amount };
                InventoryManager.AddItemToInventory(target, item);
            }
        }

        [Command("inventory", "~m~Benutzung: ~s~/inventory [Spieler]")]
        public void CmdAdminGiveItem(Client player, string targetname)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            Client target = ClientService.GetClientByNameOrId(targetname);
            if (target == null || !target.IsLoggedIn())
            {
                ChatService.PlayerNotFound(player);
                return;
            }

            var user = target.GetUser();

            InventoryManager.GetUserItemsAsAdmin(player, user);
        }

        [Command("editmode", "~m~Benutzung: ~s~/editmode")]
        public void CmdAdminToggleEditMode(Client player)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            if (player.GetData("editmode") == false)
            {
                player.SetData("editmode", true);
                player.SendNotification("Edit-Mode ~g~aktiviert");
                player.TriggerEvent("toggleEditMode", true);
            }
            else
            {
                player.SetData("editmode", false);
                player.SendNotification("Edit-Mode ~r~deaktiviert");
                player.TriggerEvent("toggleEditMode", false);
            }

        }

        [Command("setbliptemplate", "~m~Benutzung: ~s~/setbliptemplate [byte COLOR] [byte ALPHA] [bool SHORTRANGE] [uint SPRITE] [float SCALE] [string NAME]", GreedyArg = true)]
        public void CmdAdminSetBlipTemplate(Client player, byte color, byte alpha, bool shortRange, uint sprite, float scale, string name)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            TempBlip newTempBlip = new TempBlip()
            {
                Color = color,
                Name = name,
                Transparency = alpha,
                ShortRange = shortRange,
                Sprite = sprite,
                Scale = scale,
            };

            NAPI.Data.SetWorldData("blipTemplate", newTempBlip);
        }

        [Command("vmod", "~m~Benutzung: ~s~/vmod [Slot] [Mod ID]")]
        public void CmdAdminVmod(Client player, int slot, int mod)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            if (!player.IsInVehicle)
            {
                ChatService.ErrorMessage(player, "Du sitzt momentan nicht in einem Fahrzeug");
                return;
            }

            player.Vehicle.SetMod(slot, mod);
        }

        [Command("aneon", "~m~Benutzung: ~s~/aneon [R][G][B]")]
        public void CmdAdminNeon(Client player, int r, int g, int b)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            if (!player.IsInVehicle)
            {
                ChatService.ErrorMessage(player, "Du sitzt momentan nicht in einem Fahrzeug");
                return;
            }

            Vehicle veh = NAPI.Player.GetPlayerVehicle(player);
            NAPI.Vehicle.SetVehicleNeonColor(veh, r, g, b);
            NAPI.Vehicle.SetVehicleNeonState(veh, true);
        }

        [Command("vehsmoke", "~m~Benutzung: ~s~/vehsmoke [R][G][B]")]
        public void CmdAdminVehSmoke(Client player, int r, int g, int b)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            if (!player.IsInVehicle)
            {
                ChatService.ErrorMessage(player, "Du sitzt momentan nicht in einem Fahrzeug");
                return;
            }

            Vehicle veh = NAPI.Player.GetPlayerVehicle(player);
            NAPI.Vehicle.SetVehicleTyreSmokeColor(veh, new Color(r, g, b));
        }

        [Command("ipl", "~m~Benutzung: ~s~/ipl [Load / Remove] [Name]")]
        public void CmdAdminIpl(Client player, string option, string name)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            option = option.ToLower();

            if (option == "load")
            {
                NAPI.World.RequestIpl(name);
                ChatService.SendMessage(player, "~g~Das IPL ~s~" + name + " ~g~wurde erfolgreich geladen");
            }
            else if (option == "remove")
            {
                NAPI.World.RemoveIpl(name);
                ChatService.SendMessage(player, "~g~Das IPL ~s~" + name + " ~g~wurde erfolgreich entladen");
            }
            else
            {
                ChatService.SendMessage(player, "~m~Benutzung: ~s~/ipl [Load / Remove] [Name]");
            }
        }

        [Command("rsethp", "~m~Benutzung: ~s~/rsethp [Radius] (Leben)")]
        public void CmdAdminRangeSetHP(Client player, float radius, int hp = 100)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }
            var peopleInRange = NAPI.Player.GetPlayersInRadiusOfPlayer(radius, player);

            foreach (var managedClient in peopleInRange)
            {
                if (!managedClient.IsLoggedIn()) return;
                managedClient.Health = hp;
                ChatService.SendMessage(managedClient, "~b~Admin " + player.Name + " hat im Radius von " + radius + " die HP auf " + hp + " gesetzt.");
            }
            ChatService.SendMessage(player, "~b~Das Leben von " + peopleInRange.Count + " Spielern wurde auf " + hp + " gesetzt.");
        }

        [Command("freekh", "~m~Benutzung: ~s~/freekh (Radius)")]
        public void CmdAdminFreekh(Client player, float radius = -1)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }
            var peopleInRange = radius == -1 ? NAPI.Pools.GetAllPlayers() : NAPI.Player.GetPlayersInRadiusOfPlayer(radius, player);
            int playerRevided = 0;

            string toPlayerChat = "~b~Admin " + player.Name + " hat alle Spieler wiederbelebt";
            string toPlayerNotification = "Du wurdest von Admin ~y~" + player.Name + "~s~ wiederbelebt.";

            foreach (var managedClient in peopleInRange)
            {
                if (!managedClient.IsLoggedIn()) return;
                if (!managedClient.HasData("isDead") || managedClient.GetData("isDead") == false) continue;
                playerRevided++;

                managedClient.TriggerEvent("onPlayerRevived");
                managedClient.SetData("isDead", false);
                managedClient.SendNotification(toPlayerNotification);
                ChatService.SendMessage(managedClient, toPlayerChat);

                NAPI.Player.SpawnPlayer(managedClient, managedClient.Position);
                managedClient.Health = 100;

                MedicTask task = Medic.ReviveTasks.FirstOrDefault(t => t.Victim == managedClient.Name);
                Medic.RemoveTaskFromList(task);
            }

            ChatService.SendMessage(player, "~b~Du hast " + playerRevided + " Spieler wiederbelebt.");
        }

        [Command("rsetarmor", "~m~Benutzung: ~s~/rsetarmor [Radius] (Armor)")]
        public void CmdAdminRangeSetArmor(Client player, float radius, int Armor = 100)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }
            var peopleInRange = NAPI.Player.GetPlayersInRadiusOfPlayer(radius, player);

            foreach (var managedClient in peopleInRange)
            {
                if (!managedClient.IsLoggedIn()) return;
                managedClient.Armor = Armor;
                ChatService.SendMessage(managedClient, "~b~Admin " + player.Name + " hat im Radius von " + radius + " die Rüstung auf " + Armor + " gesetzt.");
            }
            ChatService.SendMessage(player, "~b~Die Rüstung von " + peopleInRange.Count + " Spielern wurde auf " + Armor + " gesetzt.");
        }

        [Command("rgiveweapon", "~m~Benutzung: ~s~/rgiveweapon [Radius] [Waffe] [Munition]")]
        public void CmdAdminRangeGiveWeapon(Client player, float radius, string weapon, int munition)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            weapon = weapon.ToLower();

            if (!uint.TryParse(weapon, out uint uHash))
            {
                if (weapon.Contains("mk2") && !weapon.Contains("_mk2")) weapon = weapon.Replace("mk2", "_mk2");
                uHash = NAPI.Util.GetHashKey($"weapon_{weapon}");
            }

            if (!WeaponManager.IsValidHash(uHash))
            {
                ChatService.ErrorMessage(player, "Diese Waffe existiert nicht");
                return;
            }

            WeaponHash weaponHash = (WeaponHash)uHash;

            var peopleInRange = NAPI.Player.GetPlayersInRadiusOfPlayer(radius, player);

            foreach (var managedClient in peopleInRange)
            {
                if (!managedClient.IsLoggedIn()) return;
                managedClient.GiveWeapon(weaponHash, munition);
                ChatService.SendMessage(managedClient, "~b~Admin " + player.Name + " hat im Radius von " + radius + " eine/n " + weapon + " mit " + munition + " Munition vergeben.");
            }
            ChatService.SendMessage(player, "~b~Du hast " + peopleInRange.Count + " Spielern eine " + weapon + " mit " + munition + " Munition gegeben");
        }

        [Command("time", "~m~Benutzung: ~s~/time [Stunde] (Minuten) (Sekunden)")]
        public void CmdAdminTime(Client player, int hour, int min = 0, int sec = 0)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            if (hour > 23 || min > 59 || sec > 59)
            {
                ChatService.ErrorMessage(player, "Es wurde eine ungültige Zeit eingegeben");
                return;
            }

            if (hour == -1)
            {
                ChatService.SendMessage(player, "Es wird nun wieder die Echtzeit genutzt.");
                TimeManager.StartTimeManager();
                return;
            }

            string broadcastMsg = $"Serverzeit wurde auf {hour:D2}:{min:D2}:{sec:D2} gesetzt!";
            NAPI.Notification.SendNotificationToAll(broadcastMsg);
            TimeManager.PauseTimeManager();
            NAPI.World.SetTime(hour, min, sec);
            return;

        }

        [Command("ainvite", "~m~Benutzung: ~s~/ainvite [Name] [Fraktion]")]
        public void CmdAdminAinvite(Client player, string name, int faction)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            Client target = ClientService.GetClientByNameOrId(name);
            if (target == null || !target.IsLoggedIn())
            {
                ChatService.PlayerNotFound(player);
                return;
            }

            using (var dbContext = new DatabaseContext())
            {
                Entities.Faction f = dbContext.Factions.FirstOrDefault(x => x.Id == faction);
                if (f == null && faction != 0)
                {
                    ChatService.ErrorMessage(player, "Diese Fraktion existiert nicht (Liste: ~m~/factionlist~s~)");
                    return;
                }

                Entities.User u = target.GetUser(dbContext);

                if (faction != 0)
                {
                    u.FactionId = f.Id;
                    u.FactionRankId = dbContext.FactionRanks.
                        OrderBy(x => x.Order)
                        .FirstOrDefault(r => r.FactionId == f.Id)?.Id ?? null;

                    ChatService.SendMessage(player, "~b~[ADMIN]~s~ Du hast hast den Spieler ~y~" + target.Name + "~s~ administrativ in die Fraktion ~o~" + f.Name + "~s~ eingeladen.");
                    ChatService.SendMessage(target, "~b~[ADMIN]~s~ Du wurdest von ~y~" + player.Name + "~s~ administrativ in die Fraktion ~o~" + f.Name + "~s~ eingeladen.");
                }
                else
                {
                    u.FactionId = null;
                    u.FactionRankId = null;
                    ChatService.SendMessage(player, "~b~[ADMIN]~s~ Du hast hast den Spieler ~y~" + target.Name + "~s~ administrativ aus seiner Fraktion geworfen.");
                    ChatService.SendMessage(target, "~b~[ADMIN]~s~ Du wurdest von ~y~" + player.Name + "~s~ administrativ aus deiner Fraktion geworfen.");
                }

                u.FactionLeader = false;

                dbContext.SaveChanges();
            }
        }

        [Command("makeleader", "~m~Benutzung: ~s~/makeleader [Name] [Fraktion]")]
        public void CmdAdminMakeleader(Client player, string name, int faction)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            Client target = ClientService.GetClientByNameOrId(name);
            if (target == null || !target.IsLoggedIn())
            {
                ChatService.PlayerNotFound(player);
                return;
            }

            using (var dbContext = new DatabaseContext())
            {
                Entities.Faction f = dbContext.Factions.FirstOrDefault(x => x.Id == faction);
                if (f == null)
                {
                    ChatService.ErrorMessage(player, "Diese Fraktion existiert nicht (Liste: ~m~/factionlist~s~)");
                    return;
                }

                Entities.User u = target.GetUser(dbContext);

                u.FactionId = f.Id;
                u.FactionRankId = dbContext.FactionRanks.
                    OrderByDescending(x => x.Order)
                    .FirstOrDefault(r => r.FactionId == f.Id)?.Id ?? null;
                u.FactionLeader = true;

                ChatService.SendMessage(player, "~b~[ADMIN]~s~ Du hast hast den Spieler ~y~" + target.Name + "~s~ zum Leader der Fraktion ~o~" + f.Name + "~s~ ernannt.");
                ChatService.SendMessage(target, "~b~[ADMIN]~s~ Du wurdest von ~y~" + player.Name + "~s~ zum Leader der Fraktion ~o~" + f.Name + "~s~ ernannt.");

                dbContext.SaveChanges();
            }
        }

        [Command("save", "~m~Benutzung: ~s~/save [Typ = ~g~Blip~s~, ~g~Goto (X)~s~, ~r~Marker~s~, ~r~Ped~s~, ~r~Pickup~s~, ~r~TextLabel~s~, ~g~Vehicle~s~, ~g~FVehicle~s~, ~g~SVehicle (X)~s~, ~g~JVehicle (X)~s~] (Weitere Angaben) = (X)")]
        public void CmdAdminSave(Client player, string typ, string option1 = null, string option2 = null)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }
            switch (typ.ToLower())
            {
                case "blip":
                    player.TriggerEvent("saveBlip");
                    break;
                case "goto":
                    if (option1 == null)
                    {
                        ChatService.SendMessage(player, "Für Goto musst du einen dritten Parameter angeben. Beispiel: Ort des Goto-Punktes.");
                        return;
                    }
                    else
                    {
                        using (var dbContext = new DatabaseContext())
                        {
                            GotoPoint p = dbContext.GotoPoints.FirstOrDefault(x => x.Description == option1);
                            if (p == null)
                            {
                                SaveManager.SaveGotoPoint(player, option1);
                                player.SendNotification("Goto-Punkt ~g~" + option1 + "~s~ gespeichert.", true);
                            }
                            else
                            {
                                ChatService.SendMessage(player, "Einen Goto-Punkt mit dieser Bezeichnung gibt es schon!");
                            }
                        }

                    }

                    break;
                case "vehicle":
                    if (player.IsInVehicle)
                    {
                        Vehicle vehicle = player.Vehicle;
                        int playerSeat = player.VehicleSeat;
                        vehicle = SaveManager.SaveVehicleData(vehicle, (VehicleHash)vehicle.Model, vehicle.Position, vehicle.Heading, vehicle.NumberPlate,
                            Convert.ToByte(vehicle.PrimaryColor), Convert.ToByte(vehicle.SecondaryColor), vehicle.Locked);
                        player.SendNotification("Fahrzeug ~g~" + vehicle.DisplayName + "~s~ gespeichert.", true);
                        player.SetIntoVehicle(vehicle, playerSeat);
                    }
                    else ChatService.SendMessage(player, "~m~Du sitzt in keinem Fahrzeug!");
                    break;
                case "fvehicle":
                    if (player.IsInVehicle)
                    {
                        if (player.GetUser().Faction == null)
                        {
                            ChatService.SendMessage(player, "~m~Du bist in keiner Fraktion! Invite dich erst mit ~y~/ainvite");
                            return;
                        }
                        else
                        {
                            Vehicle vehicle = player.Vehicle;
                            int playerSeat = player.VehicleSeat;
                            vehicle = SaveManager.SaveFactionVehicleData(vehicle, (VehicleHash)vehicle.Model, vehicle.Position, vehicle.Heading, vehicle.NumberPlate,
                                vehicle.PrimaryColor, vehicle.SecondaryColor, vehicle.Locked, vehicle.EngineStatus, player.GetUser().FactionId.Value);
                            player.SendNotification("Fraktionsfahrzeug ~g~" + vehicle.DisplayName + "~s~ gespeichert.", true);
                            player.SetIntoVehicle(vehicle, playerSeat);
                        }
                    }
                    else ChatService.SendMessage(player, "~m~Du sitzt in keinem Fahrzeug!");
                    break;
                case "jvehicle":
                    if (player.IsInVehicle)
                    {
                        if (option1 == null)
                        {
                            ChatService.ErrorMessage(player, "Du musst eine JobID als Parameter angeben");
                            return;
                        }
                        else
                        {
                            if (!int.TryParse(option1, out int jobId))
                            {
                                ChatService.ErrorMessage(player, "Du musst eine gültige Zahl als JobID angeben");
                                return;
                            }

                            Vehicle vehicle = player.Vehicle;
                            vehicle = SaveManager.SaveJobVehicleData(vehicle, (VehicleHash)vehicle.Model, vehicle.Position, vehicle.Heading, vehicle.NumberPlate,
                                vehicle.PrimaryColor, vehicle.SecondaryColor, vehicle.Locked, vehicle.EngineStatus, jobId);
                            player.SendNotification("Jobfahrzeug ~g~" + vehicle.DisplayName + "~s~ gespeichert.", true);
                            player.SetIntoVehicle(vehicle, -1);
                        }
                    }
                    else ChatService.SendMessage(player, "~m~Du sitzt in keinem Fahrzeug!");
                    break;
                case "svehicle":
                    if (player.IsInVehicle)
                    {
                        if (option1 == null || option2 == null)
                        {
                            ChatService.SendMessage(player, "~m~Benutzung: ~s~/save SVehicle [Carshop Business ID] [Preis]");
                            return;
                        }

                        if (!int.TryParse(option1, out int businessId) || !int.TryParse(option2, out int price))
                        {
                            ChatService.SendMessage(player, "~m~Benutzung: ~s~/save SVehicle [Carshop Business ID] [Preis]");
                            return;
                        }

                        BusinessBase business = BusinessManager.GetBusiness(businessId);
                        if (business == null)
                        {
                            ChatService.ErrorMessage(player, "Dieses Business existiert nicht");
                            return;
                        }

                        if (!(business is CarDealerBusinessBase))
                        {
                            ChatService.ErrorMessage(player, "Dieses Business ist kein Fahrzeug-Business");
                            return;
                        }

                        Vehicle vehicle = player.Vehicle;
                        int playerSeat = player.VehicleSeat;
                        vehicle = SaveManager.SaveShopVehicleData(vehicle, (VehicleHash)vehicle.Model, vehicle.DisplayName, vehicle.Position, vehicle.Heading, vehicle.NumberPlate,
                            Convert.ToByte(vehicle.PrimaryColor), Convert.ToByte(vehicle.SecondaryColor), business, price);
                        player.SendNotification("Shopfahrzeug ~g~" + vehicle.DisplayName + "~s~ gespeichert.", true);
                        Vector3 oldPos = player.Position;
                        player.Position = new Vector3(oldPos.X, oldPos.Y, oldPos.Z + 2.5);
                    }
                    else ChatService.SendMessage(player, "~m~Du sitzt in keinem Fahrzeug!");
                    break;

            }
        }

        [Command("remove", "~m~Benutzung: ~s~/remove [Vehicle, Goto] [Option]")]
        public void CmdAdminRemove(Client player, string type, string option = "")
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            switch (type.ToLower())
            {
                case "vehicle":
                    if (!player.IsInVehicle)
                    {
                        ChatService.SendMessage(player, "~m~Du sitzt in keinem Fahrzeug!");
                        return;
                    }

                    ServerVehicle veh = player.Vehicle.GetServerVehicle();
                    if (veh == null)
                    {
                        ChatService.ErrorMessage(player, "Dieses Fahrzeug wird nicht von einem Server-System genutzt");
                        return;
                    }

                    if (option.ToLower() != "yes")
                    {
                        ChatService.SendMessage(player, "Bist du sicher, dass du folgendes Fahrzeug löschen willst: ~m~" + veh.ToString() + " ~s~?");
                        ChatService.SendMessage(player, "Falls ~g~Ja~s~, nutze ~y~/remove vehicle yes");
                        return;
                    }

                    using (var dbContext = new DatabaseContext())
                    {
                        VehicleManager.DeleteVehicle(player.Vehicle);
                        dbContext.ServerVehicles.Remove(veh);

                        dbContext.SaveChanges();
                    }
                    break;

                case "goto":
                    if (option == "")
                    {
                        ChatService.SendMessage(player, "~m~Benutzung: ~s~/remove [Goto] [Punkt]");
                        return;
                    }
                    if (!player.GetUser()?.IsAdmin(AdminLevel.PROJEKTLEITUNG) ?? true) //1338
                    {
                        ChatService.NotAuthorized(player);
                        return;
                    }
                    using (var dbContext = new DatabaseContext())
                    {
                        GotoPoint p = dbContext.GotoPoints.FirstOrDefault(x => x.Description == option);
                        if (p == null)
                        {
                            ChatService.ErrorMessage(player, "Dieser Goto-Punkt existiert nicht");
                            return;
                        }

                        dbContext.GotoPoints.Remove(p);
                        dbContext.SaveChanges();

                        player.SendNotification("Der Goto-Punkt ~r~" + p.Description + "~s~ wurde erfolgreich gelöscht.");
                    }
                    break;
            }
        }

        #region loadCommand
        [Command("load", "~m~Benutzung: ~s~/load [Typ = OnlineBunkers, ArcadiusBusinessCentre, MazeBankBuilding, LomBank, MazeBankWest, ClubWareHouse, SpecialLocations, GRHYacht, DHYacht, PYacht, AircraftCarrier, BridgeTC, BridgeTN, NorthYankton, ONeilsFarmB, ONeilsFarm, Morgue")]
        public void CmdAdminloadlocation(Client player, string typ)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }
            switch (typ)
            {
                case "OnlineBunkers":
                    NAPI.World.RequestIpl("gr_case10_bunkerclosed");
                    NAPI.World.RequestIpl("gr_case9_bunkerclosed");
                    NAPI.World.RequestIpl("gr_case3_bunkerclosed");
                    NAPI.World.RequestIpl("gr_case0_bunkerclosed");
                    NAPI.World.RequestIpl("gr_case1_bunkerclosed");
                    NAPI.World.RequestIpl("gr_case2_bunkerclosed");
                    NAPI.World.RequestIpl("gr_case5_bunkerclosed");
                    NAPI.World.RequestIpl("gr_case7_bunkerclosed");
                    NAPI.World.RequestIpl("gr_case11_bunkerclosed");
                    NAPI.World.RequestIpl("gr_case6_bunkerclosed");
                    NAPI.World.RequestIpl("gr_case11_bunkerclosed");
                    NAPI.World.RequestIpl("gr_case6_bunkerclosed");
                    NAPI.World.RequestIpl("gr_case4_bunkerclosed");
                    ChatService.SendMessage(player, "~y~ Online Bunkers~s~ erfolgreich geladen!");
                    break;
                case "ArcadiusBusinessCentre":
                    NAPI.World.RequestIpl("ex_dt1_02_office_02b");
                    NAPI.World.RequestIpl("ex_dt1_02_office_02c");
                    NAPI.World.RequestIpl("ex_dt1_02_office_02a");
                    NAPI.World.RequestIpl("ex_dt1_02_office_01a");
                    NAPI.World.RequestIpl("ex_dt1_02_office_01b");
                    NAPI.World.RequestIpl("ex_dt1_02_office_01c");
                    NAPI.World.RequestIpl("ex_dt1_02_office_03a");
                    NAPI.World.RequestIpl("ex_dt1_02_office_03b");
                    NAPI.World.RequestIpl("ex_dt1_02_office_03c");
                    NAPI.World.RequestIpl("imp_dt1_02_cargarage_a");
                    NAPI.World.RequestIpl("imp_dt1_02_cargarage_b");
                    NAPI.World.RequestIpl("imp_dt1_02_cargarage_c");
                    NAPI.World.RequestIpl("imp_dt1_02_modgarage");
                    ChatService.SendMessage(player, "~y~ Arcadius Business Centre~s~ erfolgreich geladen!");
                    break;
                case "MazeBankBuilding":
                    NAPI.World.RequestIpl("ex_dt1_11_office_02b");
                    NAPI.World.RequestIpl("ex_dt1_11_office_02c");
                    NAPI.World.RequestIpl("ex_dt1_11_office_02a");
                    NAPI.World.RequestIpl("ex_dt1_11_office_01a");
                    NAPI.World.RequestIpl("ex_dt1_11_office_01b");
                    NAPI.World.RequestIpl("ex_dt1_11_office_01c");
                    NAPI.World.RequestIpl("ex_dt1_11_office_03a");
                    NAPI.World.RequestIpl("ex_dt1_11_office_03b");
                    NAPI.World.RequestIpl("ex_dt1_11_office_03c");
                    NAPI.World.RequestIpl("imp_dt1_11_cargarage_a");
                    NAPI.World.RequestIpl("imp_dt1_11_cargarage_b");
                    NAPI.World.RequestIpl("imp_dt1_11_cargarage_c");
                    NAPI.World.RequestIpl("imp_dt1_11_modgarage");
                    ChatService.SendMessage(player, "~y~ Maze Bank Building~s~ erfolgreich geladen!");
                    break;
                case "LomBank":
                    NAPI.World.RequestIpl("ex_sm_13_office_02b");
                    NAPI.World.RequestIpl("ex_sm_13_office_02c");
                    NAPI.World.RequestIpl("ex_sm_13_office_02a");
                    NAPI.World.RequestIpl("ex_sm_13_office_01a");
                    NAPI.World.RequestIpl("ex_sm_13_office_01b");
                    NAPI.World.RequestIpl("ex_sm_13_office_01c");
                    NAPI.World.RequestIpl("ex_sm_13_office_03a");
                    NAPI.World.RequestIpl("ex_sm_13_office_03b");
                    NAPI.World.RequestIpl("ex_sm_13_office_03c");
                    NAPI.World.RequestIpl("imp_sm_13_cargarage_a");
                    NAPI.World.RequestIpl("imp_sm_13_cargarage_b");
                    NAPI.World.RequestIpl("imp_sm_13_cargarage_c");
                    NAPI.World.RequestIpl("imp_sm_13_modgarage");
                    ChatService.SendMessage(player, "~y~Lom Bank~s~ erfolgreich geladen!");
                    break;
                case "MazeBankWest":
                    NAPI.World.RequestIpl("ex_sm_15_office_02b");
                    NAPI.World.RequestIpl("ex_sm_15_office_02c");
                    NAPI.World.RequestIpl("ex_sm_15_office_02a");
                    NAPI.World.RequestIpl("ex_sm_15_office_01a");
                    NAPI.World.RequestIpl("ex_sm_15_office_01b");
                    NAPI.World.RequestIpl("ex_sm_15_office_01c");
                    NAPI.World.RequestIpl("ex_sm_15_office_03a");
                    NAPI.World.RequestIpl("ex_sm_15_office_03b");
                    NAPI.World.RequestIpl("ex_sm_15_office_03c");
                    NAPI.World.RequestIpl("imp_sm_15_cargarage_a");
                    NAPI.World.RequestIpl("imp_sm_15_cargarage_b");
                    NAPI.World.RequestIpl("imp_sm_15_cargarage_c");
                    NAPI.World.RequestIpl("imp_sm_15_modgarage");
                    ChatService.SendMessage(player, "~y~Maze Bank West~s~ erfolgreich geladen!");
                    break;
                case "ClubWareHouse":
                    NAPI.World.RequestIpl("bkr_biker_interior_placement_interior_0_biker_dlc_int_01_milo");
                    NAPI.World.RequestIpl("bkr_biker_interior_placement_interior_1_biker_dlc_int_02_milo");
                    NAPI.World.RequestIpl("bkr_biker_interior_placement_interior_2_biker_dlc_int_ware01_milo");
                    NAPI.World.RequestIpl("bkr_biker_interior_placement_interior_3_biker_dlc_int_ware02_milo");
                    NAPI.World.RequestIpl("bkr_biker_interior_placement_interior_4_biker_dlc_int_ware03_milo");
                    NAPI.World.RequestIpl("bkr_biker_interior_placement_interior_5_biker_dlc_int_ware04_milo");
                    NAPI.World.RequestIpl("bkr_biker_interior_placement_interior_6_biker_dlc_int_ware05_milo");
                    NAPI.World.RequestIpl("ex_exec_warehouse_placement_interior_1_int_warehouse_s_dlc_milo");
                    NAPI.World.RequestIpl("ex_exec_warehouse_placement_interior_0_int_warehouse_m_dlc_milo");
                    NAPI.World.RequestIpl("ex_exec_warehouse_placement_interior_2_int_warehouse_l_dlc_milo");
                    NAPI.World.RequestIpl("imp_impexp_interior_placement_interior_1_impexp_intwaremed_milo_");
                    NAPI.World.RequestIpl("bkr_bi_hw1_13_int");
                    ChatService.SendMessage(player, "~y~Clubs & Warehouses~s~ erfolgreich geladen!");
                    break;
                case "SpecialLocations":
                    NAPI.World.RequestIpl("cargoship");
                    NAPI.World.RequestIpl("sunkcargoship");
                    NAPI.World.RequestIpl("SUNK_SHIP_FIRE");
                    NAPI.World.RequestIpl("redCarpet");
                    NAPI.World.RequestIpl("DES_StiltHouse_imapend");
                    NAPI.World.RequestIpl("DES_stilthouse_rebuild");
                    NAPI.World.RequestIpl("FINBANK");
                    NAPI.World.RequestIpl("TrevorsMP");
                    NAPI.World.RequestIpl("TrevorsTrailerTidy");
                    NAPI.World.RequestIpl("SP1_10_real_interior");
                    NAPI.World.RequestIpl("refit_unload");
                    NAPI.World.RequestIpl("post_hiest_unload");
                    NAPI.World.RequestIpl("FIBlobby");
                    ChatService.SendMessage(player, "~y~Special Locations~s~ erfolgreich geladen!");
                    break;
                case "GRHYacht":
                    NAPI.World.RequestIpl("gr_heist_yacht2");
                    NAPI.World.RequestIpl("gr_heist_yacht2_bar");
                    NAPI.World.RequestIpl("gr_heist_yacht2_bedrm");
                    NAPI.World.RequestIpl("gr_heist_yacht2_bridge");
                    NAPI.World.RequestIpl("gr_heist_yacht2_enginrm");
                    NAPI.World.RequestIpl("gr_heist_yacht2_lounge");
                    ChatService.SendMessage(player, "~y~Gunrunning heist Yacht~s~ erfolgreich geladen!");
                    break;
                case "DHYacht":
                    NAPI.World.RequestIpl("hei_yacht_heist");
                    NAPI.World.RequestIpl("hei_yacht_heist_enginrm");
                    NAPI.World.RequestIpl("hei_yacht_heist_Lounge");
                    NAPI.World.RequestIpl("hei_yacht_heist_Bridge");
                    NAPI.World.RequestIpl("hei_yacht_heist_Bar");
                    NAPI.World.RequestIpl("hei_yacht_heist_Bedrm");
                    NAPI.World.RequestIpl("hei_yacht_heist_DistantLights");
                    NAPI.World.RequestIpl("hei_yacht_heist_LODLights");
                    ChatService.SendMessage(player, "~y~Dignity heist Yacht~s~ erfolgreich geladen!");
                    break;
                case "PYacht":
                    NAPI.World.RequestIpl("smboat");
                    NAPI.World.RequestIpl("smboat_lod");
                    ChatService.SendMessage(player, "~y~Party Yacht~s~ erfolgreich geladen!");
                    break;
                case "AircraftCarrier":
                    NAPI.World.RequestIpl("hei_carrier");
                    NAPI.World.RequestIpl("hei_carrier_DistantLights");
                    NAPI.World.RequestIpl("hei_Carrier_int1");
                    NAPI.World.RequestIpl("hei_Carrier_int2");
                    NAPI.World.RequestIpl("hei_Carrier_int3");
                    NAPI.World.RequestIpl("hei_Carrier_int4");
                    NAPI.World.RequestIpl("hei_Carrier_int5");
                    NAPI.World.RequestIpl("hei_Carrier_int6");
                    NAPI.World.RequestIpl("hei_carrier_LODLights");
                    ChatService.SendMessage(player, "~y~Aircraft Carrier~s~ erfolgreich geladen!");
                    break;
                case "BridgeTC":
                    NAPI.World.RequestIpl("canyonriver01_traincrash");
                    NAPI.World.RequestIpl("canyonriver01_traincrash");
                    ChatService.SendMessage(player, "~y~Bridge Train Crash~s~ erfolgreich geladen!");
                    break;
                case "BridgeTN":
                    NAPI.World.RequestIpl("canyonriver01");
                    NAPI.World.RequestIpl("railing_start");
                    ChatService.SendMessage(player, "~y~Bridge Train Normal~s~ erfolgreich geladen!");
                    break;
                case "NorthYankton":
                    NAPI.World.RequestIpl("prologue01");
                    NAPI.World.RequestIpl("prologue01c");
                    NAPI.World.RequestIpl("prologue01d");
                    NAPI.World.RequestIpl("prologue01e");
                    NAPI.World.RequestIpl("prologue01f");
                    NAPI.World.RequestIpl("prologue01g");
                    NAPI.World.RequestIpl("prologue01h");
                    NAPI.World.RequestIpl("prologue01i");
                    NAPI.World.RequestIpl("prologue01j");
                    NAPI.World.RequestIpl("prologue01k");
                    NAPI.World.RequestIpl("prologue01z");
                    NAPI.World.RequestIpl("prologue02");
                    NAPI.World.RequestIpl("prologue03");
                    NAPI.World.RequestIpl("prologue03b");
                    NAPI.World.RequestIpl("prologue03_grv_dug");
                    NAPI.World.RequestIpl("prologue_grv_torch");
                    NAPI.World.RequestIpl("prologue04");
                    NAPI.World.RequestIpl("prologue04b");
                    NAPI.World.RequestIpl("prologue04_cover");
                    NAPI.World.RequestIpl("des_protree_end");
                    NAPI.World.RequestIpl("des_protree_start");
                    NAPI.World.RequestIpl("prologue05");
                    NAPI.World.RequestIpl("prologue05b");
                    NAPI.World.RequestIpl("prologue06");
                    NAPI.World.RequestIpl("prologue06b");
                    NAPI.World.RequestIpl("prologue06_int");
                    NAPI.World.RequestIpl("prologue06_pannel");
                    NAPI.World.RequestIpl("plg_occl_00");
                    NAPI.World.RequestIpl("prologue_occl");
                    NAPI.World.RequestIpl("prologuerd");
                    NAPI.World.RequestIpl("prologuerdb");
                    ChatService.SendMessage(player, "~y~North Yankton~s~ erfolgreich geladen!");
                    break;
                case "ONeilsFarmB":
                    NAPI.World.RequestIpl("farmint");
                    NAPI.World.RequestIpl("farm_burnt");
                    NAPI.World.RequestIpl("farm_burnt_props");
                    NAPI.World.RequestIpl("des_farmhs_endimap");
                    NAPI.World.RequestIpl("des_farmhs_end_occl");
                    ChatService.SendMessage(player, "~y~ONeils Farm Burnt~s~ erfolgreich geladen!");
                    break;
                case "ONeilsFarm":
                    NAPI.World.RequestIpl("farm");
                    NAPI.World.RequestIpl("farm_props");
                    NAPI.World.RequestIpl("farm_int");
                    ChatService.SendMessage(player, "~y~ONeils Farm~s~ erfolgreich geladen!");
                    break;
                case "Morgue":
                    NAPI.World.RequestIpl("coronertrash");
                    NAPI.World.RequestIpl("Coroner_Int_On");
                    ChatService.SendMessage(player, "~y~Morgue~s~ erfolgreich geladen!");
                    break;
            }

        }
        #endregion

        //
        [Command("managefactionranks", "~m~Benutzung: ~s~/managefactionranks [Fraktions-ID]")]
        public void CmdFactionManageFactionRanks(Client player, int factionID)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            using (var context = new DatabaseContext())
            {
                Entities.Faction f = context.Factions.FirstOrDefault(id => id.Id == factionID);
                if (f == null)
                {
                    ChatService.ErrorMessage(player, "Diese Fraktion existiert nicht (Liste: ~m~/factionlist~s~)");
                    return;
                }

                List<FactionRank> factionRanks = context.FactionRanks.ToList().FindAll(r => r.FactionId == f.Id).OrderByDescending(o => o.Order).ToList();
                List<Rank> rankList = new List<Rank>();

                factionRanks.ForEach(r =>
                {
                    rankList.Add(new Rank
                    {
                        Id = r.Id,
                        Name = r.RankName
                    });
                });

                FactionRankHelper helper = new FactionRankHelper
                {
                    FactionId = f.Id,
                    Ranks = rankList
                };

                string json = JsonConvert.SerializeObject(helper, Formatting.None);
                player.TriggerEvent("manageFactionRanks", json);
            }
        }

        [Command("setweather", "~m~Benutzung: ~s~/setweather [Wetter]")]
        public void CmdAdminSetweather(Client player, string weather)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            bool found = false;
            foreach (string w in Enum.GetNames(typeof(Weather)))
            {
                if (w.ToLower() == weather)
                {
                    found = true;
                    break;
                }
            }

            if (!found)
            {
                ChatService.ErrorMessage(player, "Dieses Wetter existiert nicht");
                return;
            }

            Weather weatherBefore = NAPI.World.GetWeather();
            NAPI.World.SetWeather(weather);
            Weather weatherAfter = NAPI.World.GetWeather();

            if (!weatherBefore.Equals(weatherAfter))
            {
                ChatService.SendMessage(player, "~w~Wetter geändert: " + NAPI.World.GetWeather());
                NAPI.Notification.SendNotificationToAll("Das Wetter wurde auf ~g~ " + NAPI.World.GetWeather() + "~s~ geändert.", true);
            }
            else
            {
                ChatService.SendMessage(player, "~w~Das Wetter konnte nicht geändert werden");
            }
        }

        [Command("aspeed", "~m~Benutzung: ~s~/aspeed [Modifier]")] //TODO: Überarbeiten ?? SetPlayerVelocity ??
        public void CmdAdminAspeed(Client player, int modifier)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            if (!player.IsInVehicle)
            {
                ChatService.ErrorMessage(player, "Du sitzt momentan nicht in einem Fahrzeug");
                return;
            }

            player.Vehicle.SetSharedData("vehicleAdminSpeed", modifier);
        }

        [Command("setmoney", "~m~Benutzung: ~s~/setmoney [Name] [Menge]")]
        public void SetPlayerMoney(Client player, string receiver, int amount)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }
            Client target = ClientService.GetClientByNameOrId(receiver);
            if (target == null || !target.IsLoggedIn())
            {
                ChatService.PlayerNotFound(player);
                return;
            }

            using (var dbContext = new DatabaseContext())
            {
                target.GetUser().GetBankAccount(dbContext).Balance = amount;
                dbContext.SaveChanges();
            }
            ChatService.SendMessage(player, "~b~[ADMIN]~s~ Du hast das Geld von " + target.Name + " auf ~g~$" + amount + "~s~ gesetzt.");
            ChatService.SendMessage(target, "~b~[ADMIN]~s~ Dein Geld wurde von Admin " + player.Name + " auf ~g~$" + amount + "~s~ gesetzt.");
        }

        [Command("givemoney", "~m~Benutzung: ~s~/givemoney [Name] [Menge]")]
        public void GivePlayerMoney(Client player, string receiver, int amount)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            Client target = ClientService.GetClientByNameOrId(receiver);
            if (target == null || !target.IsLoggedIn())
            {
                ChatService.PlayerNotFound(player);
                return;
            }

            using (var dbContext = new DatabaseContext())
            {
                target.GetUser().GetBankAccount(dbContext).Balance += amount;
                dbContext.SaveChanges();
            }
            ChatService.SendMessage(player, "~b~[ADMIN]~s~ Du hast " + target.Name + " ~g~$" + amount + "~s~ gegeben.");
            ChatService.SendMessage(target, "~b~[ADMIN]~s~ Admin " + player.Name + " hat dir ~g~$" + amount + "~s~ gegeben.");
        }

        [Command("setbusinessowner", "~m~Benutzung: ~s~/setbusinessowner [Name] [Business ID]")]
        public void CmdAdminSetbusinessowner(Client player, string name, int businessid)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            Client target = ClientService.GetClientByNameOrId(name);
            if (target == null || !target.IsLoggedIn())
            {
                ChatService.PlayerNotFound(player);
                return;
            }

            if (target.GetUser().BusinessId != null)
            {
                ChatService.ErrorMessage(player, "Der Spieler besitzt momentan schon ein Business: ~o~" + BusinessManager.GetBusiness(target.GetUser().BusinessId).Name);
                return;
            }

            BusinessBase business = BusinessManager.GetBusiness(businessid);
            if (business == null)
            {
                ChatService.ErrorMessage(player, "Dieses Business existiert nicht. ~m~/businesslist");
                return;
            }

            if (business.GetOwner() != null)
            {
                ChatService.ErrorMessage(player, "Das Business hat momentan noch einen Besitzer: ~o~" + business.GetOwner().Name + "~s~. Entferne diesen Besitzer erst mit ~m~/clearbusiness");
                return;
            }

            using (var dbContext = new DatabaseContext())
            {
                Entities.User targetUser = target.GetUser(dbContext);
                targetUser.BusinessId = businessid;

                dbContext.SaveChanges();
                business.Update();
            }
        }

        [Command("clearbusiness", "~m~Benutzung:~s~ /clearbusiness [Business ID]")]
        public void CmdAdminClearbusiness(Client player, int businessid)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            BusinessBase business = BusinessManager.GetBusiness(businessid);
            if (business == null)
            {
                ChatService.ErrorMessage(player, "Dieses Business existiert nicht. ~m~/businesslist");
                return;
            }

            using (var dbContext = new DatabaseContext())
            {
                User owner = business.GetOwner(dbContext);
                if (owner == null)
                {
                    ChatService.ErrorMessage(player, "Dieses Business hat momentan keinen Besitzer");
                    return;
                }

                owner.BusinessId = null;
                business.GetBankAccount(dbContext).Balance = 0;

                ChatService.SendMessage(owner.Client, "~b~[ADMIN]~s~ Dir wurde von ~y~" + player.Name + "~s~ dein Business entzogen.");
                ChatService.SendMessage(player, "~b~[ADMIN]~s~ Du hast ~y~" + owner.Name + "~s~ sein Business ~o~" + business.Name + "~s~ entzogen.");

                dbContext.SaveChanges();
                business.Update();
            }
        }

        [Command("setbusinessbankbalance", "~m~Benutzung: ~s~/setbusinessbankbalance [Business ID] [Menge]")]
        public void CmdAdminGivebusinessbankbalance(Client player, int businessid, int amount)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            BusinessBase business = BusinessManager.GetBusiness(businessid);
            if (business == null)
            {
                ChatService.ErrorMessage(player, "Dieses Business existiert nicht. ~m~/businesslist");
                return;
            }

            BankManager.SetMoney(player, business, amount, "Admin");
        }

        [Command("showtuningmenu", "~m~Benutzung: ~s~/showtuningmenu")]
        public void CmdAdminShowtuningmenu(Client player)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            player.TriggerEvent("showTuningMenu");
        }

        [Command("interior", "~m~Benutzung: ~s~/interior [Add / Remove / SetEnterPosition / SetExitPosition] [Name / ID]")]
        public void CmdAdminInterior(Client player, string option1, string option2)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            option1 = option1.ToString();

            if (option1 != "add" && option1 != "remove" && option1 != "setenterposition" && option1 != "setexitposition")
            {
                ChatService.SendMessage(player, "~m~Benutzung: ~s~/interior [Add / Remove / SetEnterPosition / SetExitPosition] [Name]");
                return;
            }

            switch (option1)
            {
                case "add":
                    using (var dbContext = new DatabaseContext())
                    {
                        Interior interiorAdd = new Interior
                        {
                            Name = option2
                        };
                        dbContext.Interiors.Add(interiorAdd);
                        dbContext.SaveChanges();
                        ChatService.SendMessage(player, "~b~[ADMIN]~s~ Das Interior ~y~" + option2 + "~s~ wurde erstellt. ~m~ID: " + interiorAdd.Id);
                    }
                    break;
                case "remove":
                    using (var dbContext = new DatabaseContext())
                    {
                        if (!int.TryParse(option2, out int intId))
                        {
                            ChatService.ErrorMessage(player, "Es muss eine Nummer angegeben werden");
                            return;
                        }
                        Interior interiorRemove = InteriorManager.GetInteriorById(intId, dbContext);
                        if (interiorRemove == null)
                        {
                            ChatService.ErrorMessage(player, "Dieses Interior existiert nicht");
                            return;
                        }

                        InteriorManager.DeleteInterior(interiorRemove);

                        dbContext.Interiors.Remove(interiorRemove);
                        dbContext.SaveChanges();
                    }
                    ChatService.SendMessage(player, "~b~[ADMIN]~s~ Das Interior wurde gelöscht.");
                    break;
                case "setenterposition":
                    using (var dbContext = new DatabaseContext())
                    {
                        if (!int.TryParse(option2, out int intIdEnter))
                        {
                            ChatService.ErrorMessage(player, "Es muss eine Nummer angegeben werden");
                            return;
                        }
                        Interior interior = InteriorManager.GetInteriorById(intIdEnter, dbContext);
                        if (interior == null)
                        {
                            ChatService.ErrorMessage(player, "Dieses Interior existiert nicht");
                            return;
                        }
                        interior.EnterPosition = player.Position;
                        dbContext.SaveChanges();
                        InteriorManager.DeleteInterior(interior);
                        InteriorManager.LoadInterior(interior);
                        ChatService.SendMessage(player, "~b~[ADMIN]~s~ Die Eingangs-Position vom Interior ~y~" + interior.Name + "~s~ wurde gesetzt.");
                        InteriorManager.LoadInteriors();
                    }
                    break;
                case "setexitposition":
                    using (var dbContext = new DatabaseContext())
                    {
                        if (!int.TryParse(option2, out int intIdExit))
                        {
                            ChatService.ErrorMessage(player, "Es muss eine Nummer angegeben werden");
                            return;
                        }
                        Interior interior = InteriorManager.GetInteriorById(intIdExit, dbContext);
                        if (interior == null)
                        {
                            ChatService.ErrorMessage(player, "Dieses Interior existiert nicht");
                            return;
                        }
                        interior.ExitPosition = player.Position;
                        dbContext.SaveChanges();
                        InteriorManager.DeleteInterior(interior);
                        InteriorManager.LoadInterior(interior);
                        ChatService.SendMessage(player, "~b~[ADMIN]~s~ Die Eingangs-Position vom Interior ~y~" + interior.Name + "~s~ wurde gesetzt.");
                        InteriorManager.LoadInteriors();
                    }
                    break;
            }
        }

        [Command("reloaddoors", "~m~Benutzung: ~s~/reloaddoors")]
        public void CmdAdminReloaddoors(Client player)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            DoorManager.ReloadDoors();
            ChatService.SendMessage(player, "~b~[ADMIN]~s~ Die Türen wurden erfolgreich neugeladen.");
        }

        [Command("house", "~m~Benutzung: ~s~/house [add / remove / price / type / reloadhouses]", GreedyArg = true)]
        public void CmdAdminHouse(Client player, string option1, string option2 = null)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            option1 = option1.ToLower();

            if (option1 == "add")
            {
                House nearHouse = HouseManager.GetNearHouse(player.Position);
                if (nearHouse != null)
                {
                    ChatService.ErrorMessage(player, "In der Nähe ist schon ein Haus");
                    return;
                }

                using (var dbContext = new DatabaseContext())
                {
                    House house = new House()
                    {
                        Price = 0,
                        Type = "Haus",
                        X = player.Position.X,
                        Y = player.Position.Y,
                        Z = player.Position.Z
                    };

                    dbContext.Houses.Add(house);
                    dbContext.SaveChanges();

                    HouseManager.LoadHouse(house);

                    player.SendNotification("Das Haus wurde erstellt");
                }

                return;
            }
            else if (option1 == "remove")
            {
                using (var dbContext = new DatabaseContext())
                {
                    House nearHouse = HouseManager.GetNearHouse(player.Position, dbContext);
                    if (nearHouse == null)
                    {
                        ChatService.ErrorMessage(player, "In deiner Nähe befindet sich kein Haus");
                        return;
                    }

                    dbContext.Houses.Remove(nearHouse);
                    dbContext.SaveChanges();

                    HouseManager.RemoveHouse(nearHouse);

                    player.SendNotification("Das Haus wurde gelöscht");
                }

                return;
            }
            else if (option1 == "price")
            {
                if (!int.TryParse(option2, out int price))
                {
                    ChatService.ErrorMessage(player, "~m~Benutzung: ~s~/house price [Price]");
                    return;
                }

                using (var dbContext = new DatabaseContext())
                {
                    House nearHouse = HouseManager.GetNearHouse(player.Position, dbContext);
                    if (nearHouse == null)
                    {
                        ChatService.ErrorMessage(player, "In deiner Nähe befindet sich kein Haus");
                        return;
                    }

                    nearHouse.Price = price;
                    dbContext.SaveChanges();

                    HouseManager.RemoveHouse(nearHouse);
                    HouseManager.LoadHouse(nearHouse);

                    player.SendNotification("Der Hauspreis wurde gesetzt");
                }

                return;
            }
            else if (option1 == "type")
            {
                if(option2 == null)
                {
                    ChatService.ErrorMessage(player, "~m~Benutzung: ~s~/house type [Type]");
                    return;
                }

                using (var dbContext = new DatabaseContext())
                {
                    House nearHouse = HouseManager.GetNearHouse(player.Position, dbContext);
                    if (nearHouse == null)
                    {
                        ChatService.ErrorMessage(player, "In deiner Nähe befindet sich kein Haus");
                        return;
                    }

                    nearHouse.Type = option2;
                    dbContext.SaveChanges();

                    HouseManager.RemoveHouse(nearHouse);
                    HouseManager.LoadHouse(nearHouse);

                    player.SendNotification("Der Haustyp wurde gesetzt");
                }

                return;
            }
            else if(option1 == "reloadhouses")
            {
                HouseManager.ReloadAllHouses();
                player.SendNotification("Alle Häuser wurden neu geladen");
            }

            player.SendChatMessage("~m~Benutzung: ~s~/house [add / remove / price / type / reloadhouses]");
        }

        [Command("paydaydrop", "~m~Benutzung: ~s~/paydaydrop")]
        public void CmdAdminPaydaydrop(Client player)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            foreach (var target in NAPI.Pools.GetAllPlayers().Select(c => c.GetUser()))
            {
                Economy.SetPaycheck(target.Client, target.Wage);
            }

            ChatService.SendMessage(player, "~b~[ADMIN]~s~ Du hast ein Payday gedroppt.");
        }

        [Command("setwage", "~m~Benutzung: ~s~/setwage [Name/Id] [Lohn]")]
        public void CmdAdminSetWage(Client player, string nameOrId, int wage)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            Client target = ClientService.GetClientByNameOrId(nameOrId);
            if (target == null || !target.IsLoggedIn())
            {
                ChatService.PlayerNotFound(player);
                return;
            }

            using (var dbContext = new DatabaseContext())
            {
                target.GetUser(dbContext).Wage = wage;
                dbContext.SaveChanges();
            }
        }

        #endregion

        #region ALevel1338
        [Command("whitelist", "~m~Benutzung: ~s~/whitelist [Add / Remove] [Socialclub Name]")]
        public void CmdAdminWhitelist(Client player, string option, string scName)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.PROJEKTLEITUNG) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            option = option.ToLower();

            if (option != "add" && option != "remove")
            {
                ChatService.SendMessage(player, "~m~Benutzung: ~s~/whitelist [Add / Remove] [Socialclub Name]");
                return;
            }

            using (var dbContext = new DatabaseContext())
            {
                if (option == "add")
                {
                    if (dbContext.WhitelistEntries.Any(w => w.SocialClubName.ToLower() == scName.ToLower()))
                    {
                        ChatService.ErrorMessage(player, "Dieser Name ist schon auf der Whitelist");
                        return;
                    }

                    Whitelist whitelist = new Whitelist { SocialClubName = scName.ToLower() };
                    dbContext.WhitelistEntries.Add(whitelist);

                    ChatService.SendMessage(player, "~b~[ADMIN]~s~ ~y~" + scName + "~s~ wurde erfolgreich zur Whitelist hinzugefügt.");
                }
                else if (option == "remove")
                {
                    if (!dbContext.WhitelistEntries.Any(w => w.SocialClubName.ToLower() == scName.ToLower()))
                    {
                        ChatService.ErrorMessage(player, "Dieser Name ist nicht auf der Whitelist");
                        return;
                    }

                    Whitelist whitelist = dbContext.WhitelistEntries.FirstOrDefault(w => w.SocialClubName.ToLower() == scName.ToLower());
                    dbContext.WhitelistEntries.Remove(whitelist);

                    ChatService.SendMessage(player, "~b~[ADMIN]~s~ ~y~" + scName + "~s~ wurde erfolgreich aus der Whitelist entfernt.");
                }
                dbContext.SaveChanges();
            }
        }

        [Command("makeadmin", "~m~Benutzung: ~s~/makeadmin [Name] [Adminlevel]")]
        public void CmdAdminSetadmin(Client player, string name, int rank)
        {
            if (!player.GetUser()?.IsAdmin(AdminLevel.PROJEKTLEITUNG) ?? true)
            {
                ChatService.NotAuthorized(player);
                return;
            }

            if (!Enum.IsDefined(typeof(AdminLevel), rank))
            {
                ChatService.ErrorMessage(player, "Dieser Adminrang ist nicht definiert");
                return;
            }

            Client target = ClientService.GetClientByNameOrId(name);
            if (target == null || !target.IsLoggedIn())
            {
                ChatService.PlayerNotFound(player);
                return;
            }

            using (var dbContext = new DatabaseContext())
            {
                target.GetUser(dbContext).AdminLevel = (AdminLevel)rank;
                dbContext.SaveChanges();
            }
            ChatService.SendMessage(target, "Du wurdest durch " + player.Name + " auf Adminlevel " + target.GetUser().AdminLevel.GetName() + ":(" + rank + ") gesetzt.");
            ChatService.SendMessage(player, "Du hast " + target.Name + " auf Adminlevel " + target.GetUser().AdminLevel.GetName() + ":(" + rank + ") gesetzt.");

        }
        #endregion
    }
}
