private async ValueTask <bool> HandleSendChat(ClientPlayer sender, string message) { var @event = new PlayerChatEvent(Game, sender, this, message); await _eventManager.CallAsync(@event); return([email protected]); }
private void Network_SendUserMessage(Identity sender, string msg) { if (msg.StartsWith(sender.GetUser().Player.CommandPrefix)) { if (msg.Length == 1) { return; } var cmdLine = msg.Substring(1).Trim(); var cmdName = cmdLine.Split(' ')[0]; CommandManager.Instance.Eval(sender.GetUser().Player, cmdName, cmdLine); return; } PlayerChatEvent @event = new PlayerChatEvent(sender.Owner.Player); @event.Message = msg; @event.Format = "<color=yellow>{NAME}</color>: {MESSAGE}"; EventManager.Instance.CallEvent(@event); if (@event.IsCancelled) { return; } Regex.Replace(msg, @"({\p{Lu}.})", ""); // {UPPERCASE} is reserved and may not be used by players var userName = sender.GetUser().Name; string formattedMsg = @event.Format.Replace("{NAME}", userName).Replace("{MESSAGE}", @event.Message); Channel.Send(nameof(Network_ReceiveMessage), ECall.All, sender, formattedMsg); }
static void ClassicServer_PrePacketEvent(object sender, LibMinecraft.Classic.Server.PrePacketEventArgs e) { PlayerChatEvent args = null; if (e.Packet.PacketID == PacketID.Message) { e.Packet.ReadPacket(e.Client); args = new PlayerChatEvent(e.Client, ((MessagePacket)e.Packet).Message); } EventCache.Call(args); if (args.IsCancelled) { MCForgeServer.ClassicServer.cancelprepacket = true; } }
/// <summary> /// Handles incoming chat messages /// </summary> /// <param name="message"></param> public override void HandleMcpeText(McpeText message) { string text = message.message; if (string.IsNullOrEmpty(text)) { return; } PlayerChatEvent chatEvent = new PlayerChatEvent(this, text); EventDispatcher.DispatchEventAsync(chatEvent).Then(result => { if (result.IsCancelled) { return; } Level.BroadcastMessage(chatEvent.Message, sender: this); }); }
public void OnPlayerChat(PlayerChatEvent e) { if (e.IsCancelled) { return; } var companion = e.Player.GetAttribute <ChatCompanion>(); if (companion == null) { return; } if (companion.Muted) { e.SetCancelled(true); e.Player.SendMessage($"§4You have been muted, you may not send any chat messages!"); return; } if (!companion.CanChat()) { e.SetCancelled(true); e.Player.SendMessage($"§4Calm down, no need to spam the chat!"); return; } string filtered = e.Message; if (!companion.Filter(filtered, out filtered)) { e.SetCancelled(true); e.Player.SendMessage($"§4Please watch your language!"); return; } e.Message = filtered; companion.SentChatMesssage(); }
public void HandlePlayerChat(PlayerChatEvent @event) { if ([email protected]("say", StringComparison.InvariantCulture)) { return; } var message = @event.Message; if (string.IsNullOrWhiteSpace(message)) { return; } var config = _configurationService.Configuration; if (!message.StartsWith(config.CommandSpecifier) && !message.StartsWith(config.CommandSilentSpecifier)) { return; } try { var commands = _commandService.GetCommands().ToList(); var commandInput = CommandInputMetadata.Parse(message, commands.Select(c => c.Name).ToList()); if (string.IsNullOrWhiteSpace(commandInput.CommandName)) { @event.Player.SendMessage( new NetworkText(NetworkTextMode.Literal, "Invalid command input."), Color3.White); return; } } catch (Exception e) { Console.WriteLine(e); throw; } }