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)); }); }
/// <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) }