Skip to content

Commit

Permalink
1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Misfiy committed May 3, 2024
1 parent dd85255 commit 0239c7f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
45 changes: 28 additions & 17 deletions SpectatorList/EventHandler.cs
Original file line number Diff line number Diff line change
@@ -1,45 +1,56 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MEC;
using Exiled.API.Features;
using MEC;
using PlayerRoles;
using UnityEngine;

namespace SpectatorList
{
public class EventHandler
{
private const string CoroutineTag = "Spectator-List";

private Config _config => SpectatorList.Instance.Config;

public EventHandler() => Timing.RunCoroutine(DoList());

public EventHandler()
{
Exiled.Events.Handlers.Server.RoundStarted += OnRoundStarted;
}

~EventHandler()
{
Exiled.Events.Handlers.Server.RoundStarted -= OnRoundStarted;
Timing.KillCoroutines(CoroutineTag);
}

private void OnRoundStarted() => Timing.RunCoroutine(DoList().CancelWith(Server.Host.GameObject), CoroutineTag);

private IEnumerator<float> DoList()
{
for (; ;)
Log.Debug("haii");
while (true)
{
if (Round.IsEnded)
{
Timing.WaitForSeconds(5);
continue;
}

Log.Debug("Running foreach loop.");

foreach (Player player in Player.List)
{
Log.Debug("Checking condition for Spec List");
if (player.IsDead || _config.HiddenFor.Contains(player.Role.Team)) continue;

Log.Debug("Player is able to see Spectator List");

int count = player.CurrentSpectatingPlayers.Count(p => p.Role != RoleTypeId.Overwatch);

StringBuilder sb = new StringBuilder();
sb.AppendLine($"{count} players are spectating{(count == 0 ? string.Empty : ":")}");

foreach (Player spectator in player.CurrentSpectatingPlayers.Where(p => p.Role != RoleTypeId.Overwatch))
{
sb.AppendLine(_config.PlayerDisplay.Replace("%name%", spectator.DisplayNickname));
}
sb.AppendLine(_config.PlayerDisplay.Replace("%name%", spectator.CustomName));

player.ShowHint(_config.FullText.Replace("%display%", sb.ToString()), _config.RefreshRate + 0.15f);
}

yield return Timing.WaitForSeconds(_config.RefreshRate);
}
}
Expand Down
2 changes: 1 addition & 1 deletion SpectatorList/SpectatorList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class SpectatorList : Plugin<Config>

public override string Name { get; } = "Spectator List";
public override string Author { get; } = "@misfiy";
public override Version Version { get; } = new Version(1,1,0);
public override Version Version { get; } = new Version(1,1,1);
public override Version RequiredExiledVersion { get; } = new Version(8, 8, 1);

private EventHandler _handler;
Expand Down

0 comments on commit 0239c7f

Please sign in to comment.