<repo_name>TheUltiOne/AFK<file_sep>/AFK/Handlers/AFKCommand.cs
using CommandSystem;

using Exiled.API.Features;
using RemoteAdmin;

using System;

using System.Linq;

namespace AFK
{
    [CommandHandler(typeof(ClientCommandHandler))]
    public class AFKCommand : ICommand
    {
        public string Command => "afk";

        public string[] Aliases => Array.Empty<string>();

        public string Description => "Gives a player an overwatch-like mode to prevent AFK kicking";

        public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
        {
            if (sender is PlayerCommandSender player)
            {
                if (Handlers.AFKHandlers.afk_players.Count() >= AFK.Instance.Config.AFKMaxplayers)
                {
                    response = AFK.Instance.Config.AFKMaxPlayersMessage.Replace("%afkcount%", Convert.ToString(AFK.Instance.Config.AFKMaxplayers)); ;
                    return false;
                }

                Player p = Player.Get(player.SenderId);

                if (Handlers.AFKHandlers.afk_players.Contains(p)) {
                    Handlers.AFKHandlers.afk_players.Remove(p);
                } else
                {
                    Handlers.AFKHandlers.afk_players.Add(p);
                }

                response = Handlers.AFKHandlers.afk_players.Contains(p)
                    ? AFK.Instance.Config.AddedToAFK
                    : AFK.Instance.Config.RemovedFromAFK;
                return true;
            }

            response = "This command must be executed from the game level.";
            return false;
        }
    }
}
<file_sep>/README.md
# AFK
If command in the `~` console is .afk, you will go into overwatch mode.
This makes you __NOT__ respawn.
Running the command will take you out of overwatch mode.
IT SHOULD KILL YOU!
# Config Options
| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `is_enabled` | bool | Toggles the plugin | true |

This plugin requires https://github.com/galaxy119/EXILED/releases/tag/2.1.18.
To install EXILED go to https://www.youtube.com/watch?v=EUfzj8OWvQU.
Once EXILED is installed, go to `appdata/roaming/exiled/plugins` and put it there. (windows)
LINUX: `.config/exiled/plugins`

Discord: TypicalIllusion#5726
<file_sep>/AFK/Config.cs
﻿using System.ComponentModel;

using Exiled.API.Interfaces;

namespace AFK
{
    public class Config : IConfig
    {
        [Description("Is the plugin enabled?")]
        public bool IsEnabled { get; set; } = true;

        [Description("How many players until the command doesnt work?")]
        public int AFKMaxplayers { get; set; } = 3;

        [Description("The response in console when removed from AFK.")]
        public string RemovedFromAFK { get; set; } = "Removed from AFK!";

        [Description("The response in console when added to AFK.")]
        public string AddedToAFK { get; set; } = "Added to AFK!";

        [Description("Sets the Hint content when the player is not affected by a respawn wave to let them know about their AFK mode.")]
        public string AFKHintContent { get; set; } = "AFK Mode ON ~ To remove it, run .afk in the console. (~/`)";

        [Description("Sets the Hint duration when the player is not affected by a respawn wave.")]
        public float AFKHintDuration { get; set; } = 5;

        [Description("Sets the response sent while trying to use the command but max players are AFK. (use %afkcount% for AFK max players)")]
        public string AFKMaxPlayersMessage { get; set; } = "Max AFK players reached - %afkcount%/%afkcount%";
    }
}
<file_sep>/AFK/AFK.cs
using Exiled.API.Features;
using Exiled.API.Enums;

using Server = Exiled.Events.Handlers.Server;
using Player = Exiled.Events.Handlers.Player;
using Map = Exiled.Events.Handlers.Map;
using System;

namespace AFK
{
    public class AFK : Plugin<Config>
    {
        public override string Name { get; } = "AFKPlugin";
        public override string Author { get; } = "TheUltiOne";
        public override Version Version { get; } = new Version(1, 0, 0);
        public override Version RequiredExiledVersion { get; } = new Version(2, 1, 29);

        private static AFK Singleton = new AFK();

        public override PluginPriority Priority { get; } = PluginPriority.Medium;
        private Handlers.AFKHandlers handlers;

        private AFK()
        {
        }

        public static AFK Instance => Singleton;

        public override void OnEnabled()
        {
            RegisterEvents();
        }

        public override void OnDisabled()
        {
            UnregisterEvents();
        }

        public override void OnReloaded()
        {
            UnregisterEvents();
            RegisterEvents();
        }

        public void RegisterEvents()
        {
            handlers = new Handlers.AFKHandlers();

            Server.RespawningTeam += handlers.OnRespawningTeam;
            Server.RoundEnded += handlers.OnRoundEnded;
        }

        public void UnregisterEvents()
        {
            Server.RespawningTeam -= handlers.OnRespawningTeam;
            Server.RoundEnded -= handlers.OnRoundEnded;
            handlers = null;
        }
    }
}
<file_sep>/AFK/Handlers/AFKHandlers.cs
﻿using System.Collections.Generic;
using System.Linq;
using Exiled.API.Features;
using Exiled.Events.EventArgs;

namespace AFK.Handlers
{
    class AFKHandlers
    {
        public static List<Player> afk_players = new List<Player>();
        
        public void OnRoundEnded(RoundEndedEventArgs ev) {
            afk_players.Clear();
        }

        public void OnRespawningTeam(RespawningTeamEventArgs ev)
        {
            foreach (Player i in ev.Players.ToList())
            {
                if (afk_players.Contains(i))
                {
                    ev.Players.Remove(i);
                    i.ShowHint(AFK.Instance.Config.AFKHintContent, AFK.Instance.Config.AFKHintDuration);
                }
            }
        }
    }
}
<file_sep>/AFK/Handlers/Server.cs
﻿using System;
using Exiled.Events.EventArgs;
using EPlayer = Exiled.API.Features.Player;
using System.Collections.Generic;

namespace AFK.Handlers
{
    class Server
    {
        public static List<EPlayer> afk_players = new List<EPlayer>();

        public void OnRespawningTeam(RespawningTeamEventArgs ev)
        {
            foreach (EPlayer player in EPlayer.List)
            {
                if (afk_players.Contains(player))
                {
                    ev.Players.Remove(player);
                }
            }
        }
    }
}
