@@ -30,9 +30,7 @@ public enum Status
3030 }
3131
3232 private static readonly Logger Log = LogManager . GetLogger ( "Essentials Voting" ) ;
33- private static readonly Random rnd = new Random ( ) ;
3433 private static AutoCommand _command ;
35- private static readonly int _cooldown = rnd . Next ( 5 , 30 ) ;
3634 private static string voteInProgress ;
3735 private static readonly Dictionary < ulong , DateTime > _voteReg = new Dictionary < ulong , DateTime > ( ) ;
3836 private static readonly Dictionary < ulong , DateTime > _voteCooldown = new Dictionary < ulong , DateTime > ( ) ;
@@ -48,7 +46,10 @@ public enum Status
4846 public void Vote ( string name )
4947 {
5048 if ( Context . Player == null )
49+ {
50+ Context . Respond ( "This is an in-game command" ) ;
5151 return ;
52+ }
5253
5354 if ( VoteStatus == Status . voteInProgress )
5455 {
@@ -57,17 +58,16 @@ public void Vote(string name)
5758 return ;
5859 }
5960
60- _command = EssentialsPlugin . Instance . Config . AutoCommands . FirstOrDefault ( c => ! string . IsNullOrEmpty ( c . Name ) && c . Name . Equals ( name ) ) ;
61+ _command = EssentialsPlugin . Instance . Config . AutoCommands . FirstOrDefault ( c => ! string . IsNullOrEmpty ( c . Name )
62+ && c . CommandTrigger == Trigger . Vote && c . Name . Equals ( name ) ) ;
6163
62- if ( _command == null || _command . CommandTrigger != Trigger . Vote )
64+ if ( _command == null )
6365 {
6466 Context . Respond ( $ "Couldn't find any votable command with the name { name } ") ;
65- _command = null ;
6667 return ;
6768 }
6869
6970
70- // Rexxar's spam blocker. Timing is random as fuck and unique to each player.
7171 var steamid = Context . Player . SteamUserId ;
7272 if ( _voteCooldown . TryGetValue ( steamid , out var activeCooldown ) )
7373 {
@@ -79,15 +79,15 @@ public void Vote(string name)
7979 return ;
8080 }
8181
82- _voteCooldown [ steamid ] = DateTime . Now . AddMinutes ( _cooldown ) ;
82+ _voteCooldown [ steamid ] = DateTime . Now . AddSeconds ( _command . TriggerCount ) ;
8383 }
8484
8585 else
8686 {
87- _voteCooldown . Add ( steamid , DateTime . Now . AddMinutes ( _cooldown ) ) ;
87+ _voteCooldown . Add ( steamid , DateTime . Now . AddSeconds ( _command . TriggerCount ) ) ;
8888 }
8989
90- var _voteDuration = TimeSpan . Parse ( _command . Interval ) ;
90+ var voteDuration = TimeSpan . Parse ( _command . Interval ) ;
9191 // voting status
9292 voteInProgress = name ;
9393 VoteStatus = Status . voteInProgress ;
@@ -99,7 +99,7 @@ public void Vote(string name)
9999 //vote countdown
100100 Task . Run ( ( ) =>
101101 {
102- var countdown = VoteCountdown ( _voteDuration ) . GetEnumerator ( ) ;
102+ var countdown = VoteCountdown ( voteDuration ) . GetEnumerator ( ) ;
103103 while ( countdown . MoveNext ( ) ) Thread . Sleep ( 1000 ) ;
104104 } ) ;
105105
0 commit comments