public static void VoteParams( Player player, Command cmd )
{
string option = cmd.Next();
if ( option == null ) { player.Message( "Invalid param" ); return; }
switch ( option ) {
default:
if ( VoteIsOn ) {
if ( VoteKickReason == null ) {
player.Message( "Last Question: {0}&C asked: {1}", VoteStarter, Question );
player.Message( Usage );
return;
} else
player.Message( "Last VoteKick: &CA VoteKick has started for {0}&C, reason: {1}", TargetName, VoteKickReason );
player.Message( Usage );
return;
} else
player.Message( option );
break;
case "abort":
case "stop":
if ( !VoteIsOn ) {
player.Message( "No vote is currently running" );
return;
}
if ( !player.Can( Permission.MakeVotes ) ) {
player.Message( "You do not have Permission to abort votes" );
return;
}
VoteIsOn = false;
foreach ( Player V in Voted ) {
if ( V.Info.HasVoted )
V.Info.HasVoted = false;
V.Message( "Your vote was cancelled" );
}
Voted.Clear();
TargetName = null;
Server.Players.Message( "{0} &Saborted the vote.", player.ClassyName );
break;
case "yes":
if ( !VoteIsOn ) {
player.Message( "No vote is currently running" );
return;
}
if ( player.Info.HasVoted ) {
player.Message( "&CYou have already voted" );
return;
}
Voted.Add( player );
VotedYes++;
player.Info.HasVoted = true;
player.Message( "&8You have voted for 'Yes'" );
break;
case "kick":
string toKick = cmd.Next();
string Reason = cmd.NextAll();
VoteKickReason = Reason;
if ( toKick == null ) {
player.Message( "Target cannot be empty. " + Usage );
return;
}
Player target = Server.FindPlayerOrPrintMatches( player, toKick, false, true );
if ( target == null ) {
// FIX: Target is null when no such player is online, this caused crashes
return;
}
if ( !Player.IsValidName( target.Name ) ) {
return;
}
if ( !player.Can( Permission.MakeVoteKicks ) ) {
player.Message( "You do not have permissions to start a VoteKick" );
return;
}
if ( VoteIsOn ) {
player.Message( "A vote has already started. Each vote lasts 1 minute." );
return;
}
if ( VoteKickReason.Length < 3 ) {
player.Message( "Invalid reason" );
return;
}
if ( target == player ) {
player.Message( "You cannot VoteKick yourself, lol" );
return;
}
VoteThread = new Thread( new ThreadStart( delegate {
TargetName = target.Name;
if ( !Player.IsValidName( TargetName ) ) {
player.Message( "Invalid name" );
return;
}
NewVote();
VoteStarter = player.ClassyName;
Server.Players.Message( "{0}&S started a VoteKick for player: {1}", player.ClassyName, target.ClassyName );
Server.Players.Message( "&WReason: {0}", VoteKickReason );
Server.Players.Message( "&9Vote now! &S/Vote &AYes &Sor /Vote &CNo" );
VoteIsOn = true;
Logger.Log( LogType.SystemActivity, "{0} started a votekick on player {1} reason: {2}", player.Name, target.Name, VoteKickReason );
Thread.Sleep( 60000 );
VoteKickCheck();
} ) );
VoteThread.Start();
break;
case "no":
if ( !VoteIsOn ) {
player.Message( "No vote is currently running" );
return;
}
if ( player.Info.HasVoted ) {
player.Message( "&CYou have already voted" );
return;
}
VotedNo++;
Voted.Add( player );
player.Info.HasVoted = true;
player.Message( "&8You have voted for 'No'" );
break;
case "ask":
string AskQuestion = cmd.NextAll();
Question = AskQuestion;
if ( !player.Can( Permission.MakeVotes ) ) {
player.Message( "You do not have permissions to ask a question" );
return;
}
if ( VoteIsOn ) {
player.Message( "A vote has already started. Each vote lasts 1 minute." );
return;
}
if ( Question.Length < 5 ) {
player.Message( "Invalid question" );
return;
}
VoteThread = new Thread( new ThreadStart( delegate {
NewVote();
VoteStarter = player.ClassyName;
Server.Players.Message( "{0}&S Asked: {1}", player.ClassyName, Question );
Server.Players.Message( "&9Vote now! &S/Vote &AYes &Sor /Vote &CNo" );
VoteIsOn = true;
Thread.Sleep( 60000 );
VoteCheck();
} ) );
VoteThread.Start();
break;
}
}