Find() public static method

Finds a player in the list
public static Find ( string name ) : Player
name string The name of the player
return Player
コード例 #1
0
ファイル: CmdFollow.cs プロジェクト: MinedroidFTW/MCSharp
        // Code to run when used by a player
        public override void Use(Player p, string message)
        {
            if (message == "")
            {
                if (dList.ContainsKey(p.name))
                {
                    p.SendMessage("Stopped following: " + dList[p.name]);
                    Player oldPlayer = Player.Find(dList[p.name]);
                    if (oldPlayer != null)
                    {
                        p.SendSpawn(oldPlayer.id, oldPlayer.name, oldPlayer.pos[0], oldPlayer.pos[1], oldPlayer.pos[2], oldPlayer.rot[0], oldPlayer.rot[1]);
                    }
                    dList.Remove(p.name);
                    return;
                }
                else
                {
                    Help(p);
                    return;
                }
            }

            Player who = Player.Find(message);

            if (who == null)
            {
                p.SendMessage("No such player!");
                return;
            }
            else
            {
                if (who.hidden)
                {
                    p.SendMessage("No such player!");
                    return;
                }
                else if (who.name == p.name)
                {
                    p.SendMessage("You have a better chance at chasing your tail than following yourself!");
                    return;
                }
            }

            if (!dList.ContainsKey(p.name))
            {
                if (!p.hidden)
                {
                    Command.all.Find("hide").Use(p, "");
                }
                p.SendDie(who.id);
                dList.Add(p.name, who.name);
                p.SendMessage("Now following: " + who.color + who.name);
                p.SendMessage("--Make sure you have flight turned ON!--");
                p.SendMessage("--Otherwise expect jittery movement!--");
            }
            else
            {
                Player oldPlayer = Player.Find(dList[p.name]);
                if (oldPlayer != null)
                {
                    p.SendSpawn(oldPlayer.id, oldPlayer.name, oldPlayer.pos[0], oldPlayer.pos[1], oldPlayer.pos[2], oldPlayer.rot[0], oldPlayer.rot[1]);
                }
                dList[p.name] = who.name;
                p.SendDie(who.id);
            }
        }
コード例 #2
0
ファイル: CmdSetRank.cs プロジェクト: MinedroidFTW/MCSharp
        // Code to run when used by a player
        public override void Use(Player p, string message)
        {
            int number = message.Split(' ').Length;

            if (number > 2)
            {
            }

            if (number == 2) // Change the players rank
            {
                // Seperate message string
                int    pos        = message.IndexOf(' ');
                string tempName   = message.Substring(0, pos).ToLower();
                string newRankmsg = message.Substring(pos + 1).ToLower();

                Player    target    = Player.Find(tempName);
                bool      validRank = true;
                GroupEnum rank      = GroupEnum.Null;

                // Ensure we catch a valid rank
                switch (newRankmsg)
                {
                case "operator":
                case "op":
                    rank = GroupEnum.Operator;
                    break;

                case "moderator":
                case "mod":
                    rank = GroupEnum.Moderator;
                    break;

                case "advbuilder":
                case "adv":
                    rank = GroupEnum.AdvBuilder;
                    break;

                case "builder":
                    rank = GroupEnum.Builder;
                    break;

                case "guest":
                    rank = GroupEnum.Guest;
                    break;

                default:
                    validRank = false;
                    break;
                }
                // Make sure the rank is valid
                if (validRank)
                {
                    // Validate target players name
                    if (Player.ValidName(tempName))
                    {
                        // Can't set your own rank
                        if (p.name != tempName)
                        {
                            // Player must be a lower rank than yourself
                            if (p.Rank > Player.GetRank(tempName))
                            {
                                // Cannot set a banned player's rank
                                if (Player.GetRank(tempName) != GroupEnum.Banned)
                                {
                                    if (rank < p.Rank)
                                    {
                                        if (target != null)
                                        {
                                            Player.GlobalMessage("[Server]: " + target.color + target.name + "&e is now a " + Group.Find(rank).Color + Group.Find(rank).Name);
                                            Player.ChangeRank(target, rank);

                                            target.SendMessage("You are now ranked " + target.group.Color + target.group.Name + "&e, type /help for your new set of commands.");
                                        }
                                        else
                                        {
                                            Player.GlobalMessage("[Server]: " + tempName + " &f(offline)&e is now a " + Group.Find(rank).Color + Group.Find(rank).Name);
                                            Player.ChangeRank(tempName, rank);
                                        }
                                        Logger.Log(tempName + " was set to " + rank + " by " + p.name);
                                    }
                                    else
                                    {
                                        p.SendMessage("You cannot set someone to the same or higher rank than you!");
                                    }
                                }
                                else
                                {
                                    p.SendMessage("You must unban this player before you can change his rank!");
                                }
                            }
                            else
                            {
                                p.SendMessage("You cannot change the rank of someone who is higher rank than you!");
                            }
                        }
                        else
                        {
                            p.SendMessage("You cannot change your own rank");
                        }
                    }
                    else
                    {
                        p.SendMessage("Invalid name \"" + message + "\".");
                    }
                }
                else
                {
                    p.SendMessage("The rank \"" + newRankmsg + "\" is invalid!");
                }
            }
            else if (message != "") // Return the players current rank
            {
                if (Player.ValidName(message))
                {
                    Group rank = MCSharp.Group.Find(Player.GetRank(message));
                    p.SendMessage(message + "'s rank is: " + rank.Color + rank.Name);
                }
            }
            else // Return usage
            {
                Help(p);
            }
        }
