Skip to content

Commit

Permalink
Merge pull request #6 from B3none/queue-priority
Browse files Browse the repository at this point in the history
Added queue priority for players with the @css/vip flag
  • Loading branch information
B3none authored Jan 3, 2024
2 parents b8a2997 + 1aca1f6 commit 58beb48
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 10 deletions.
34 changes: 33 additions & 1 deletion Modules/Managers/Queue.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Admin;
using CounterStrikeSharp.API.Modules.Utils;

namespace RetakesPlugin.Modules.Managers;
Expand Down Expand Up @@ -121,17 +122,48 @@ private void RemoveDisconnectedPlayers()
QueuePlayers.RemoveAll(player => disconnectedQueuePlayers.Contains(player));
}
}

private void HandleQueuePriority()
{
var vipsInQueue = QueuePlayers.Where(player => AdminManager.PlayerHasPermissions(player, "@css/vip")).ToList().Count;

if (vipsInQueue > 0)
{
Helpers.Shuffle(
ActivePlayers
.Where(player => !AdminManager.PlayerHasPermissions(player, "@css/vip"))
.ToList()
)
.ForEach(player =>
{
if (vipsInQueue <= 0)
{
return;
}

ActivePlayers.Remove(player);
QueuePlayers.Add(player);
vipsInQueue--;
});
}
}

public void Update()
{
RemoveDisconnectedPlayers();
HandleQueuePriority();

var playersToAdd = _maxRetakesPlayers - ActivePlayers.Count;

if (playersToAdd > 0 && QueuePlayers.Count > 0)
{
// Take players from QueuePlayers and add them to ActivePlayers
var playersToAddList = QueuePlayers.Take(playersToAdd).ToList();
// Ordered by players with @retakes/queue group first since they
// have queue priority.
var playersToAddList = QueuePlayers
.OrderBy(player => AdminManager.PlayerHasPermissions(player, "@css/vip"))
.Take(playersToAdd)
.ToList();

QueuePlayers.RemoveAll(player => playersToAddList.Contains(player));
ActivePlayers.AddRange(playersToAddList);
Expand Down
19 changes: 10 additions & 9 deletions RetakesPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,41 +111,42 @@ public void AddSpawnCommand(CCSPlayerController? player, CommandInfo commandInfo

commandInfo.ReplyToCommand($"{LogPrefix}{(didAddSpawn ? "Spawn added" : "Error adding spawn")}");
}

[ConsoleCommand("css_teleport", "This command teleports the player to the given coordinates")]
[RequiresPermissions("@css/root")]
public void OnCommandTeleport(CCSPlayerController? player, CommandInfo command)
public void OnCommandTeleport(CCSPlayerController? player, CommandInfo commandInfo)
{
if (player == null)
if (!Helpers.IsValidPlayer(player))
{
return;
}
if (!player.PlayerPawn.IsValid)

if (!player!.PlayerPawn.IsValid)
{
return;
}

if (command.ArgCount != 4)
if (commandInfo.ArgCount != 4)
{
return;
}

if (!float.TryParse(command.ArgByIndex(1), out float positionX))
if (!float.TryParse(commandInfo.ArgByIndex(1), out var positionX))
{
return;
}

if (!float.TryParse(command.ArgByIndex(2), out float positionY))
if (!float.TryParse(commandInfo.ArgByIndex(2), out var positionY))
{
return;
}

if (!float.TryParse(command.ArgByIndex(3), out float positionZ))
if (!float.TryParse(commandInfo.ArgByIndex(3), out var positionZ))
{
return;
}

player?.PlayerPawn?.Value?.Teleport(new Vector(positionX, positionY, positionZ), new QAngle(0f,0f,0f), new Vector(0f, 0f, 0f));
player.PlayerPawn.Value?.Teleport(new Vector(positionX, positionY, positionZ), new QAngle(0f,0f,0f), new Vector(0f, 0f, 0f));
}

// Listeners
Expand Down

0 comments on commit 58beb48

Please sign in to comment.