diff --git a/CrossCutting/MapLister.cs b/CrossCutting/MapLister.cs index b5cd0a3..d93fe29 100644 --- a/CrossCutting/MapLister.cs +++ b/CrossCutting/MapLister.cs @@ -1,4 +1,6 @@ -using cs2_rockthevote.Core; +using CounterStrikeSharp.API.Modules.Entities; +using cs2_rockthevote.Core; +using CounterStrikeSharp.API.Core; namespace cs2_rockthevote { @@ -58,5 +60,28 @@ public void OnLoad(Plugin plugin) _plugin = plugin; LoadMaps(); } + + // returns "" if there's no matching or if there's more than one + // otherwise, returns the macting name + public string GetSingleMatchingMapName(string map, CCSPlayerController player, StringLocalizer _localizer) + { + var matchingMaps = this.Maps! + .Select(x => x.Name) + .Where(x => x.ToLower().Contains(map.ToLower())) + .ToList(); + + if (matchingMaps.Count == 0) + { + player!.PrintToChat(_localizer.LocalizeWithPrefix("general.invalid-map")); + return ""; + } + else if (matchingMaps.Count > 1) + { + player!.PrintToChat(_localizer.LocalizeWithPrefix("nominate.multiple-maps-containing-name")); + return ""; + } + + return matchingMaps[0]; + } } } diff --git a/Features/NominationCommand.cs b/Features/NominationCommand.cs index 9aca62d..feca335 100644 --- a/Features/NominationCommand.cs +++ b/Features/NominationCommand.cs @@ -118,23 +118,10 @@ void Nominate(CCSPlayerController player, string map) return; } - var matchingMaps = _mapLister.Maps! - .Select(x => x.Name) - .Where(x => x.ToLower().Contains(map.ToLower())) - .ToList(); + string matchingMap = _mapLister.GetSingleMatchingMapName(map, player, _localizer); - if (matchingMaps.Count == 0) - { - player!.PrintToChat(_localizer.LocalizeWithPrefix("general.invalid-map")); + if (matchingMap == "") return; - } - else if (matchingMaps.Count > 1) - { - player!.PrintToChat(_localizer.LocalizeWithPrefix("nominate.multiple-maps-containing-name")); - return; - } - - string matchingMap = matchingMaps[0]; var userId = player.UserId!.Value; if (!Nominations.ContainsKey(userId))