コード例 #1
0
ファイル: CmdAwards.cs プロジェクト: DireatClassicube/MCLawl
        public override void Use(Player p, string message)
        {
            if (message.Split(' ').Length > 2)
            {
                Help(p); return;
            }
            // /awards
            // /awards 1
            // /awards bob
            // /awards bob 1

            int    totalCount  = 0;
            string foundPlayer = "";

            if (message != "")
            {
                if (message.Split(' ').Length == 2)
                {
                    foundPlayer = message.Split(' ')[0];
                    Player who = Player.Find(foundPlayer);
                    if (who != null)
                    {
                        foundPlayer = who.name;
                    }
                    try
                    {
                        totalCount = int.Parse(message.Split(' ')[1]);
                    }
                    catch
                    {
                        Help(p);
                        return;
                    }
                }
                else
                {
                    if (message.Length <= 3)
                    {
                        try
                        {
                            totalCount = int.Parse(message);
                        }
                        catch
                        {
                            foundPlayer = message;
                            Player who = Player.Find(foundPlayer);
                            if (who != null)
                            {
                                foundPlayer = who.name;
                            }
                        }
                    }
                    else
                    {
                        foundPlayer = message;
                        Player who = Player.Find(foundPlayer);
                        if (who != null)
                        {
                            foundPlayer = who.name;
                        }
                    }
                }
            }

            if (totalCount < 0)
            {
                Player.SendMessage(p, "Cannot display pages less than 0");
                return;
            }

            List <Awards.awardData> awardList = new List <Awards.awardData>();

            if (foundPlayer == "")
            {
                awardList = Awards.allAwards;
            }
            else
            {
                foreach (string s in Awards.getPlayersAwards(foundPlayer))
                {
                    Awards.awardData aD = new Awards.awardData();
                    aD.awardName   = s;
                    aD.description = Awards.getDescription(s);
                    awardList.Add(aD);
                }
            }

            if (awardList.Count == 0)
            {
                if (foundPlayer != "")
                {
                    Player.SendMessage(p, "The player has no awards!");
                }
                else
                {
                    Player.SendMessage(p, "There are no awards in this server yet");
                }

                return;
            }

            int max   = totalCount * 5;
            int start = (totalCount - 1) * 5;

            if (start > awardList.Count)
            {
                Player.SendMessage(p, "There aren't that many awards. Enter a smaller number");
                return;
            }
            if (max > awardList.Count)
            {
                max = awardList.Count;
            }

            if (foundPlayer != "")
            {
                Player.SendMessage(p, Server.FindColor(foundPlayer) + foundPlayer + Server.DefaultColor + " has the following awards:");
            }
            else
            {
                Player.SendMessage(p, "Awards available: ");
            }

            if (totalCount == 0)
            {
                foreach (Awards.awardData aD in awardList)
                {
                    Player.SendMessage(p, "&6" + aD.awardName + ": &7" + aD.description);
                }

                if (awardList.Count > 8)
                {
                    Player.SendMessage(p, "&5Use &b/awards " + message + " 1/2/3/... &5for a more ordered list");
                }
            }
            else
            {
                for (int i = start; i < max; i++)
                {
                    Awards.awardData aD = awardList[i];
                    Player.SendMessage(p, "&6" + aD.awardName + ": &7" + aD.description);
                }
            }
        }
コード例 #2
0
ファイル: CmdAward.cs プロジェクト: DireatClassicube/MCLawl
        public override void Use(Player p, string message)
        {
            if (message == "" || message.IndexOf(' ') == -1)
            {
                Help(p); return;
            }

            bool give = true;

            if (message.Split(' ')[0].ToLower() == "give")
            {
                give    = true;
                message = message.Substring(message.IndexOf(' ') + 1);
            }
            else if (message.Split(' ')[0].ToLower() == "take")
            {
                give    = false;
                message = message.Substring(message.IndexOf(' ') + 1);
            }

            string foundPlayer = message.Split(' ')[0];
            Player who         = Player.Find(message);

            if (who != null)
            {
                foundPlayer = who.name;
            }
            string awardName = message.Substring(message.IndexOf(' ') + 1);

            if (!Awards.awardExists(awardName))
            {
                Player.SendMessage(p, "The award you entered doesn't exist");
                Player.SendMessage(p, "Use /awards for a list of awards");
                return;
            }

            if (give)
            {
                if (Awards.giveAward(foundPlayer, awardName))
                {
                    Player.GlobalChat(p, Server.FindColor(foundPlayer) + foundPlayer + Server.DefaultColor + " was awarded: &b" + Awards.camelCase(awardName), false);
                }
                else
                {
                    Player.SendMessage(p, "The player already has that award!");
                }
            }
            else
            {
                if (Awards.takeAward(foundPlayer, awardName))
                {
                    Player.GlobalChat(p, Server.FindColor(foundPlayer) + foundPlayer + Server.DefaultColor + " had their &b" + Awards.camelCase(awardName) + Server.DefaultColor + " award removed", false);
                }
                else
                {
                    Player.SendMessage(p, "The player didn't have the award you tried to take");
                }
            }

            Awards.Save();
        }