本文整理汇总了C#中fCraft.Events.ChatSendingEventArgs类的典型用法代码示例。如果您正苦于以下问题:C# ChatSendingEventArgs类的具体用法?C# ChatSendingEventArgs怎么用?C# ChatSendingEventArgs使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ChatSendingEventArgs类属于fCraft.Events命名空间,在下文中一共展示了ChatSendingEventArgs类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendWorld
/// <summary> Sends world/local chat message. </summary>
/// <param name="player"> Player writing the message. </param>
/// <param name="rawMessage"> Message text. </param>
/// <returns> True if message was sent, false if it was canceled by an event callback. </returns>
/// <exception cref="ArgumentNullException"> If player or rawMessage is null. </exception>
public static bool SendWorld( [NotNull] Player player, [NotNull] string rawMessage ) {
if( player == null ) throw new ArgumentNullException( "player" );
if( rawMessage == null ) throw new ArgumentNullException( "rawMessage" );
World playerWorld = player.World;
if( playerWorld == null ) PlayerOpException.ThrowNoWorld( player );
var recipientList = playerWorld.Players
.NotIgnoring( player );
string formattedMessage = String.Format( "({0}&F){1}: {2}",
playerWorld.ClassyName,
player.ClassyName,
rawMessage );
var e = new ChatSendingEventArgs( player,
rawMessage,
formattedMessage,
ChatMessageType.World,
recipientList );
if( !SendInternal( e ) ) return false;
Logger.Log( LogType.GlobalChat,
"(world {0}){1}: {2}",
playerWorld.Name, player.Name, rawMessage );
return true;
}
示例2: ChatSending
public static void ChatSending( object sender, ChatSendingEventArgs e )
{
if ( e.MessageType == ChatMessageType.Global ) {
if ( e.Message == null )
return;
if ( e.Player == null )
return;
//Parse greentext
if ( e.Message.Length > 1 && e.MessageType == ChatMessageType.Global ) {
if ( e.Message.StartsWith( ">" ) && e.Message[1] != ' ' ) {
e.FormattedMessage = String.Format( "{0}&F: {1}{2}", e.Player.ClassyName, Color.Lime, e.Message );
return;
}
}
//Parse all others
string Message = e.Message; //use only e.Message so you don't accidentally highlight user names ect
Message = HighlightSections( Message );
e.FormattedMessage = String.Format( "{0}&F: {1}", e.Player.ClassyName, Message ); //reformat the message
}
}
示例3: SendPM
/// <summary> Sends a private message (PM). Does NOT send a copy of the message to the sender. </summary>
/// <param name="from"> Sender player. </param>
/// <param name="to"> Recepient player. </param>
/// <param name="rawMessage"> Message text. </param>
/// <returns> True if message was sent, false if it was cancelled by an event callback. </returns>
public static bool SendPM( [NotNull] Player from, [NotNull] Player to, [NotNull] string rawMessage ) {
if( from == null ) throw new ArgumentNullException( "from" );
if( to == null ) throw new ArgumentNullException( "to" );
if( rawMessage == null ) throw new ArgumentNullException( "rawMessage" );
var recepientList = new[] { to };
string formattedMessage = String.Format( "&Pfrom {0}: {1}",
from.Name, rawMessage );
var e = new ChatSendingEventArgs( from,
rawMessage,
formattedMessage,
ChatMessageType.PM,
recepientList );
if( !SendInternal( e ) ) return false;
Logger.Log( LogType.PrivateChat,
"{0} to {1}: {2}",
from.Name, to.Name, rawMessage );
return true;
}
示例4: SendMe
/// <summary> Sends an action message (/Me). </summary>
/// <param name="player"> Player writing the message. </param>
/// <param name="rawMessage"> Message text. </param>
/// <returns> True if message was sent, false if it was cancelled by an event callback. </returns>
public static bool SendMe( [NotNull] Player player, [NotNull] string rawMessage ) {
if( player == null ) throw new ArgumentNullException( "player" );
if( rawMessage == null ) throw new ArgumentNullException( "rawMessage" );
var recepientList = Server.Players.NotIgnoring( player );
string formattedMessage = String.Format( "&M*{0} {1}",
player.Name,
rawMessage );
var e = new ChatSendingEventArgs( player,
rawMessage,
formattedMessage,
ChatMessageType.Me,
recepientList );
if( !SendInternal( e ) ) return false;
Logger.Log( LogType.GlobalChat,
"(me){0}: {1}", player.Name, rawMessage );
return true;
}
示例5: SendGlobal
/// <summary> Sends a global (white) chat. </summary>
/// <param name="player"> Player writing the message. </param>
/// <param name="rawMessage"> Message text. </param>
/// <returns> True if message was sent, false if it was cancelled by an event callback. </returns>
public static bool SendGlobal([NotNull] Player player, [NotNull] string rawMessage)
{
if (player == null) throw new ArgumentNullException("player");
if (rawMessage == null) throw new ArgumentNullException("rawMessage");
rawMessage = rawMessage.Replace("$motd", ConfigKey.MOTD.GetString());
rawMessage = rawMessage.Replace("$time", DateTime.Now.ToString()); //used to test env realistic
var recepientList = Server.Players.NotIgnoring(player);
// Check caps
if (!player.Can(Permission.ChatWithCaps))
{
int caps = 0;
for (int i = 0; i < rawMessage.Length; i++)
{
if (Char.IsUpper(rawMessage[i]))
{
caps++;
if (caps > ConfigKey.MaxCaps.GetInt())
{
rawMessage = rawMessage.ToLower();
player.Message("Your message was changed to lowercase as it exceeded the maximum amount of capital letters.");
}
}
}
}
if (player.IsStaticStaff)
{
recepientList = Server.Players.Can(Permission.ReadStaffChat)
.NotIgnoring(player)
.Union(player);
rawMessage = rawMessage.Replace(rawMessage, "&P(staff)" + player.ClassyName + "&P: " + rawMessage);
}
// Swear filter
if (!player.Can(Permission.Swear))
{
if (!File.Exists("SwearWords.txt"))
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("#This txt file should be filled with bad words that you want to be filtered out");
sb.AppendLine("#I have included some examples, excuse my language :P");
sb.AppendLine("fuck");
sb.AppendLine("fucking");
sb.AppendLine("fucked");
sb.AppendLine("dick");
sb.AppendLine("bitch");
sb.AppendLine("shit");
sb.AppendLine("shitting");
sb.AppendLine("shithead");
sb.AppendLine("cunt");
sb.AppendLine("nigger");
sb.AppendLine("wanker");
sb.AppendLine("wank");
sb.AppendLine("wanking");
sb.AppendLine("piss");
File.WriteAllText("SwearWords.txt", sb.ToString());
}
string CensoredText = Color.ReplacePercentCodes(ConfigKey.SwearReplace.GetString())+"&F";
if (ConfigKey.SwearReplace.GetString() == null)
{
CensoredText = "&CBlock&F";
}
const string PatternTemplate = @"\b({0})(s?)\b";
const RegexOptions Options = RegexOptions.IgnoreCase;
if (Swears.Count == 0)
{
Swears.AddRange(File.ReadAllLines("SwearWords.txt").Where(line => line.StartsWith("#") == false || line.Trim().Equals(String.Empty)));
}
if (badWordMatchers == null)
{
badWordMatchers = Swears.
Select(x => new Regex(string.Format(PatternTemplate, x), Options));
}
string output = badWordMatchers.
Aggregate(rawMessage, (current, matcher) => matcher.Replace(current, CensoredText));
rawMessage = output;
}
string formattedMessage = String.Format("{0}&F: {1}",
player.ClassyName,
rawMessage);
var e = new ChatSendingEventArgs(player,
rawMessage,
formattedMessage,
ChatMessageType.Global,
recepientList);
//.........这里部分代码省略.........
示例6: SendGlobal
/// <summary> Sends a global (white) chat. </summary>
/// <param name="player"> Player writing the message. </param>
/// <param name="rawMessage"> Message text. </param>
/// <returns> True if message was sent, false if it was cancelled by an event callback. </returns>
public static bool SendGlobal( [NotNull] Player player, [NotNull] string rawMessage ) {
if( player == null ) throw new ArgumentNullException( "player" );
if( rawMessage == null ) throw new ArgumentNullException( "rawMessage" );
string OriginalMessage = rawMessage;
if (Server.Moderation && !Server.VoicedPlayers.Contains(player) && player.World != null)
{
player.Message("&WError: Server Moderation is activated. Message failed to send");
return false;
}
rawMessage = rawMessage.Replace("$name", "Hello my name is " + player.ClassyName);
rawMessage = rawMessage.Replace("$kicks", "I have kicked " + player.Info.TimesKickedOthers.ToString() + " players.");
rawMessage = rawMessage.Replace("$bans", "I have banned " + player.Info.TimesBannedOthers.ToString() + " players.");
rawMessage = rawMessage.Replace("$awesome", "It is my professional opinion, that " + ConfigKey.ServerName.GetString() + " is the best server on Minecraft");
rawMessage = rawMessage.Replace("$server", ConfigKey.ServerName.GetString());
rawMessage = rawMessage.Replace("$motd", ConfigKey.MOTD.GetString());
rawMessage = rawMessage.Replace("$date", DateTime.UtcNow.ToShortDateString());
rawMessage = rawMessage.Replace("$time", DateTime.Now.ToString());
if (!player.Can(Permission.ChatWithCaps))
{
int caps = 0;
for (int i = 0; i < rawMessage.Length; i++)
{
if (Char.IsUpper(rawMessage[i]))
{
caps++;
if (caps > ConfigKey.MaxCaps.GetInt())
{
rawMessage = rawMessage.ToLower();
player.Message("Your message was changed to lowercase as it exceeded the maximum amount of capital letters.");
}
}
}
}
if (!player.Can(Permission.Swear))
{
if (!File.Exists("SwearWords.txt"))
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("#This txt file should be filled with bad words that you want to be filtered out");
sb.AppendLine("#I have included some examples, excuse my language :P");
sb.AppendLine("fuck");
sb.AppendLine("fucking");
sb.AppendLine("fucked");
sb.AppendLine("dick");
sb.AppendLine("bitch");
sb.AppendLine("shit");
sb.AppendLine("shitting");
sb.AppendLine("shithead");
sb.AppendLine("cunt");
sb.AppendLine("nigger");
sb.AppendLine("wanker");
sb.AppendLine("wank");
sb.AppendLine("wanking");
sb.AppendLine("piss");
File.WriteAllText("SwearWords.txt", sb.ToString());
}
string CensoredText = Color.ReplacePercentCodes(ConfigKey.SwearName.GetString()) + Color.White;
if (ConfigKey.SwearName.GetString() == null)
{
CensoredText = "&CBlock&F";
}
const string PatternTemplate = @"\b({0})(s?)\b";
const RegexOptions Options = RegexOptions.IgnoreCase;
if (Swears.Count == 0)
{
Swears.AddRange(File.ReadAllLines("SwearWords.txt").
Where(line => line.StartsWith("#") == false || line.Trim().Equals(String.Empty)));
}
if (badWordMatchers == null)
{
badWordMatchers = Swears.
Select(x => new Regex(string.Format(PatternTemplate, x), Options));
}
string output = badWordMatchers.
Aggregate(rawMessage, (current, matcher) => matcher.Replace(current, CensoredText));
rawMessage = output;
}
var recepientList = Server.Players.NotIgnoring(player);
string formattedMessage = String.Format( "{0}&F: {1}",
player.ClassyName,
rawMessage );
var e = new ChatSendingEventArgs( player,
rawMessage,
formattedMessage,
ChatMessageType.Global,
recepientList );
//.........这里部分代码省略.........
示例7: SendSay
/// <summary> Sends a global announcement (/Say). </summary>
/// <param name="player"> Player writing the message. </param>
/// <param name="rawMessage"> Message text. </param>
/// <returns> True if message was sent, false if it was cancelled by an event callback. </returns>
public static bool SendSay( [NotNull] Player player, [NotNull] string rawMessage ) {
if( player == null ) throw new ArgumentNullException( "player" );
if( rawMessage == null ) throw new ArgumentNullException( "rawMessage" );
var recepientList = Server.Players;
string formattedMessage = Color.Say + rawMessage;
var e = new ChatSendingEventArgs( player,
rawMessage,
formattedMessage,
ChatMessageType.Say,
recepientList );
if( !SendInternal( e ) ) return false;
Logger.Log( LogType.GlobalChat,
"(say){0}: {1}", player.Name, rawMessage );
return true;
}
示例8: RaiseSentEvent
static void RaiseSentEvent( ChatSendingEventArgs args, int count )
{
var h = Sent;
if( h != null ) h( null, new ChatSentEventArgs( args.Player, args.Message, args.FormattedMessage,
args.MessageType, args.RecepientList, count ) );
}
示例9: IRCSendStaff
/// <summary> Sends a staff message from irc (!St). </summary>
/// <param name="player"> Player writing the message. </param>
/// <param name="rawMessage"> Message text. </param>
/// <returns> True if message was sent, false if it was cancelled by an event callback. </returns>
public static bool IRCSendStaff([NotNull] string player, [NotNull] string rawMessage)
{
if (player == null) throw new ArgumentNullException("player");
if (rawMessage == null) throw new ArgumentNullException("rawMessage");
var recipientList = Server.Players.Can(Permission.ReadStaffChat).Where(p => p.Info.ReadIRC == true);
string formattedMessage = String.Format("&P(IRC+staff)&5(IRC){0}&P: {1}",
player,
rawMessage);
var e = new ChatSendingEventArgs( Player.Console,
rawMessage,
formattedMessage,
ChatMessageType.Staff,
recipientList);
if (!SendInternal(e)) return false;
IRC.SendChannelMessage("\u211C\u212C(IRC+Staff)(IRC)\u211C" + player + ": " + rawMessage);
Logger.Log(LogType.GlobalChat,
"(IRC+staff)(IRC){0}: {1}",
player,
rawMessage);
return true;
}
示例10: SendIRCStaff
/// <summary> Sends a staff message (/IRCStaff). </summary>
/// <param name="player"> Player writing the message. </param>
/// <param name="rawMessage"> Message text. </param>
/// <returns> True if message was sent, false if it was cancelled by an event callback. </returns>
public static bool SendIRCStaff([NotNull] Player player, [NotNull] string rawMessage)
{
if (player == null) throw new ArgumentNullException("player");
if (rawMessage == null) throw new ArgumentNullException("rawMessage");
var recipientList = Server.Players.Can(Permission.ReadStaffChat)
.NotIgnoring(player)
.Union(player);
string formattedMessage = String.Format("&P(IRC+staff){0}&P: {1}",
player.Name,
rawMessage);
var e = new ChatSendingEventArgs(player,
rawMessage,
formattedMessage,
ChatMessageType.Staff,
recipientList);
IRC.SendChannelMessage("\u212C(IRC+Staff)\u211C" + player.Name + ": " + rawMessage);
if (!SendInternal(e)) return false;
Logger.Log(LogType.GlobalChat,
"(IRC+staff){0}: {1}",
player.Name,
rawMessage);
return true;
}
示例11: SendStaffSay
/// <summary> Sends a global announcement to staff (/StaffSay). </summary>
/// <param name="player"> Player writing the message. </param>
/// <param name="rawMessage"> Message text. </param>
/// <returns> True if message was sent, false if it was cancelled by an event callback. </returns>
public static bool SendStaffSay([NotNull] Player player, [NotNull] string rawMessage) {
if (player == null)
throw new ArgumentNullException("player");
if (rawMessage == null)
throw new ArgumentNullException("rawMessage");
var recepientList = Server.Players.Where(p => p.Info.Rank != RankManager.HighestRank).Can(Permission.ReadStaffChat);
string formattedMessage = Color.Say + rawMessage;
var e = new ChatSendingEventArgs(player, rawMessage, formattedMessage, ChatMessageType.Staff, recepientList);
if (!SendInternal(e))
return false;
var recepientListOwner = Server.Players.Where(p => p.Info.Rank == RankManager.HighestRank);
string formattedMessageOwner = "&s[&yStaffSay&s][&f" + player.Name + "&s] &Y" + rawMessage;
var eo = new ChatSendingEventArgs(player, rawMessage, formattedMessageOwner, ChatMessageType.StaffSayOwner, recepientListOwner);
if (!SendInternal(eo))
return false;
Logger.Log(LogType.GlobalChat, "(staff_say){0}: {1}", player.Name, rawMessage);
return true;
}
示例12: SendSay
/// <summary> Sends a global announcement (/Say). </summary>
/// <param name="player"> Player writing the message. </param>
/// <param name="rawMessage"> Message text. </param>
/// <returns> True if message was sent, false if it was cancelled by an event callback. </returns>
public static bool SendSay([NotNull] Player player, [NotNull] string rawMessage) {
if (player == null)
throw new ArgumentNullException("player");
if (rawMessage == null)
throw new ArgumentNullException("rawMessage");
var recepientList = Server.Players.Where(p => !p.IsStaff);
string formattedMessage = Color.Say + rawMessage;
var e = new ChatSendingEventArgs(player, rawMessage, formattedMessage, ChatMessageType.Say, recepientList);
if (!SendInternal(e))
return false;
var recepientListStaff = Server.Players.Can(Permission.ReadStaffChat);
string formattedMessageStaff = "&s[&YSay&s][&f" + player.Name + "&s] &Y" + rawMessage;
var es = new ChatSendingEventArgs(player, rawMessage, formattedMessageStaff, ChatMessageType.SayStaff, recepientListStaff);
if (!SendInternal(es))
return false;
Logger.Log(LogType.GlobalChat,
"(say){0}: {1}", player.Name, rawMessage);
return true;
}
示例13: SendGlobal
//.........这里部分代码省略.........
sb.AppendLine("#This txt file should be filled with bad words that you want to be filtered out");
sb.AppendLine("#I have included some examples, excuse my language :P");
sb.AppendLine("fuck");
sb.AppendLine("fucking");
sb.AppendLine("fucked");
sb.AppendLine("dick");
sb.AppendLine("bitch");
sb.AppendLine("shit");
sb.AppendLine("shitting");
sb.AppendLine("shithead");
sb.AppendLine("cunt");
sb.AppendLine("nigger");
sb.AppendLine("wanker");
sb.AppendLine("wank");
sb.AppendLine("wanking");
sb.AppendLine("piss");
File.WriteAllText("SwearWords.txt", sb.ToString());
}
string CensoredText = Color.ReplacePercentCodes(ConfigKey.SwearName.GetString()) + Color.White;
if (ConfigKey.SwearName.GetString() == null)
{
CensoredText = "&CBlock&F";
}
const string PatternTemplate = @"\b({0})(s?)\b";
const RegexOptions Options = RegexOptions.IgnoreCase;
if (Swears.Count == 0)
{
Swears.AddRange(File.ReadAllLines("SwearWords.txt").
Where(line => line.StartsWith("#") == false || line.Trim().Equals(String.Empty)));
}
if (badWordMatchers == null)
{
badWordMatchers = Swears.
Select(x => new Regex(string.Format(PatternTemplate, x), Options));
}
string output = badWordMatchers.
Aggregate(rawMessage, (current, matcher) => matcher.Replace(current, CensoredText));
rawMessage = output;
}
/*if (player.World != null)
{
if (player.World.GameOn)
{
if (Games.MineChallenge.mode == Games.MineChallenge.GameMode.math1)
{
if (rawMessage == Games.MineChallenge.answer.ToString() && !Games.MineChallenge.completed.Contains(player))
{
Games.MineChallenge.completed.Add(player);
player.Message("&8Correct!");
if (player.World.blueTeam.Contains(player)) player.World.blueScore++;
else player.World.redScore++;
}
else
{
player.Message("&8Incorrect");
}
return false;
}
if (Games.MineChallenge.mode == Games.MineChallenge.GameMode.math2)
{
if (rawMessage == Games.MineChallenge.answer.ToString() && !Games.MineChallenge.completed.Contains(player))
{
Games.MineChallenge.completed.Add(player);
player.Message("&8Correct!");
if (player.World.blueTeam.Contains(player)) player.World.blueScore++;
else player.World.redScore++;
}
else
{
player.Message("&8Incorrect");
}
return false;
}
}
}*/
var recepientList = Server.Players.NotIgnoring(player); if (player.World.WorldOnlyChat) recepientList = player.World.Players.NotIgnoring(player);
string formattedMessage = String.Format( "{0}&F: {1}",
player.ClassyName,
rawMessage );
var e = new ChatSendingEventArgs( player,
rawMessage,
formattedMessage,
ChatMessageType.Global,
recepientList );
if( !SendInternal( e ) ) return false;
Logger.Log( LogType.GlobalChat,
"{0}: {1}", player.Name, OriginalMessage );
return true;
}
示例14: ChatSentEventArgs
internal ChatSentEventArgs( ChatSendingEventArgs e, int recipientCount ) {
Player = e.Player;
Message = e.Message;
MessageType = e.MessageType;
RecipientList = e.RecipientList;
FormattedMessage = e.FormattedMessage;
RecipientCount = recipientCount;
}
示例15: SendRank
/// <summary> Sends a rank-wide message (@@Rank message). </summary>
/// <param name="player"> Player writing the message. </param>
/// <param name="rank"> Target rank. </param>
/// <param name="rawMessage"> Message text. </param>
/// <returns> True if message was sent, false if it was cancelled by an event callback. </returns>
public static bool SendRank( [NotNull] Player player, [NotNull] Rank rank, [NotNull] string rawMessage )
{
if( player == null ) throw new ArgumentNullException( "player" );
if( rank == null ) throw new ArgumentNullException( "rank" );
if( rawMessage == null ) throw new ArgumentNullException( "rawMessage" );
var recepientList = rank.Players.NotIgnoring( player ).Union( player );
string formattedMessage = String.Format( "&P({0}&P){1}: {2}",
rank.ClassyName,
player.Name,
rawMessage );
var e = new ChatSendingEventArgs( player,
rawMessage,
formattedMessage,
ChatMessageType.Rank,
recepientList );
if( !SendInternal( e ) ) return false;
Logger.Log( LogType.RankChat,
"(rank {0}){1}: {2}",
rank.Name, player.Name, rawMessage );
return true;
}