void OnChat(OnPlayerChat args) { if (pList.ContainsKey(args.Player)) { var p = Player.Find(pList[args.Player]); //Player.UniversalChat(p.voicestring + p.color + p.prefix + p.Username + ": &f" + args.message); } }
private void plist(OnPlayerChat eventargs) { eventargs.Unregister(); if (eventargs.message.ToLower() != "yes" || eventargs.Player.ExtraData.GetIfExist("LastCmd") != "mapinfo" && eventargs.Player.ExtraData.GetIfExist("LastCmd") != "mi") return; eventargs.Cancel(); List<Player> templist = Server.Players.FindAll((p) => { return p.Level == (Level)eventargs.datapass; }); if (templist.Count == 0) { eventargs.Player.SendMessage("No one is on " + ((Level)eventargs.datapass).Name + "."); return; } if (templist.Count == 1 && eventargs.Player.Level == (Level)eventargs.datapass) { eventargs.Player.SendMessage("No one besides you is on " + ((Level)eventargs.datapass).Name + "."); return; } templist.ForEach((p) => { eventargs.Player.SendMessage(String.Concat((string)p.ExtraData.GetIfExist("Color"), p.Username)); }); }
public void CallBack2(OnPlayerChat e) { //Server.Log("Test: " + e.target.Username + " disconnected!"); e.message += " Yeah, and Pikachu ROCKS!"; e.Unregister(); }
/// <summary> /// Used to register a method to be executed when the event is fired. /// </summary> /// <param name="callback">The method to call</param> /// <param name="target">The player to watch for. (null for any players)</param> /// <returns>the OnPlayerChat event</returns> public static OnPlayerChat Register(OnCall callback, Player target) { Logger.Log("OnPlayerChat registered to the method " + callback.Method.Name, LogType.Debug); //We add it to the list here OnPlayerChat pe = _eventQueue.Find(match => (match.Player == null ? target == null : target != null && target.Username == match.Player.Username)); if (pe != null) //It already exists, so we just add it to the queue. pe._queue += callback; else { //Doesn't exist yet. Make a new one. pe = new OnPlayerChat(callback, target); _eventQueue.Add(pe); } return pe; }
/// <summary> /// This is meant to be called from the code where you mean for the event to happen. /// /// In this case, it is called from the chat processing code. /// </summary> /// <param name="p">The player that caused the event.</param> /// <param name="msg">The message sent by the player.</param> /// <returns>a new (or existing) event with the modified string.</returns> internal static OnPlayerChat Call(Player p, string msg) { Logger.Log("Calling OnPlayerChat event", LogType.Debug); //Event was called from the code. List<OnPlayerChat> opcList = new List<OnPlayerChat>(); //Do we keep or discard the event? _eventQueue.ForEach(opc => { if (opc.Player == null || opc.Player.Username == p.Username) {// We keep it //Set up variables, then fire all callbacks. opc.message = msg; Player oldPlayer = opc.Player; opc._target = p; // Set player that triggered event. opc._queue(opc); // fire callback opcList.Add(opc); // add to used list opc._target = oldPlayer; } }); OnPlayerChat pc = new OnPlayerChat(null, p); //If the messages are equal, we return it. pc.message = (opcList.Count > 0 ? opcList[0].message : msg); if (opcList.Any(pe => pe.cancel)) { pc.Cancel(); } //The message returned is the new message to use. If two events return different messages, then the 'null' message is used first. (Prevents duplicates) return ((opcList.All((opc) => opc.message == pc.message)) ? pc : opcList.Find(opc => opc.Player == null)); // Retern an event with the message //return (opcList.Any(pe => pe.cancel) ? "" : (opcList.Count > 0 ? opcList.Last().message : msg )); //Return if last canceled the event. (empty string) }
/// <summary> /// Unregisters the specific event /// </summary> /// <param name="pe">The event to unregister</param> public static void Unregister(OnPlayerChat pe) { pe.Unregister(); }