Skip to content
This repository has been archived by the owner on Sep 1, 2024. It is now read-only.

Commit

Permalink
GetPlayers
Browse files Browse the repository at this point in the history
  • Loading branch information
K4ryuu committed Feb 10, 2024
1 parent d8d229f commit 25d15fc
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
-- 2023.02.10 - V3.3.5

- fix: Invalid player blocked from functions (problem by GetPlayers)

-- 2023.02.10 - V3.3.4

- fix: Bomb explode using HostageRescueAll points
Expand Down
2 changes: 1 addition & 1 deletion src/Module/Rank/RankEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public void Initialize_Events(Plugin plugin)
{
List<CCSPlayerController> players = Utilities.GetPlayers();
players.Where(p => p?.IsValid == true && p.PlayerPawn?.IsValid == true && !p.IsBot && !p.IsHLTV && p.PawnIsAlive && rankCache.ContainsPlayer(p))
players.Where(p => p?.IsValid == true && p.PlayerPawn?.IsValid == true && !p.IsBot && !p.IsHLTV && p.PawnIsAlive && rankCache.ContainsPlayer(p) && p.SteamID.ToString().Length == 17)
.ToList()
.ForEach(p => rankCache[p].PlayedRound = true);
Expand Down
7 changes: 5 additions & 2 deletions src/Module/Rank/RankFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public bool IsPointsAllowed()
if (plugin.GameRules == null)
return false;

int notBots = Utilities.GetPlayers().Count(player => !player.IsBot);
int notBots = Utilities.GetPlayers().Count(p => !p.IsBot && p.SteamID.ToString().Length == 17);

return (!plugin.GameRules.WarmupPeriod || Config.RankSettings.WarmupPoints) && (Config.RankSettings.MinPlayers <= notBots);
}
Expand All @@ -28,7 +28,7 @@ public Rank GetNoneRank()

public void BeforeRoundEnd(int winnerTeam)
{
List<CCSPlayerController> players = Utilities.GetPlayers().Where(player => player?.IsValid == true && player.PlayerPawn?.IsValid == true && !player.IsBot && !player.IsHLTV && rankCache.ContainsPlayer(player)).ToList();
List<CCSPlayerController> players = Utilities.GetPlayers().Where(p => p?.IsValid == true && p.PlayerPawn?.IsValid == true && !p.IsBot && !p.IsHLTV && rankCache.ContainsPlayer(p) && p.SteamID.ToString().Length == 17).ToList();

foreach (CCSPlayerController player in players)
{
Expand Down Expand Up @@ -99,6 +99,9 @@ public void ModifyPlayerPoints(CCSPlayerController player, int amount, string re
if (player.IsBot || player.IsHLTV)
return;

if (player.SteamID.ToString().Length == 17)
return;

if (!rankCache.ContainsPlayer(player))
return;

Expand Down
3 changes: 0 additions & 3 deletions src/Plugin/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ public override void Unload(bool hotReload)
public async Task<bool> CreateMultipleTablesAsync()
{
string timesModuleTable = @$"CREATE TABLE IF NOT EXISTS `{this.Config.DatabaseSettings.TablePrefix}k4times` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`steam_id` VARCHAR(32) COLLATE 'utf8mb4_unicode_ci' UNIQUE NOT NULL,
`name` VARCHAR(255) COLLATE 'utf8mb4_unicode_ci' NOT NULL,
`all` INT NOT NULL DEFAULT 0,
Expand All @@ -134,7 +133,6 @@ public async Task<bool> CreateMultipleTablesAsync()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;";

string statsModuleTable = $@"CREATE TABLE IF NOT EXISTS `{this.Config.DatabaseSettings.TablePrefix}k4stats` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`steam_id` VARCHAR(32) COLLATE 'utf8mb4_unicode_ci' UNIQUE NOT NULL,
`name` VARCHAR(255) COLLATE 'utf8mb4_unicode_ci' NOT NULL,
`lastseen` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
Expand All @@ -156,7 +154,6 @@ public async Task<bool> CreateMultipleTablesAsync()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;";

string ranksModuleTable = $@"CREATE TABLE IF NOT EXISTS `{this.Config.DatabaseSettings.TablePrefix}k4ranks` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`steam_id` VARCHAR(32) COLLATE 'utf8mb4_unicode_ci' UNIQUE NOT NULL,
`name` VARCHAR(255) COLLATE 'utf8mb4_unicode_ci' NOT NULL,
`rank` VARCHAR(255) COLLATE 'utf8mb4_unicode_ci' NOT NULL,
Expand Down
3 changes: 3 additions & 0 deletions src/Plugin/PluginBasics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ public void Initialize_Events()
if (player.IsBot || player.IsHLTV)
continue;
if (player.SteamID.ToString().Length == 17)
continue;
player.PrintToChat($" {Localizer["k4.general.prefix"]} {ChatColors.Lime}{Localizer["k4.general.spawnmessage"]}");
}
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/PluginManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public sealed partial class Plugin : BasePlugin

public override string ModuleAuthor => "K4ryuu";

public override string ModuleVersion => "3.3.4 " +
public override string ModuleVersion => "3.3.5 " +
#if RELEASE
"(release)";
#else
Expand Down
12 changes: 3 additions & 9 deletions src/Plugin/PluginStock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,14 @@ public List<PlayerData> PreparePlayersData()
{
List<PlayerData> playersData = new List<PlayerData>();
List<CCSPlayerController> players = Utilities.GetPlayers()
.Where(p => p?.IsValid == true && p.PlayerPawn?.IsValid == true && !p.IsBot && !p.IsHLTV && p.Connected == PlayerConnectedState.PlayerConnected)
.Where(p => p?.IsValid == true && p.PlayerPawn?.IsValid == true && !p.IsBot && !p.IsHLTV && p.Connected == PlayerConnectedState.PlayerConnected && p.SteamID.ToString().Length == 17)
.ToList();

foreach (CCSPlayerController player in players)
{
try
{
if (!ulong.TryParse(player.SteamID.ToString(), out ulong steamIdValue))
{
Logger.LogError($"Invalid SteamID for {player.PlayerName} > {player.SteamID}");
continue;
}

SteamID steamId = new SteamID(steamIdValue);
SteamID steamId = new SteamID(player.SteamID);

if (!steamId.IsValid())
continue;
Expand Down Expand Up @@ -396,7 +390,7 @@ public async Task LoadPlayerCacheAsync(int slot, string combinedQuery, MySqlPara

private void LoadAllPlayersCache()
{
List<CCSPlayerController> players = Utilities.GetPlayers().Where(player => player != null && player.IsValid && player.PlayerPawn.IsValid && !player.IsBot && !player.IsHLTV).ToList();
List<CCSPlayerController> players = Utilities.GetPlayers().Where(player => player != null && player.IsValid && player.PlayerPawn.IsValid && !player.IsBot && !player.IsHLTV && player.SteamID.ToString().Length == 17).ToList();

Dictionary<string, int> steamIdToSlot = players.ToDictionary(player => player.SteamID.ToString(), player => player.Slot);

Expand Down

0 comments on commit 25d15fc

Please sign in to comment.