Skip to content

Commit

Permalink
Move static function to bottom of file, add Linq ref, and add some docs
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasjosif committed Feb 17, 2021
1 parent deb241b commit 8ef0ac4
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions UltimateAFK/PlayerEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Exiled.Events.EventArgs;
using Exiled.Permissions.Extensions;
using Exiled.Loader;
using System.Linq;

namespace UltimateAFK
{
Expand All @@ -16,13 +17,6 @@ public PlayerEvents(MainClass plugin)
this.plugin = plugin;
}

public static bool IsGhost(Player player)
{
Assembly assembly = Loader.Plugins.FirstOrDefault(pl => pl.Name == "GhostSpectator")?.Assembly;
if (assembly == null) return false;
return ((bool)assembly.GetType("GhostSpectator.API")?.GetMethod("IsGhost")?.Invoke(null, new object[] { player })) == true;
}

public void OnPlayerJoined(JoinedEventArgs ev)
{
// Add a component to the player to check AFK status.
Expand Down Expand Up @@ -140,7 +134,11 @@ public void OnSCP079Exp(GainingExperienceEventArgs ev)
}
}

// Thanks iopietro!
/// <summary>
/// Reset the AFK time of a player.
/// Thanks iopietro!
/// </summary>
/// <param name="player"></param>
public void ResetAFKTime(Player player)
{
try
Expand All @@ -158,5 +156,17 @@ public void ResetAFKTime(Player player)
Log.Error($"ERROR In ResetAFKTime(): {e}");
}
}

/// <summary>
/// Checks if a player is a "ghost" using GhostSpectator's API.
/// </summary>
/// <param name="player"></param>
/// <returns></returns>
public static bool IsGhost(Player player)
{
Assembly assembly = Loader.Plugins.FirstOrDefault(pl => pl.Name == "GhostSpectator")?.Assembly;
if (assembly == null) return false;
return ((bool)assembly.GetType("GhostSpectator.API")?.GetMethod("IsGhost")?.Invoke(null, new object[] { player })) == true;
}
}
}

0 comments on commit 8ef0ac4

Please sign in to comment.