Skip to content
This repository has been archived by the owner on Oct 9, 2022. It is now read-only.

Commit

Permalink
mmyes
Browse files Browse the repository at this point in the history
  • Loading branch information
Build committed Jun 6, 2022
1 parent 3b584a8 commit 2d1b235
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions UltimateAFK/Components/AfkComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ public class AfkComponent : MonoBehaviour
private int afkTime;
private int afkCounter;

private static Plugin Plugin => Plugin.Instance;

private void Awake()
{
player = Player.Get(gameObject);
Expand All @@ -48,8 +46,8 @@ private void CheckAfk()
{
if (player.CheckPermission("uafk.ignore") ||
player.IsDead ||
Plugin.Config.MinimumPlayers > Player.Dictionary.Count ||
(Plugin.Config.IgnoreTutorials && player.Role.Type == RoleType.Tutorial) ||
Plugin.Instance.Config.MinimumPlayers > Player.Dictionary.Count ||
(Plugin.Instance.Config.IgnoreTutorials && player.Role.Type == RoleType.Tutorial) ||
player.Role is Scp096Role { TryingNotToCry: true })
{
afkTime = 0;
Expand All @@ -65,26 +63,26 @@ private void CheckAfk()
}

afkTime++;
if (afkTime < Plugin.Config.AfkTime)
if (afkTime < Plugin.Instance.Config.AfkTime)
return;

int gracePeriodRemaining = Plugin.Config.GraceTime + Plugin.Config.AfkTime - afkTime;
int gracePeriodRemaining = Plugin.Instance.Config.GraceTime + Plugin.Instance.Config.AfkTime - afkTime;
if (gracePeriodRemaining > 0)
{
player.Broadcast(1, string.Format(Plugin.Translation.GracePeriodWarning, gracePeriodRemaining).Replace("$seconds", gracePeriodRemaining == 1 ? "second" : "seconds"), shouldClearPrevious: true);
player.Broadcast(1, string.Format(Plugin.Instance.Translation.GracePeriodWarning, gracePeriodRemaining).Replace("$seconds", gracePeriodRemaining == 1 ? "second" : "seconds"), shouldClearPrevious: true);
return;
}

Log.Debug($"{player} has been detected as AFK.", Plugin.Config.Debug);
Log.Debug($"{player} has been detected as AFK.", Plugin.Instance.Config.Debug);
afkTime = 0;

if (Plugin.Config.TryReplace)
if (Plugin.Instance.Config.TryReplace)
TryReplace();

player.ClearInventory();
if (Plugin.Instance.Config.SpectateLimit > 0 && ++afkCounter > Plugin.Instance.Config.SpectateLimit)
{
player.Disconnect(Plugin.Translation.KickReason);
player.Disconnect(Plugin.Instance.Translation.KickReason);
return;
}

Expand All @@ -93,15 +91,15 @@ private void CheckAfk()

private void TryReplace()
{
Player toSwap = Player.List.FirstOrDefault(ply => ply.IsDead && !ply.IsOverwatchEnabled && ply != player);
Player toSwap = Player.List.FirstOrDefault(toSwap => toSwap.IsDead && !toSwap.IsOverwatchEnabled && toSwap != player);
if (toSwap is not null)
new PlayerInfo(player).AddTo(toSwap);
}

private void ForceSpectator()
{
player.Role.Type = RoleType.Spectator;
player.Broadcast(Plugin.Translation.SpectatorForced);
player.Broadcast(Plugin.Instance.Translation.SpectatorForced);
}
}
}

0 comments on commit 2d1b235

Please sign in to comment.