Skip to content

Commit

Permalink
Optimization: remove unnecessary loop
Browse files Browse the repository at this point in the history
  • Loading branch information
lengran committed Apr 11, 2024
1 parent 87375c1 commit afc87c6
Showing 1 changed file with 30 additions and 24 deletions.
54 changes: 30 additions & 24 deletions CS2AnnouncementBroadcaster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class CS2AnnouncementBroadcaster : BasePlugin
{
public override string ModuleName => "CS2 Announcement Broadcaster";

public override string ModuleVersion => "0.2.0";
public override string ModuleVersion => "0.2.1";

public override string ModuleAuthor => "Lengran";

Expand Down Expand Up @@ -131,19 +131,24 @@ public HookResult OnPlayerConnectFull(EventPlayerConnectFull @event, GameEventIn
[GameEventHandler]
public HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info)
{
var players = Utilities.GetPlayers();

foreach (var tmpPlayer in players)
// var players = Utilities.GetPlayers();

// foreach (var tmpPlayer in players)
// {
// if (!tmpPlayer.IsValid || tmpPlayer.IsBot || tmpPlayer.IsHLTV)
// {
// continue;
// }

// foreach (var msg in _onRoundStartMsgs)
// {
// tmpPlayer.PrintToChat(msg.msg);
// }
// }

foreach (var msg in _onRoundStartMsgs)
{
if (!tmpPlayer.IsValid || tmpPlayer.IsBot || tmpPlayer.IsHLTV)
{
continue;
}

foreach (var msg in _onRoundStartMsgs)
{
tmpPlayer.PrintToChat(msg.msg);
}
Server.PrintToChatAll(msg.msg);
}

return HookResult.Continue;
Expand Down Expand Up @@ -199,17 +204,18 @@ private void UnregisterCommand()
private void RegisterTimer(TimerMsg msg)
{
var timer = AddTimer(msg.timer, () => {
var players = Utilities.GetPlayers();

foreach (var tmpPlayer in players)
{
if (!tmpPlayer.IsValid || tmpPlayer.IsBot || tmpPlayer.IsHLTV)
{
continue;
}

tmpPlayer.PrintToChat(msg.msg);
}
// var players = Utilities.GetPlayers();

// foreach (var tmpPlayer in players)
// {
// if (!tmpPlayer.IsValid || tmpPlayer.IsBot || tmpPlayer.IsHLTV)
// {
// continue;
// }

// tmpPlayer.PrintToChat(msg.msg);
// }
Server.PrintToChatAll(msg.msg);
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.REPEAT);

_registeredTimers.Add(timer);
Expand Down

0 comments on commit afc87c6

Please sign in to comment.