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:
parent
54b265d43d
commit
e33975fe8b
117 changed files with 1532 additions and 1674 deletions
|
|
@ -8,13 +8,17 @@ using System.Reflection;
|
|||
|
||||
namespace jRandomSkills
|
||||
{
|
||||
#pragma warning disable IDE1006 // Style nazewnictwa
|
||||
public partial class jRandomSkills : BasePlugin
|
||||
#pragma warning restore IDE1006 // Style nazewnictwa
|
||||
{
|
||||
#pragma warning disable CS8618 // Pole niedopuszczające wartości null musi zawierać wartość inną niż null podczas kończenia działania konstruktora. Rozważ zadeklarowanie pola jako dopuszczającego wartość null.
|
||||
public static jRandomSkills Instance { get; private set; }
|
||||
#pragma warning restore CS8618 // Pole niedopuszczające wartości null musi zawierać wartość inną niż null podczas kończenia działania konstruktora. Rozważ zadeklarowanie pola jako dopuszczającego wartość null.
|
||||
|
||||
public List<jSkill_PlayerInfo> skillPlayer { get; } = new List<jSkill_PlayerInfo>();
|
||||
public List<jSkill_PlayerInfo> SkillPlayer { get; } = [];
|
||||
public Random Random { get; } = new Random();
|
||||
public CCSGameRules GameRules { get; set; }
|
||||
public CCSGameRules? GameRules { get; set; }
|
||||
|
||||
public override string ModuleName => "[CS2] [ jRandomSkills ]";
|
||||
public override string ModuleAuthor => "D3X, Juzlus";
|
||||
|
|
@ -40,13 +44,15 @@ namespace jRandomSkills
|
|||
if (Config.GetValue<bool>(skill, "active"))
|
||||
SkillAction(skill.ToString()!, "LoadSkill");
|
||||
|
||||
Debug.WriteToDebug($"jRandomSkills v{Instance.ModuleVersion} ({SkillData.Skills.Count - 1}/{Config.config.SkillsInfo.Length - 1} Skills) loaded!");
|
||||
Debug.WriteToDebug($"GameModes: {(Config.GameModes)Config.config.Settings.GameMode}, Lang: {Config.config.Settings.LangCode}");
|
||||
Debug.WriteToDebug($"jRandomSkills v{Instance.ModuleVersion} ({SkillData.Skills.Count - 1}/{Config.LoadedConfig.SkillsInfo.Length - 1} Skills) loaded!");
|
||||
Debug.WriteToDebug($"GameModes: {(Config.GameModes)Config.LoadedConfig.Settings.GameMode}, Lang: {Config.LoadedConfig.Settings.LangCode}");
|
||||
foreach (var skill in SkillData.Skills)
|
||||
Debug.WriteToDebug($"Loaded: {skill.Skill}");
|
||||
}
|
||||
|
||||
internal void SkillAction(string skill, string methodName, object[] param = null)
|
||||
#pragma warning disable CA1822 // Oznaczaj elementy członkowskie jako statyczne
|
||||
internal void SkillAction(string skill, string methodName, object[]? param = null)
|
||||
#pragma warning restore CA1822 // Oznaczaj elementy członkowskie jako statyczne
|
||||
{
|
||||
string className = $"jRandomSkills.{skill}";
|
||||
Type? type = Type.GetType(className);
|
||||
|
|
@ -70,23 +76,27 @@ namespace jRandomSkills
|
|||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
internal void AddCommand(string name, string description, CommandInfo.CommandCallback handler)
|
||||
internal new void AddCommand(string name, string description, CommandInfo.CommandCallback handler)
|
||||
{
|
||||
var definition = new CommandDefinition(name, description, handler);
|
||||
CommandDefinitions.Add(definition);
|
||||
CommandManager.RegisterCommand(definition);
|
||||
}
|
||||
|
||||
internal bool IsPlayerValid(CCSPlayerController player)
|
||||
#pragma warning disable CA1822 // Oznaczaj elementy członkowskie jako statyczne
|
||||
internal bool IsPlayerValid(CCSPlayerController? player)
|
||||
#pragma warning restore CA1822 // Oznaczaj elementy członkowskie jako statyczne
|
||||
{
|
||||
return player != null && player.IsValid && player.PlayerPawn?.Value != null && player.PlayerPawn.Value.LifeState == (byte)LifeState_t.LIFE_ALIVE;
|
||||
return player != null && player.IsValid && player.PlayerPawn?.Value != null && player.PlayerPawn.Value.IsValid && player.PlayerPawn.Value.LifeState == (byte)LifeState_t.LIFE_ALIVE;
|
||||
}
|
||||
|
||||
public uint[] footstepSoundEvents = { 3109879199, 70939233, 1342713723, 2722081556, 1909915699, 3193435079, 2300993891, 3847761506, 4084367249, 1342713723, 3847761506, 2026488395, 2745524735, 2684452812, 2265091453, 1269567645, 520432428, 3266483468, 1346129716, 2061955732, 2240518199, 2829617974, 1194677450, 1803111098, 3749333696, 29217150, 1692050905, 2207486967, 2633527058, 3342414459, 988265811, 540697918, 1763490157, 3755338324, 3161194970, 3753692454, 3166948458, 3997353267, 3161194970, 3753692454, 3166948458, 3997353267, 809738584, 3368720745, 3295206520, 3184465677, 123085364, 3123711576, 737696412, 1403457606, 1770765328, 892882552, 3023174225, 4163677892, 3952104171, 4082928848, 1019414932, 1485322532, 1161855519, 1557420499, 1163426340, 809738584, 3368720745, 2708661994, 2479376962, 3295206520, 1404198078, 1194093029, 1253503839, 2189706910, 1218015996, 96240187, 1116700262, 84876002, 1598540856, 2231399653 };
|
||||
public uint[] silentSoundEvents = { 2551626319, 765706800, 765706800, 2860219006, 2162652424, 2551626319, 2162652424, 117596568, 117596568, 740474905, 1661204257, 3009312615, 1506215040, 115843229, 3299941720, 1016523349, 2684452812, 2067683805, 2067683805, 1016523349, 4160462271, 1543118744, 585390608, 3802757032, 2302139631, 2546391140, 144629619, 4152012084, 4113422219, 1627020521, 2899365092, 819435812, 3218103073, 961838155, 1535891875, 1826799645, 3460445620, 1818046345, 3666896632, 3099536373, 1440734007, 1409986305, 1939055066, 782454593, 4074593561, 1540837791, 3257325156 };
|
||||
public uint[] footstepSoundEvents = [3109879199, 70939233, 1342713723, 2722081556, 1909915699, 3193435079, 2300993891, 3847761506, 4084367249, 1342713723, 3847761506, 2026488395, 2745524735, 2684452812, 2265091453, 1269567645, 520432428, 3266483468, 1346129716, 2061955732, 2240518199, 2829617974, 1194677450, 1803111098, 3749333696, 29217150, 1692050905, 2207486967, 2633527058, 3342414459, 988265811, 540697918, 1763490157, 3755338324, 3161194970, 3753692454, 3166948458, 3997353267, 3161194970, 3753692454, 3166948458, 3997353267, 809738584, 3368720745, 3295206520, 3184465677, 123085364, 3123711576, 737696412, 1403457606, 1770765328, 892882552, 3023174225, 4163677892, 3952104171, 4082928848, 1019414932, 1485322532, 1161855519, 1557420499, 1163426340, 809738584, 3368720745, 2708661994, 2479376962, 3295206520, 1404198078, 1194093029, 1253503839, 2189706910, 1218015996, 96240187, 1116700262, 84876002, 1598540856, 2231399653];
|
||||
public uint[] silentSoundEvents = [2551626319, 765706800, 765706800, 2860219006, 2162652424, 2551626319, 2162652424, 117596568, 117596568, 740474905, 1661204257, 3009312615, 1506215040, 115843229, 3299941720, 1016523349, 2684452812, 2067683805, 2067683805, 1016523349, 4160462271, 1543118744, 585390608, 3802757032, 2302139631, 2546391140, 144629619, 4152012084, 4113422219, 1627020521, 2899365092, 819435812, 3218103073, 961838155, 1535891875, 1826799645, 3460445620, 1818046345, 3666896632, 3099536373, 1440734007, 1409986305, 1939055066, 782454593, 4074593561, 1540837791, 3257325156];
|
||||
}
|
||||
|
||||
#pragma warning disable IDE1006
|
||||
public class jSkill_PlayerInfo
|
||||
#pragma warning restore IDE1006
|
||||
{
|
||||
public required ulong SteamID { get; set; }
|
||||
public required string PlayerName { get; set; }
|
||||
|
|
@ -96,23 +106,16 @@ namespace jRandomSkills
|
|||
public bool IsDrawing { get; set; }
|
||||
}
|
||||
|
||||
public class jSkill_SkillInfo
|
||||
#pragma warning disable IDE1006
|
||||
public class jSkill_SkillInfo(Skills skill, string color, bool display)
|
||||
#pragma warning restore IDE1006
|
||||
{
|
||||
public Skills Skill { get; }
|
||||
public string Name { get; }
|
||||
public string Description { get; }
|
||||
public string Color { get; }
|
||||
public Skills Skill { get; } = skill;
|
||||
public string Name { get; } = Localization.GetTranslation(skill.ToString().ToLower());
|
||||
public string Description { get; } = Localization.GetTranslation($"{skill.ToString().ToLower()}_desc");
|
||||
public string Color { get; } = color;
|
||||
|
||||
public bool Display { get; }
|
||||
|
||||
public jSkill_SkillInfo(Skills skill, string color, bool display)
|
||||
{
|
||||
Skill = skill;
|
||||
Name = Localization.GetTranslation(skill.ToString().ToLower());
|
||||
Description = Localization.GetTranslation($"{skill.ToString().ToLower()}_desc");
|
||||
Color = color;
|
||||
Display = display;
|
||||
}
|
||||
public bool Display { get; } = display;
|
||||
|
||||
public static implicit operator Skills(jSkill_SkillInfo v)
|
||||
{
|
||||
|
|
@ -122,6 +125,6 @@ namespace jRandomSkills
|
|||
|
||||
public static class SkillData
|
||||
{
|
||||
public static List<jSkill_SkillInfo> Skills { get; } = new List<jSkill_SkillInfo>();
|
||||
public static List<jSkill_SkillInfo> Skills { get; } = [];
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue