Refactor skill lookup logic and vote system, update language files

Refactored command handling to improve player and skill lookup logic, replaced some list operations with direct queries, and updated method signatures for clarity and null safety. The vote system was reworked to support more robust vote tracking, cooldowns, and localized chat messages. Language files were updated to add new vote-related translations. Various code style and nullability improvements were made throughout the plugin.
This commit is contained in:
Juzlus 2025-09-04 04:53:23 +02:00
parent 54b265d43d
commit e33975fe8b
117 changed files with 1532 additions and 1674 deletions

View file

@ -9,12 +9,12 @@ namespace jRandomSkills
public class SniperElite : ISkill
{
private const Skills skillName = Skills.SniperElite;
private static readonly Dictionary<ulong, string> sniperElites = new Dictionary<ulong, string>();
private static readonly Dictionary<ulong, string> sniperElites = [];
private static string[] rifles = { "weapon_mp9", "weapon_mac10", "weapon_bizon", "weapon_mp7", "weapon_ump45", "weapon_p90",
private static readonly string[] rifles = [ "weapon_mp9", "weapon_mac10", "weapon_bizon", "weapon_mp7", "weapon_ump45", "weapon_p90",
"weapon_mp5sd", "weapon_famas", "weapon_galilar", "weapon_m4a1", "weapon_m4a1_silencer", "weapon_ak47",
"weapon_aug", "weapon_sg553", "weapon_ssg08", "weapon_awp", "weapon_scar20", "weapon_g3sg1",
"weapon_nova", "weapon_xm1014", "weapon_mag7", "weapon_sawedoff", "weapon_m249", "weapon_negev" };
"weapon_nova", "weapon_xm1014", "weapon_mag7", "weapon_sawedoff", "weapon_m249", "weapon_negev" ];
public static void LoadSkill()
{
@ -26,7 +26,7 @@ namespace jRandomSkills
{
foreach (var player in Utilities.GetPlayers())
{
var playerInfo = Instance.skillPlayer.FirstOrDefault(p => p.SteamID == player.SteamID);
var playerInfo = Instance.SkillPlayer.FirstOrDefault(p => p.SteamID == player.SteamID);
if (playerInfo?.Skill == skillName)
EnableSkill(player);
}
@ -44,11 +44,10 @@ namespace jRandomSkills
Instance.RegisterEventHandler<EventPlayerDeath>((@event, info) =>
{
var player = @event.Userid;
var playerInfo = Instance.skillPlayer.FirstOrDefault(p => p.SteamID == player.SteamID);
if (player == null || !player.IsValid) return HookResult.Continue;
var playerInfo = Instance.SkillPlayer.FirstOrDefault(p => p.SteamID == player.SteamID);
if (playerInfo?.Skill == skillName)
if (sniperElites.ContainsKey(player.SteamID))
sniperElites.Remove(player.SteamID);
sniperElites.Remove(player.SteamID);
return HookResult.Continue;
});
@ -61,8 +60,7 @@ namespace jRandomSkills
public static void DisableSkill(CCSPlayerController player)
{
if (sniperElites.ContainsKey(player.SteamID))
sniperElites.Remove(player.SteamID);
sniperElites.Remove(player.SteamID);
}
public static void UseSkill(CCSPlayerController player)
@ -77,41 +75,38 @@ namespace jRandomSkills
private static void RemoveAndGiveWeapon(CCSPlayerController player)
{
string holdedWeapon = "weapon_awp";
if (sniperElites.TryGetValue(player.SteamID, out string weapon))
holdedWeapon = weapon;
if (sniperElites.TryGetValue(player.SteamID, out string? weapon))
if (!string.IsNullOrEmpty(weapon))
holdedWeapon = weapon;
try
{
string activeRifle = GetActiveRifle(player);
if (activeRifle != null)
string? activeRifle = GetActiveRifle(player);
if (!string.IsNullOrEmpty(activeRifle))
player.RemoveItemByDesignerName(activeRifle, true);
sniperElites[player.SteamID] = activeRifle;
Server.NextFrame(() =>
{
player.GiveNamedItem(holdedWeapon ?? "weapon_awp");
});
sniperElites[player.SteamID] = activeRifle ?? "weapon_awp";
Server.NextFrame(() => player.GiveNamedItem(holdedWeapon ?? "weapon_awp") );
}
catch { }
}
private static string GetActiveRifle(CCSPlayerController player)
private static string? GetActiveRifle(CCSPlayerController player)
{
string rifle = null;
var weapons = player.PlayerPawn.Value.WeaponServices.MyWeapons;
if (weapons == null) return rifle;
string rifle = string.Empty;
var pawn = player.PlayerPawn.Value;
if (pawn == null || !pawn.IsValid) return rifle;
var weaponServices = pawn.WeaponServices;
if (weaponServices == null) return rifle;
foreach (var weapon in weapons)
foreach (var weapon in weaponServices.MyWeapons)
if (weapon != null && weapon.IsValid && weapon.Value != null && weapon.Value.IsValid)
if (rifles.Contains(weapon.Value.DesignerName))
rifle = weapon.Value.DesignerName;
rifle = SkillUtils.GetDesignerName(weapon.Value);
return rifle;
}
public class SkillConfig : Config.DefaultSkillInfo
public class SkillConfig(Skills skill = skillName, bool active = false, string color = "#e0873a", CsTeam onlyTeam = CsTeam.None, bool needsTeammates = false) : Config.DefaultSkillInfo(skill, active, color, onlyTeam, needsTeammates)
{
public SkillConfig(Skills skill = skillName, bool active = false, string color = "#e0873a", CsTeam onlyTeam = CsTeam.None, bool needsTeammates = false) : base(skill, active, color, onlyTeam, needsTeammates)
{
}
}
}
}