public void Mute( [NotNull] Player player, TimeSpan duration, bool announce, bool raiseEvents )
{
if ( player == null )
throw new ArgumentNullException( "player" );
if ( duration <= TimeSpan.Zero ) {
throw new ArgumentException( "Mute duration may not be zero or negative.", "duration" );
}
// Check if player is trying to mute self
if ( player.Info == this ) {
PlayerOpException.ThrowCannotTargetSelf( player, this, "mute" );
}
lock ( actionLock ) {
// Check if player can mute in general
if ( !player.Can( Permission.Mute ) ) {
PlayerOpException.ThrowPermissionMissing( player, this, "mute", Permission.Mute );
}
// Check if player has sufficient rank permissions
if ( !player.Can( Permission.Mute, Rank ) ) {
PlayerOpException.ThrowPermissionLimit( player, this, "mute", Permission.Mute );
}
// Check if target is already muted for longer
DateTime newMutedUntil = DateTime.UtcNow.Add( duration );
if ( newMutedUntil > MutedUntil ) {
// raise PlayerInfo.MuteChanging event
if ( raiseEvents ) {
if ( RaiseMuteChangingEvent( this, player, duration, false, announce ) ) {
PlayerOpException.ThrowCancelled( player, this );
}
}
// actually mute
MutedUntil = newMutedUntil;
MutedBy = player.Name;
LastModified = DateTime.UtcNow;
// raise PlayerInfo.MuteChanged event
if ( raiseEvents ) {
RaiseMuteChangedEvent( this, player, duration, false, announce );
}
// log and announce mute publicly
Logger.Log( LogType.UserActivity,
"Player {0} was muted by {1} for {2}",
Name, player.Name, duration );
if ( announce ) {
Player target = PlayerObject;
if ( target != null ) {
target.Message( "You were muted by {0}&S for {1}",
player.ClassyName, duration.ToMiniString() );
}
Server.Message( target,
"&SPlayer {0}&S was muted by {1}&S for {2}",
ClassyName, player.ClassyName, duration.ToMiniString() );
}
} else {
// no action needed - already muted for same or longer duration
string msg = String.Format( "Player {0} was already muted by {1} ({2} left)",
ClassyName, MutedBy,
TimeMutedLeft.ToMiniString() );
string colorMsg = String.Format( "&SPlayer {0}&S was already muted by {1}&S ({2} left)",
ClassyName, MutedByClassy,
TimeMutedLeft.ToMiniString() );
throw new PlayerOpException( player, this, PlayerOpExceptionCode.NoActionNeeded, msg, colorMsg );
}
}
}