コード例 #3
0
        // Code to run when used by a player
        public override void Use(Player p, string message)
        {
            if (message != "")
            {
                if (message == "reload")
                {
                    Server.jokerMessages.Clear();
                    try
                    {
                        if (File.Exists("joker.txt"))
                        {
                            StreamReader r = File.OpenText("joker.txt");
                            while (!r.EndOfStream)
                            {
                                Server.jokerMessages.Add(r.ReadLine());
                            }
                        }
                        else
                        {
                            File.Create("joker.txt").Close();
                        }

                        p.SendMessage("Joker Messages Reloaded!");
                    }
                    catch
                    {
                        p.SendMessage("FAILED! Joker Messages NOT loaded!");
                    }
                }
                else
                {
                    if (Server.jokerMessages.Count > 0)
                    {
                        Player target = Player.Find(message);
                        if (target != null)
                        {
                            if (target != p)
                            {
                                if (!target.isJoker && p.Rank > target.Rank)
                                {
                                    target.isJoker = true;
                                    p.SendMessage("*" + target.color + target.name + "&e is now a joker!");
                                    target.SendMessage("You are such a jokester!");
                                }
                                else
                                {
                                    target.isJoker = false;
                                    p.SendMessage("*" + target.color + target.name + "&e is no longer a joker.");
                                    target.SendMessage("Why so serious?! You are offically no longer funny!");
                                }
                            }
                            else
                            {
                                p.SendMessage("You can't joker yourself!");
                            }
                        }
                        else
                        {
                            p.SendMessage("Error! Player not found!");
                        }
                    }
                    else
                    {
                        p.SendMessage("Failed! No messages set up! Check joker.txt");
                    }
                }
            }
            else
            {
                Help(p);
            }
        }
コード例 #4
0
ファイル: CmdColor.cs プロジェクト: MinedroidFTW/MCSharp
        // Code to run when used by a player
        public override void Use(Player p, string message)
        {
            //p.SendMessage("Sorry this command is temporarily disabled");

            if (message != "" && message.Split(' ').Length <= 2)
            {
                int pos = message.IndexOf(' ');
                if (pos != -1)
                {
                    Player target = Player.Find(message.Substring(0, pos));
                    if (target == null)
                    {
                        p.SendMessage("There is no player \"" + message.Substring(0, pos) + "\"!");
                    }
                    else
                    {
                        string color = ChatColor.Parse(message.Substring(pos + 1));
                        if (color == "")
                        {
                            p.SendMessage("There is no color \"" + message + "\".");
                        }
                        else if (color == target.color)
                        {
                            p.SendMessage(target.name + " already has that color.");
                        }
                        else
                        {
                            Player.GlobalChat(target, target.color + "*" + FormatName(target.name) + " color changed to " + color + ChatColor.Name(color) + "&e.", false);
                            target.color = color;

                            Player.GlobalDie(target, false);
                            Player.GlobalSpawn(target, target.pos[0], target.pos[1], target.pos[2], target.rot[0], target.rot[1], false);
                        }
                    }
                }
                else
                {
                    string color = ChatColor.Parse(message);
                    if (color == "")
                    {
                        p.SendMessage("There is no color \"" + message + "\".");
                    }
                    else if (color == p.color)
                    {
                        p.SendMessage("You already have that color.");
                    }
                    else
                    {
                        Player.GlobalChat(p, p.color + "*" + FormatName(p.name) +
                                          " color changed to " + color +
                                          ChatColor.Name(color) + "&e.", false);
                        p.color = color; Player.GlobalDie(p, false);
                        Player.GlobalSpawn(p, p.pos[0], p.pos[1], p.pos[2], p.rot[0], p.rot[1], false);
                    }
                }
            }
            else
            {
                Help(p);
            }
        }