Skip to content

Commit

Permalink
v1.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
abnerfs committed Feb 20, 2024
1 parent 288ee9f commit ff2e986
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 27 deletions.
19 changes: 18 additions & 1 deletion Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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;
Expand All @@ -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();
}
}
13 changes: 9 additions & 4 deletions Core/EndMapVoteManager.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -53,6 +51,8 @@ public EndMapVoteManager(MapLister mapLister, ChangeMapManager changeMapManager,
private int _canVote = 0;
private Plugin? _plugin;

HashSet<int> _voted = new();

public void OnLoad(Plugin plugin)
{
_plugin = plugin;
Expand All @@ -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)
Expand Down Expand Up @@ -117,7 +120,7 @@ public void VoteDisplayTick()
stringBuilder.AppendFormat($"<br><font color='yellow'>!{index++}</font> {kv.Key} <font color='green'>({kv.Value})</font>");
}

foreach (CCSPlayerController player in ServerManager.ValidPlayers())
foreach (CCSPlayerController player in ServerManager.ValidPlayers().Where(x => !_voted.Contains(x.UserId!.Value)))
{
player.PrintToCenterHtml(stringBuilder.ToString());
}
Expand Down Expand Up @@ -171,10 +174,12 @@ IList<T> Shuffle<T>(Random rng, IList<T> 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());
Expand Down
4 changes: 2 additions & 2 deletions Features/EndOfMapVote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
26 changes: 18 additions & 8 deletions Features/NextMapCommand.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
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
{
public class NextMapCommand : IPluginDependency<Plugin, Config>
{
private ChangeMapManager _changeMapManager;
private StringLocalizer _stringLocalizer;
private NextmapConfig _config = new();

public NextMapCommand(ChangeMapManager changeMapManager, StringLocalizer stringLocalizer)
{
Expand All @@ -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) {
Expand All @@ -36,5 +41,10 @@ public void OnLoad(Plugin plugin) {
CommandHandler(player);
});
}

public void OnConfigParsed(Config config)
{
_config = config.Nextmap ?? new();
}
}
}
31 changes: 22 additions & 9 deletions Features/TimeLeftCommand.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -23,7 +24,7 @@ public class TimeLeftCommand : IPluginDependency<Plugin, Config>


private StringLocalizer _localizer;

private TimeleftConfig _config = new();

public TimeLeftCommand(TimeLimitManager timeLimitManager, MaxRoundsManager maxRoundsManager, GameRules gameRules, IStringLocalizer stringLocalizer)
{
Expand All @@ -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"));
Expand All @@ -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();
}
}
}
6 changes: 5 additions & 1 deletion Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void ConfigureServices(IServiceCollection serviceCollection)
public partial class Plugin : BasePlugin, IPluginConfig<Config>
{
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";

Expand Down Expand Up @@ -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");

Expand Down
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,17 @@ 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,
"NominationEnabled": true,
"MinPlayers": 0,
"MinRounds": 0,
"ChangeMapImmediatly": true,
"HideHudAfterVote": false,
"MapsToShow": 6,
"VoteDuration": 30,
"VotePercentage": 60,
Expand All @@ -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
}
}
```
Expand Down
3 changes: 3 additions & 0 deletions RockTheVote.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
<None Update="lang\en.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="lang\hu.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="lang\pt-BR.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
40 changes: 40 additions & 0 deletions lang/hu.json
Original file line number Diff line number Diff line change
@@ -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"
}

0 comments on commit ff2e986

Please sign in to comment.