Skip to content

Commit

Permalink
moving the method to respective class
Browse files Browse the repository at this point in the history
  • Loading branch information
exd02 committed Feb 28, 2024
1 parent a56e48e commit 3512ae4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
27 changes: 26 additions & 1 deletion CrossCutting/MapLister.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using cs2_rockthevote.Core;
using CounterStrikeSharp.API.Modules.Entities;
using cs2_rockthevote.Core;
using CounterStrikeSharp.API.Core;

namespace cs2_rockthevote
{
Expand Down Expand Up @@ -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];
}
}
}
17 changes: 2 additions & 15 deletions Features/NominationCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 3512ae4

Please sign in to comment.