diff --git a/Config.cs b/Config.cs index cab19e4..85ec767 100644 --- a/Config.cs +++ b/Config.cs @@ -22,6 +22,7 @@ public interface IEndOfMapConfig public bool ChangeMapImmediatly { get; set; } public int VoteDuration { get; set; } public bool HudMenu { get; set; } + public bool HideHudAfterVote { get; set; } } public class EndOfMapConfig : IEndOfMapConfig @@ -31,6 +32,9 @@ public class EndOfMapConfig : IEndOfMapConfig public bool HudMenu { get; set; } = true; public bool ChangeMapImmediatly { get; set; } = false; public int VoteDuration { get; set; } = 30; + public bool HideHudAfterVote { get; set; } = false; + public int TriggerSecondsBeforeEnd { get; set; } = 120; + public int TriggerRoundsBeforEnd { get; set; } = 2; } public class RtvConfig : ICommandConfig, IVoteConfig, IEndOfMapConfig @@ -41,6 +45,7 @@ public class RtvConfig : ICommandConfig, IVoteConfig, IEndOfMapConfig public int MinPlayers { get; set; } = 0; public int MinRounds { get; set; } = 0; public bool ChangeMapImmediatly { get; set; } = true; + public bool HideHudAfterVote { get; set; } = false; public int MapsToShow { get; set; } = 6; public int VoteDuration { get; set; } = 30; public int VotePercentage { get; set; } = 60; @@ -57,12 +62,24 @@ public class VotemapConfig : ICommandConfig, IVoteConfig public int MinRounds { get; set; } = 0; } + public class TimeleftConfig + { + public bool ShowToAll { get; set; } = false; + } + + public class NextmapConfig + { + public bool ShowToAll { get; set; } = false; + } + public class Config : IBasePluginConfig { - public int Version { get; set; } = 8; + public int Version { get; set; } = 9; public RtvConfig Rtv { get; set; } = new(); public VotemapConfig Votemap { get; set; } = new(); public EndOfMapConfig EndOfMapVote { get; set; } = new(); + public TimeleftConfig Timeleft { get; set; } = new(); + public NextmapConfig Nextmap { get; set; } = new(); } } diff --git a/Core/EndMapVoteManager.cs b/Core/EndMapVoteManager.cs index ce142d4..ce6fba1 100644 --- a/Core/EndMapVoteManager.cs +++ b/Core/EndMapVoteManager.cs @@ -1,7 +1,5 @@ using CounterStrikeSharp.API; using CounterStrikeSharp.API.Core; -using CounterStrikeSharp.API.Core.Attributes.Registration; -using CounterStrikeSharp.API.Modules.Commands; using CounterStrikeSharp.API.Modules.Menu; using CounterStrikeSharp.API.Modules.Timers; using System.Data; @@ -53,6 +51,8 @@ public EndMapVoteManager(MapLister mapLister, ChangeMapManager changeMapManager, private int _canVote = 0; private Plugin? _plugin; + HashSet _voted = new(); + public void OnLoad(Plugin plugin) { _plugin = plugin; @@ -69,6 +69,9 @@ public void OnMapStart(string map) public void MapVoted(CCSPlayerController player, string mapName) { + if (_config!.HideHudAfterVote) + _voted.Add(player.UserId!.Value); + Votes[mapName] += 1; player.PrintToChat(_localizer.LocalizeWithPrefix("emv.you-voted", mapName)); if (Votes.Select(x => x.Value).Sum() >= _canVote) @@ -117,7 +120,7 @@ public void VoteDisplayTick() stringBuilder.AppendFormat($"
!{index++} {kv.Key} ({kv.Value})"); } - foreach (CCSPlayerController player in ServerManager.ValidPlayers()) + foreach (CCSPlayerController player in ServerManager.ValidPlayers().Where(x => !_voted.Contains(x.UserId!.Value))) { player.PrintToCenterHtml(stringBuilder.ToString()); } @@ -171,10 +174,12 @@ IList Shuffle(Random rng, IList array) public void StartVote(IEndOfMapConfig config) { Votes.Clear(); + _voted.Clear(); + _pluginState.EofVoteHappening = true; _config = config; int mapsToShow = _config!.MapsToShow == 0 ? MAX_OPTIONS_HUD_MENU : _config!.MapsToShow; - if (config.HudMenu) + if (config.HudMenu && mapsToShow > MAX_OPTIONS_HUD_MENU) mapsToShow = MAX_OPTIONS_HUD_MENU; var mapsScrambled = Shuffle(new Random(), _mapLister.Maps!.Where(x => x != Server.MapName).ToList()); diff --git a/Features/EndOfMapVote.cs b/Features/EndOfMapVote.cs index 3fd2d87..826a252 100644 --- a/Features/EndOfMapVote.cs +++ b/Features/EndOfMapVote.cs @@ -28,13 +28,13 @@ public EndOfMapVote(TimeLimitManager timeLimit, MaxRoundsManager maxRounds, Plug bool CheckMaxRounds() { //Server.PrintToChatAll($"Remaining rounds {_maxRounds.RemainingRounds}, Remaining wins {_maxRounds.RemainingWins}"); - return !_maxRounds.UnlimitedRounds && (_maxRounds.RemainingRounds <= 2 || _maxRounds.RemainingWins <= 2); + return !_maxRounds.UnlimitedRounds && (_maxRounds.RemainingRounds <= 2 || _maxRounds.RemainingWins <= _config.TriggerRoundsBeforEnd); } bool CheckTimeLeft() { - return !_timeLimit.UnlimitedTime && _timeLimit.TimeRemaining <= 120M; + return !_timeLimit.UnlimitedTime && _timeLimit.TimeRemaining <= _config.TriggerSecondsBeforeEnd; } public void StartVote() diff --git a/Features/NextMapCommand.cs b/Features/NextMapCommand.cs index 6e489f7..23da783 100644 --- a/Features/NextMapCommand.cs +++ b/Features/NextMapCommand.cs @@ -1,9 +1,5 @@ -using CounterStrikeSharp.API.Core; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using CounterStrikeSharp.API; +using CounterStrikeSharp.API.Core; namespace cs2_rockthevote.Features { @@ -11,6 +7,7 @@ public class NextMapCommand : IPluginDependency { private ChangeMapManager _changeMapManager; private StringLocalizer _stringLocalizer; + private NextmapConfig _config = new(); public NextMapCommand(ChangeMapManager changeMapManager, StringLocalizer stringLocalizer) { @@ -21,12 +18,20 @@ public NextMapCommand(ChangeMapManager changeMapManager, StringLocalizer stringL public void CommandHandler(CCSPlayerController? player) { if (player is not null) + { + string text; if (_changeMapManager.NextMap is not null) { - player.PrintToChat(_stringLocalizer.LocalizeWithPrefix("nextmap", _changeMapManager.NextMap)); + text = _stringLocalizer.LocalizeWithPrefix("nextmap", _changeMapManager.NextMap); } else - player.PrintToChat(_stringLocalizer.LocalizeWithPrefix("nextmap.decided-by-vote")); + text = _stringLocalizer.LocalizeWithPrefix("nextmap.decided-by-vote"); + + if (_config.ShowToAll) + Server.PrintToChatAll(text); + else + player.PrintToChat(text); + } } public void OnLoad(Plugin plugin) { @@ -36,5 +41,10 @@ public void OnLoad(Plugin plugin) { CommandHandler(player); }); } + + public void OnConfigParsed(Config config) + { + _config = config.Nextmap ?? new(); + } } } diff --git a/Features/TimeLeftCommand.cs b/Features/TimeLeftCommand.cs index d18baea..ecf29a7 100644 --- a/Features/TimeLeftCommand.cs +++ b/Features/TimeLeftCommand.cs @@ -1,4 +1,5 @@ -using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API; +using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Core.Attributes.Registration; using CounterStrikeSharp.API.Modules.Commands; using cs2_rockthevote.Core; @@ -23,7 +24,7 @@ public class TimeLeftCommand : IPluginDependency private StringLocalizer _localizer; - + private TimeleftConfig _config = new(); public TimeLeftCommand(TimeLimitManager timeLimitManager, MaxRoundsManager maxRoundsManager, GameRules gameRules, IStringLocalizer stringLocalizer) { @@ -36,6 +37,8 @@ public TimeLeftCommand(TimeLimitManager timeLimitManager, MaxRoundsManager maxRo public void CommandHandler(CCSPlayerController player) { + string text; + if (_gameRules.WarmupRunning) { player.PrintToChat(_localizer.LocalizeWithPrefix("general.validation.warmup")); @@ -49,33 +52,43 @@ public void CommandHandler(CCSPlayerController player) TimeSpan remaining = TimeSpan.FromSeconds((double)_timeLimitManager.TimeRemaining); if (remaining.Hours > 0) { - player.PrintToChat(_localizer.LocalizeWithPrefix("timeleft.remaining-time-hour", remaining.Hours.ToString("00"), remaining.Minutes.ToString("00"), remaining.Seconds.ToString("00"))); + text = _localizer.LocalizeWithPrefix("timeleft.remaining-time-hour", remaining.Hours.ToString("00"), remaining.Minutes.ToString("00"), remaining.Seconds.ToString("00")); } else if (remaining.Minutes > 0) { - player.PrintToChat(_localizer.LocalizeWithPrefix("timeleft.remaining-time-minute", remaining.Minutes, remaining.Seconds)); + text = _localizer.LocalizeWithPrefix("timeleft.remaining-time-minute", remaining.Minutes, remaining.Seconds); } else { - player.PrintToChat(_localizer.LocalizeWithPrefix("timeleft.remaining-time-second", remaining.Seconds)); + text = _localizer.LocalizeWithPrefix("timeleft.remaining-time-second", remaining.Seconds); } } else { - player.PrintToChat(_localizer.LocalizeWithPrefix("timeleft.time-over")); + text = _localizer.LocalizeWithPrefix("timeleft.time-over"); } } else if (!_maxRoundsManager.UnlimitedRounds) { if (_maxRoundsManager.RemainingRounds > 1) - player.PrintToChat(_localizer.LocalizeWithPrefix("timeleft.remaining-rounds", _maxRoundsManager.RemainingRounds)); + text = _localizer.LocalizeWithPrefix("timeleft.remaining-rounds", _maxRoundsManager.RemainingRounds); else - player.PrintToChat(_localizer.LocalizeWithPrefix("timeleft.last-round")); + text = _localizer.LocalizeWithPrefix("timeleft.last-round"); } else { - player.PrintToChat(_localizer.LocalizeWithPrefix("timeleft.no-time-limit")); + text = _localizer.LocalizeWithPrefix("timeleft.no-time-limit"); } + + if (_config.ShowToAll) + Server.PrintToChatAll(text); + else + player.PrintToChat(text); + } + + public void OnConfigParsed(Config config) + { + _config = config.Timeleft ?? new(); } } } diff --git a/Plugin.cs b/Plugin.cs index a0c8ab5..9446d0c 100644 --- a/Plugin.cs +++ b/Plugin.cs @@ -21,7 +21,7 @@ public void ConfigureServices(IServiceCollection serviceCollection) public partial class Plugin : BasePlugin, IPluginConfig { public override string ModuleName => "RockTheVote"; - public override string ModuleVersion => "1.5.1"; + public override string ModuleVersion => "1.6.0"; public override string ModuleAuthor => "abnerfs"; public override string ModuleDescription => "General purpose map voting plugin"; @@ -99,6 +99,10 @@ public HookResult OnChat(EventPlayerChat @event, GameEventInfo info) public void OnConfigParsed(Config config) { Config = config; + + if (Config.Version < 9) + Console.WriteLine("[RockTheVote] please delete it from addons/counterstrikesharp/configs/plugins/RockTheVote and let the plugin recreate it on load"); + if (Config.Version < 7) throw new Exception("Your config file is too old, please delete it from addons/counterstrikesharp/configs/plugins/RockTheVote and let the plugin recreate it on load"); diff --git a/README.md b/README.md index b3a9661..e4ef88d 100644 --- a/README.md +++ b/README.md @@ -48,8 +48,9 @@ Players can type `nextmap` to see which map is going to be played next - Changes in the config file will require you to reload the plugin or restart the server (change the map won't work). ```json +// This configuration was automatically generated by CounterStrikeSharp for plugin 'RockTheVote', at 2024/02/19 10:46:54 { - "Version": 8, + "Version": 9, "Rtv": { "Enabled": true, "EnabledInWarmup": true, @@ -57,6 +58,7 @@ Players can type `nextmap` to see which map is going to be played next "MinPlayers": 0, "MinRounds": 0, "ChangeMapImmediatly": true, + "HideHudAfterVote": false, "MapsToShow": 6, "VoteDuration": 30, "VotePercentage": 60, @@ -75,7 +77,16 @@ Players can type `nextmap` to see which map is going to be played next "MapsToShow": 6, "HudMenu": true, "ChangeMapImmediatly": false, - "VoteDuration": 30 + "VoteDuration": 30, + "HideHudAfterVote": false, + "TriggerSecondsBeforeEnd": 120, + "TriggerRoundsBeforEnd": 2 + }, + "Timeleft": { + "ShowToAll": false + }, + "Nextmap": { + "ShowToAll": false } } ``` diff --git a/RockTheVote.csproj b/RockTheVote.csproj index 8b55192..0a0ba47 100644 --- a/RockTheVote.csproj +++ b/RockTheVote.csproj @@ -20,6 +20,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest diff --git a/lang/hu.json b/lang/hu.json new file mode 100644 index 0000000..a36cbf9 --- /dev/null +++ b/lang/hu.json @@ -0,0 +1,40 @@ +{ + "rtv.prefix": "{red}[RTV]{default}", + "votemap.prefix": "{red}[Votemap]{default}", + "timeleft.prefix": "{red}[Timeleft]{default}", + "timeleft.remaining-rounds": "{0} kör maradt ezen a pályán", + "timeleft.remaining-time-hour": "Fennmaradó idő {0}:{1}:{2}", + "timeleft.remaining-time-minute": "Fennmaradó idő {0} perc és {1} másodperc", + "timeleft.remaining-time-second": "Fennmaradó idő {0} másodperc", + "timeleft.no-time-limit": "Nincs időkorlát", + "timeleft.last-round": "Ez az utolsó kör", + "timeleft.time-over": "Az idő lejárt, ez az utolsó kör", + "votemap.player-voted": "{green}{0}{default} erre a pályára szavazott: {green}{1}{default}", + "votemap.already-voted": "Már szavaztál erre a pályára: {green}{0}{default}", + "votemap.in-the-map": "ezen a pályán: {0}", + "votemap.changing-map": "Pályaváltás ide: {green}{0}", + "votemap.changing-map-next-round": "A pálya el lesz váltva ide: {green}{0}{default} a következő körben...", + "general.votes-needed": "({0} szavazott, {1} szükséges)", + "general.invalid-map": "Érvénytelen pálya", + "nominate.nominated": "{green}{0}{default} ezt a pályát ajánlotta: {green}{1}{default}, jelenleg {2} szavazata van", + "nominate.already-nominated": "Már ajánlottad ezt a pályát: {green}{0}{default}, jelenleg {1} szavazata van", + "general.validation.current-map": "A jelenlegi pályát nem tudod kiválasztani", + "general.validation.minimum-rounds": "Ehhez a parancshoz a minimum körök száma: {0}", + "general.validation.warmup": "Bemelegítés alatt nem használható ez a parancs.", + "general.validation.minimum-players": "A minimum játékosszám ehhez a parancshoz: {0}", + "general.validation.disabled": "Jelenleg nincs engedélyezve ez a parancs", + "rtv.rocked-the-vote": "{green}{0}{default} pályaszavazást szeretne", + "rtv.already-rocked-the-vote": "Már kértél pályaszavazást", + "rtv.votes-reached": "A szükséges szavazatszám elérve, kezdődik a szavazás...", + "rtv.disabled": "Az RTV jelenleg nem használható", + "emv.you-voted": "Erre szavaztál: {0}", + "emv.vote-ended": "A pályaszavazás végetért, a következő pálya: {green}{0}{default} ({1}% / {2} szavazatok)", + "emv.vote-ended-no-votes": "Nincs szavazat, a következő pálya: {green}{0}", + "general.changing-map": "Pályaváltás ide: {green}{0}", + "general.changing-map-next-round": "A pálya el lesz váltva ide: {green}{0}{default} a következő körben...", + "emv.hud.menu-title": "Szavazz a következő pályára:", + "emv.hud.hud-timer": "Szavazz a következő pályára: {0}mp", + "emv.hud.finished": "A szavazás végetért, a köv. pálya: {0}", + "nextmap": "A köv. pálya ez lesz: {green}{0}", + "nextmap.decided-by-vote": "A következő pálya majd az automatikus szavazás útján fog eldőlni" +}