Find() public static method

public static Find ( string name ) : Group
name string
return Group
コード例 #1
0
        public override void Use(Player p, string message)
        {
            if (message.Split(' ').Length != 2)
            {
                Help(p); return;
            }
            int newLimit;

            try { newLimit = int.Parse(message.Split(' ')[1]); }
            catch { Player.SendMessage(p, "Invalid limit amount"); return; }
            if (newLimit < 1)
            {
                Player.SendMessage(p, "Cannot set below 1."); return;
            }

            Group foundGroup = Group.Find(message.Split(' ')[0]);

            if (foundGroup != null)
            {
                foundGroup.maxBlocks = newLimit;
                Player.GlobalChat(null, foundGroup.color + foundGroup.name + Server.DefaultColor + "'s building limits were set to &b" + newLimit, false);
                Group.saveGroups(Group.GroupList);
            }
            else
            {
                switch (message.Split(' ')[0].ToLower())
                {
                case "rp":
                case "restartphysics":
                    Server.rpLimit = newLimit;
                    Player.GlobalMessage("Custom /rp's limit was changed to &b" + newLimit.ToString());
                    break;

                case "rpnorm":
                case "rpnormal":
                    Server.rpNormLimit = newLimit;
                    Player.GlobalMessage("Normal /rp's limit was changed to &b" + newLimit.ToString());
                    break;

                default:
                    Player.SendMessage(p, "No supported /limit");
                    break;
                }
            }
        }
コード例 #2
0
ファイル: Group.cs プロジェクト: DireatClassicube/MCLawl
        public static void InitAll()
        {
            GroupList = new List <Group>();

            if (File.Exists("properties/ranks.properties"))
            {
                string[] lines = File.ReadAllLines("properties/ranks.properties");

                Group thisGroup = new Group();
                int   gots      = 0;

                foreach (string s in lines)
                {
                    try
                    {
                        if (s != "" && s[0] != '#')
                        {
                            if (s.Split('=').Length == 2)
                            {
                                string property = s.Split('=')[0].Trim();
                                string value    = s.Split('=')[1].Trim();

                                if (thisGroup.name == "" && property.ToLower() != "rankname")
                                {
                                    Server.s.Log("Hitting an error at " + s + " of ranks.properties");
                                }
                                else
                                {
                                    switch (property.ToLower())
                                    {
                                    case "rankname":
                                        gots      = 0;
                                        thisGroup = new Group();

                                        if (value.ToLower() == "developers" || value.ToLower() == "devs")
                                        {
                                            Server.s.Log("You are not a developer. Stop pretending you are.");
                                        }
                                        else if (GroupList.Find(grp => grp.name == value.ToLower()) == null)
                                        {
                                            thisGroup.trueName = value;
                                        }
                                        else
                                        {
                                            Server.s.Log("Cannot add the rank " + value + " twice");
                                        }
                                        break;

                                    case "permission":
                                        int foundPermission;

                                        try
                                        {
                                            foundPermission = int.Parse(value);
                                        }
                                        catch { Server.s.Log("Invalid permission on " + s); break; }

                                        if (thisGroup.Permission != LevelPermission.Null)
                                        {
                                            Server.s.Log("Setting permission again on " + s);
                                            gots--;
                                        }

                                        bool allowed = true;
                                        if (GroupList.Find(grp => grp.Permission == (LevelPermission)foundPermission) != null)
                                        {
                                            allowed = false;
                                        }

                                        if (foundPermission > 119 || foundPermission < -50)
                                        {
                                            Server.s.Log("Permission must be between -50 and 119 for ranks");
                                            break;
                                        }

                                        if (allowed)
                                        {
                                            gots++;
                                            thisGroup.Permission = (LevelPermission)foundPermission;
                                        }
                                        else
                                        {
                                            Server.s.Log("Cannot have 2 ranks set at permission level " + value);
                                        }
                                        break;

                                    case "limit":
                                        int foundLimit;

                                        try
                                        {
                                            foundLimit = int.Parse(value);
                                        }
                                        catch { Server.s.Log("Invalid limit on " + s); break; }

                                        gots++;
                                        thisGroup.maxBlocks = foundLimit;
                                        break;

                                    case "color":
                                        char foundChar;

                                        try
                                        {
                                            foundChar = char.Parse(value);
                                        }
                                        catch { Server.s.Log("Incorrect color on " + s); break; }

                                        if ((foundChar >= '0' && foundChar <= '9') || (foundChar >= 'a' && foundChar <= 'f'))
                                        {
                                            gots++;
                                            thisGroup.color = foundChar.ToString();
                                        }
                                        else
                                        {
                                            Server.s.Log("Invalid color code at " + s);
                                        }
                                        break;

                                    case "filename":
                                        if (value.Contains("\\") || value.Contains("/"))
                                        {
                                            Server.s.Log("Invalid filename on " + s);
                                            break;
                                        }

                                        gots++;
                                        thisGroup.fileName = value;
                                        break;
                                    }

                                    if (gots >= 4)
                                    {
                                        GroupList.Add(new Group(thisGroup.Permission, thisGroup.maxBlocks, thisGroup.trueName, thisGroup.color[0], thisGroup.fileName));
                                    }
                                }
                            }
                            else
                            {
                                Server.s.Log("In ranks.properties, the line " + s + " is wrongly formatted");
                            }
                        }
                    }
                    catch { }
                }
            }

            if (GroupList.Find(grp => grp.Permission == LevelPermission.Banned) == null)
            {
                GroupList.Add(new Group(LevelPermission.Banned, 1, "Banned", '8', "banned.txt"));
            }
            if (GroupList.Find(grp => grp.Permission == LevelPermission.Guest) == null)
            {
                GroupList.Add(new Group(LevelPermission.Guest, 1, "Guest", '7', "guest.txt"));
            }
            if (GroupList.Find(grp => grp.Permission == LevelPermission.Builder) == null)
            {
                GroupList.Add(new Group(LevelPermission.Builder, 400, "Builder", '2', "builders.txt"));
            }
            if (GroupList.Find(grp => grp.Permission == LevelPermission.AdvBuilder) == null)
            {
                GroupList.Add(new Group(LevelPermission.AdvBuilder, 1200, "AdvBuilder", '3', "advbuilders.txt"));
            }
            if (GroupList.Find(grp => grp.Permission == LevelPermission.Operator) == null)
            {
                GroupList.Add(new Group(LevelPermission.Operator, 2500, "Operator", 'c', "operators.txt"));
            }
            if (GroupList.Find(grp => grp.Permission == LevelPermission.Admin) == null)
            {
                GroupList.Add(new Group(LevelPermission.Admin, 65536, "SuperOP", 'e', "uberOps.txt"));
            }
            GroupList.Add(new Group(LevelPermission.Nobody, 65536, "Nobody", '0', "nobody.txt"));

            bool swap = true; Group storedGroup;

            while (swap)
            {
                swap = false;
                for (int i = 0; i < GroupList.Count - 1; i++)
                {
                    if (GroupList[i].Permission > GroupList[i + 1].Permission)
                    {
                        swap             = true;
                        storedGroup      = GroupList[i];
                        GroupList[i]     = GroupList[i + 1];
                        GroupList[i + 1] = storedGroup;
                    }
                }
            }

            if (Group.Find(Server.defaultRank) != null)
            {
                standard = Group.Find(Server.defaultRank);
            }
            else
            {
                standard = Group.findPerm(LevelPermission.Guest);
            }

            foreach (Player pl in Player.players)
            {
                pl.group = GroupList.Find(g => g.name == pl.group.name);
            }

            saveGroups(GroupList);
        }
コード例 #3
0
ファイル: CmdZone.cs プロジェクト: DireatClassicube/MCLawl
        public override void Use(Player p, string message)
        {
            CatchPos cpos;

            if (message == "")
            {
                p.ZoneCheck = true;
                Player.SendMessage(p, "Place a block where you would like to check for zones.");
                return;
            }
            else if (p.group.Permission < LevelPermission.Operator)
            {
                Player.SendMessage(p, "Reserved for OP+");
                return;
            }

            if (message.IndexOf(' ') == -1)
            {
                switch (message.ToLower())
                {
                case "del":
                    p.zoneDel = true;
                    Player.SendMessage(p, "Place a block where you would like to delete a zone.");
                    return;

                default:
                    Help(p);
                    return;
                }
            }


            if (message.ToLower() == "del all")
            {
                if (p.group.Permission < LevelPermission.Admin)
                {
                    Player.SendMessage(p, "Only a SuperOP may delete all zones at once");
                    return;
                }
                else
                {
                    for (int i = 0; i < p.level.ZoneList.Count; i++)
                    {
                        Level.Zone Zn = p.level.ZoneList[i];
                        MySQL.executeQuery("DELETE FROM `Zone" + p.level.name + "` WHERE Owner='" + Zn.Owner + "' AND SmallX='" + Zn.smallX + "' AND SMALLY='" + Zn.smallY + "' AND SMALLZ='" + Zn.smallZ + "' AND BIGX='" + Zn.bigX + "' AND BIGY='" + Zn.bigY + "' AND BIGZ='" + Zn.bigZ + "'");

                        Player.SendMessage(p, "Zone deleted for &b" + Zn.Owner);
                        p.level.ZoneList.Remove(p.level.ZoneList[i]);
                        if (i == p.level.ZoneList.Count)
                        {
                            Player.SendMessage(p, "Finished removing all zones"); return;
                        }
                        i--;
                    }
                }
            }


            if (p.group.Permission < LevelPermission.Operator)
            {
                Player.SendMessage(p, "Setting zones is reserved for OP+"); return;
            }

            if (Group.Find(message.Split(' ')[1]) != null)
            {
                message = message.Split(' ')[0] + " grp" + Group.Find(message.Split(' ')[1]).name;
            }

            if (message.Split(' ')[0].ToLower() == "add")
            {
                Player foundPlayer = Player.Find(message.Split(' ')[1]);
                if (foundPlayer == null)
                {
                    cpos.Owner = message.Split(' ')[1].ToString();
                }
                else
                {
                    cpos.Owner = foundPlayer.name;
                }
            }
            else
            {
                Help(p); return;
            }

            if (!Player.ValidName(cpos.Owner))
            {
                Player.SendMessage(p, "INVALID NAME."); return;
            }

            cpos.x = 0; cpos.y = 0; cpos.z = 0; p.blockchangeObject = cpos;

            Player.SendMessage(p, "Place two blocks to determine the edges.");
            Player.SendMessage(p, "Zone for: &b" + cpos.Owner + ".");
            p.ClearBlockchange();
            p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);
        }
コード例 #4
0
ファイル: CmdWhois.cs プロジェクト: DireatClassicube/MCLawl
        public override void Use(Player p, string message)
        {
            Player who = null;

            if (message == "")
            {
                who = p; message = p.name;
            }
            else
            {
                who = Player.Find(message);
            }
            if (who != null && !who.hidden)
            {
                Player.SendMessage(p, who.color + who.name + Server.DefaultColor + " is on &b" + who.level.name);
                Player.SendMessage(p, who.color + who.prefix + who.name + Server.DefaultColor + " has :");
                Player.SendMessage(p, "> > the rank of " + who.group.color + who.group.name);
                try
                {
                    if (!Group.Find("Nobody").commands.Contains("pay") && !Group.Find("Nobody").commands.Contains("give") && !Group.Find("Nobody").commands.Contains("take"))
                    {
                        Player.SendMessage(p, "> > &a" + who.money + Server.DefaultColor + " " + Server.moneys);
                    }
                }
                catch { }
                Player.SendMessage(p, "> > &cdied &a" + who.overallDeath + Server.DefaultColor + " times");
                Player.SendMessage(p, "> > &bmodified &a" + who.overallBlocks + Server.DefaultColor + " blocks, &a" + who.loginBlocks + Server.DefaultColor + " since logging in.");
                string storedTime = Convert.ToDateTime(DateTime.Now.Subtract(who.timeLogged).ToString()).ToString("HH:mm:ss");
                Player.SendMessage(p, "> > been logged in for &a" + storedTime);
                Player.SendMessage(p, "> > first logged into the server on &a" + who.firstLogin.ToString("yyyy-MM-dd") + " at " + who.firstLogin.ToString("HH:mm:ss"));
                Player.SendMessage(p, "> > logged in &a" + who.totalLogins + Server.DefaultColor + " times, &c" + who.totalKicked + Server.DefaultColor + " of which ended in a kick.");
                Player.SendMessage(p, "> > " + Awards.awardAmount(who.name) + " awards");

                bool skip = false;
                if (p != null)
                {
                    if (p.group.Permission <= LevelPermission.AdvBuilder)
                    {
                        skip = true;
                    }
                }
                if (!skip)
                {
                    string givenIP;
                    if (Server.bannedIP.Contains(who.ip))
                    {
                        givenIP = "&8" + who.ip + ", which is banned";
                    }
                    else
                    {
                        givenIP = who.ip;
                    }
                    Player.SendMessage(p, "> > the IP of " + givenIP);
                    if (Server.useWhitelist)
                    {
                        if (Server.whiteList.Contains(who.name))
                        {
                            Player.SendMessage(p, "> > Player is &fWhitelisted");
                        }
                    }
                    if (Server.devs.Contains(who.name.ToLower()))
                    {
                        Player.SendMessage(p, Server.DefaultColor + "> > Player is a &9Developer");
                    }
                }
            }
            else
            {
                Player.SendMessage(p, "\"" + message + "\" is offline! Using /whowas instead."); Command.all.Find("whowas").Use(p, message);
            }
        }
コード例 #5
0
ファイル: CmdSetRank.cs プロジェクト: tyabus/MCLawl
        public override void Use(Player p, string message)
        {
            if (message.Split(' ').Length < 2)
            {
                Help(p); return;
            }
            Player who     = Player.Find(message.Split(' ')[0]);
            Group  newRank = Group.Find(message.Split(' ')[1]);
            string msgGave;

            if (message.Split(' ').Length > 2)
            {
                msgGave = message.Substring(message.IndexOf(' ', message.IndexOf(' ') + 1));
            }
            else
            {
                msgGave = "Congratulations!";
            }
            if (newRank == null)
            {
                Player.SendMessage(p, "Could not find specified rank."); return;
            }

            Group bannedGroup = Group.findPerm(LevelPermission.Banned);

            if (who == null)
            {
                string foundName = message.Split(' ')[0];
                if (Group.findPlayerGroup(foundName) == bannedGroup || newRank == bannedGroup)
                {
                    Player.SendMessage(p, "Cannot change the rank to or from \"" + bannedGroup.name + "\".");
                    return;
                }

                if (p != null)
                {
                    if (Group.findPlayerGroup(foundName).Permission >= p.group.Permission || newRank.Permission >= p.group.Permission)
                    {
                        Player.SendMessage(p, "Cannot change the rank of someone equal or higher than you"); return;
                    }
                }

                Group oldGroup = Group.findPlayerGroup(foundName);
                oldGroup.playerList.Remove(foundName);
                oldGroup.playerList.Save();

                newRank.playerList.Add(foundName);
                newRank.playerList.Save();

                Player.GlobalMessage(foundName + " &f(offline)" + Server.DefaultColor + "'s rank was set to " + newRank.color + newRank.name);
            }
            else if (who == p)
            {
                Player.SendMessage(p, "Cannot change your own rank."); return;
            }
            else
            {
                if (p != null)
                {
                    if (who.group == bannedGroup || newRank == bannedGroup)
                    {
                        Player.SendMessage(p, "Cannot change the rank to or from \"" + bannedGroup.name + "\".");
                        return;
                    }

                    if (who.group.Permission >= p.group.Permission || newRank.Permission >= p.group.Permission)
                    {
                        Player.SendMessage(p, "Cannot change the rank of someone equal or higher to yourself."); return;
                    }
                }

                who.group.playerList.Remove(who.name);
                who.group.playerList.Save();

                newRank.playerList.Add(who.name);
                newRank.playerList.Save();

                Player.GlobalChat(who, who.color + who.name + Server.DefaultColor + "'s rank was set to " + newRank.color + newRank.name, false);
                Player.GlobalChat(null, "&6" + msgGave, false);
                who.group = newRank;
                who.color = who.group.color;
                Player.GlobalDie(who, false);
                who.SendMessage("You are now ranked " + newRank.color + newRank.name + Server.DefaultColor + ", type /help for your new set of commands.");
                Player.GlobalSpawn(who, who.pos[0], who.pos[1], who.pos[2], who.rot[0], who.rot[1], false);
            }
        }
コード例 #6
0
        public override void Use(Player p, string message)
        {
            if (message == "")
            {
                Help(p); return;
            }
            Player pl = Player.Find(message);

            if (pl != null && !pl.hidden)
            {
                Player.SendMessage(p, pl.color + pl.name + Server.DefaultColor + " is online, using /whois instead.");
                Command.all.Find("whois").Use(p, message);
                return;
            }

            if (message.IndexOf("'") != -1)
            {
                Player.SendMessage(p, "Cannot parse request."); return;
            }

            string FoundRank = Group.findPlayer(message.ToLower());

            DataTable playerDb = MySQL.fillData("SELECT * FROM Players WHERE Name='" + message + "'");

            if (playerDb.Rows.Count == 0)
            {
                Player.SendMessage(p, Group.Find(FoundRank).color + message + Server.DefaultColor + " has the rank of " + Group.Find(FoundRank).color + FoundRank); return;
            }

            Player.SendMessage(p, Group.Find(FoundRank).color + playerDb.Rows[0]["Title"] + " " + message + Server.DefaultColor + " has :");
            Player.SendMessage(p, "> > the rank of \"" + Group.Find(FoundRank).color + FoundRank);
            try
            {
                if (!Group.Find("Nobody").commands.Contains("pay") && !Group.Find("Nobody").commands.Contains("give") && !Group.Find("Nobody").commands.Contains("take"))
                {
                    Player.SendMessage(p, "> > &a" + playerDb.Rows[0]["Money"] + Server.DefaultColor + " " + Server.moneys);
                }
            }
            catch { }
            Player.SendMessage(p, "> > &cdied &a" + playerDb.Rows[0]["TotalDeaths"] + Server.DefaultColor + " times");
            Player.SendMessage(p, "> > &bmodified &a" + playerDb.Rows[0]["totalBlocks"] + Server.DefaultColor + " blocks.");
            Player.SendMessage(p, "> > was last seen on &a" + playerDb.Rows[0]["LastLogin"]);
            Player.SendMessage(p, "> > first logged into the server on &a" + playerDb.Rows[0]["FirstLogin"]);
            Player.SendMessage(p, "> > logged in &a" + playerDb.Rows[0]["totalLogin"] + Server.DefaultColor + " times, &c" + playerDb.Rows[0]["totalKicked"] + Server.DefaultColor + " of which ended in a kick.");
            Player.SendMessage(p, "> > " + Awards.awardAmount(message) + " awards");

            bool skip = false;

            if (p != null)
            {
                if (p.group.Permission <= LevelPermission.AdvBuilder)
                {
                    skip = true;
                }
            }

            if (!skip)
            {
                if (Server.bannedIP.Contains(playerDb.Rows[0]["IP"].ToString()))
                {
                    playerDb.Rows[0]["IP"] = "&8" + playerDb.Rows[0]["IP"] + ", which is banned";
                }
                Player.SendMessage(p, "> > the IP of " + playerDb.Rows[0]["IP"]);
                if (Server.useWhitelist)
                {
                    if (Server.whiteList.Contains(message.ToLower()))
                    {
                        Player.SendMessage(p, "> > Player is &fWhitelisted");
                    }
                }
                if (Server.devs.Contains(message.ToLower()))
                {
                    Player.SendMessage(p, Server.DefaultColor + "> > Player is a &9Developer");
                }
            }
            playerDb.Dispose();
        }
コード例 #7
0
        public override void Use(Player p, string message)
        {
            try
            {
                if (message == "")
                {
                    Player.SendMessage(p, "Basic blocks: ");
                    for (byte i = 0; i < 50; i++)
                    {
                        message += ", " + Block.Name(i);
                    }
                    Player.SendMessage(p, message.Remove(0, 2));
                    Player.SendMessage(p, "&d/blocks all <0/1/2/3/4> " + Server.DefaultColor + "will show the rest.");
                }
                else if (message.ToLower() == "all")
                {
                    Player.SendMessage(p, "Complex blocks: ");
                    for (byte i = 50; i < 255; i++)
                    {
                        if (Block.Name(i).ToLower() != "unknown")
                        {
                            message += ", " + Block.Name(i);
                        }
                    }
                    Player.SendMessage(p, message.Remove(0, 2));
                    Player.SendMessage(p, "Use &d/blocks all <0/1/2/3/4> " + Server.DefaultColor + "for a readable list.");
                }
                else if (message.ToLower().IndexOf(' ') != -1 && message.Split(' ')[0] == "all")
                {
                    int foundRange = 0;
                    try { foundRange = int.Parse(message.Split(' ')[1]); }
                    catch { Player.SendMessage(p, "Incorrect syntax"); return; }

                    if (foundRange >= 5 || foundRange < 0)
                    {
                        Player.SendMessage(p, "Number must be between 0 and 4"); return;
                    }

                    message = "";
                    Player.SendMessage(p, "Blocks between " + foundRange * 51 + " and " + (foundRange + 1) * 51);
                    for (byte i = (byte)(foundRange * 51); i < (byte)((foundRange + 1) * 51); i++)
                    {
                        if (Block.Name(i).ToLower() != "unknown")
                        {
                            message += ", " + Block.Name(i);
                        }
                    }
                    Player.SendMessage(p, message.Remove(0, 2));
                }
                else
                {
                    string printMessage = ">>>&b";

                    if (Block.Byte(message) != Block.Zero)
                    {
                        byte b = Block.Byte(message);
                        if (b < 51)
                        {
                            for (byte i = 51; i < 255; i++)
                            {
                                if (Block.Convert(i) == b)
                                {
                                    printMessage += Block.Name(i) + ", ";
                                }
                            }

                            if (printMessage != ">>>&b")
                            {
                                Player.SendMessage(p, "Blocks which look like \"" + message + "\":");
                                Player.SendMessage(p, printMessage.Remove(printMessage.Length - 2));
                            }
                            else
                            {
                                Player.SendMessage(p, "No Complex Blocks look like \"" + message + "\"");
                            }
                        }
                        else
                        {
                            Player.SendMessage(p, "&bComplex information for \"" + message + "\":");
                            Player.SendMessage(p, "&cBlock will appear as a \"" + Block.Name(Block.Convert(b)) + "\" block");

                            if (Block.LightPass(b))
                            {
                                Player.SendMessage(p, "Block will allow light through");
                            }
                            if (Block.Physics(b))
                            {
                                Player.SendMessage(p, "Block effects physics in some way");
                            }
                            else
                            {
                                Player.SendMessage(p, "Block will not effect physics in any way");
                            }
                            if (Block.NeedRestart(b))
                            {
                                Player.SendMessage(p, "The block's physics will auto-start");
                            }

                            if (Block.OPBlocks(b))
                            {
                                Player.SendMessage(p, "Block is unaffected by explosions");
                            }

                            if (Block.AllowBreak(b))
                            {
                                Player.SendMessage(p, "Anybody can activate the block");
                            }
                            if (Block.Walkthrough(b))
                            {
                                Player.SendMessage(p, "Block can be walked through");
                            }
                            if (Block.Death(b))
                            {
                                Player.SendMessage(p, "Walking through block will kill you");
                            }

                            if (Block.DoorAirs(b) != (byte)0)
                            {
                                Player.SendMessage(p, "Block is an ordinary door");
                            }
                            if (Block.tDoor(b))
                            {
                                Player.SendMessage(p, "Block is a tdoor, which allows other blocks through when open");
                            }
                            if (Block.odoor(b) != Block.Zero)
                            {
                                Player.SendMessage(p, "Block is an odoor, which toggles (GLITCHY)");
                            }

                            if (Block.Mover(b))
                            {
                                Player.SendMessage(p, "Block can be activated by walking through it");
                            }
                        }
                    }
                    else if (Group.Find(message) != null)
                    {
                        LevelPermission Perm = Group.Find(message).Permission;
                        foreach (Block.Blocks bL in Block.BlockList)
                        {
                            if (Block.canPlace(Perm, bL.type) && Block.Name(bL.type).ToLower() != "unknown")
                            {
                                printMessage += Block.Name(bL.type) + ", ";
                            }
                        }

                        if (printMessage != ">>>&b")
                        {
                            Player.SendMessage(p, "Blocks which " + Group.Find(message).color + Group.Find(message).name + Server.DefaultColor + " can place: ");
                            Player.SendMessage(p, printMessage.Remove(printMessage.Length - 2));
                        }
                        else
                        {
                            Player.SendMessage(p, "No blocks are specific to this rank");
                        }
                    }
                    else if (message.IndexOf(' ') == -1)
                    {
                        if (message.ToLower() == "count")
                        {
                            Player.SendMessage(p, "Blocks in this map: " + p.level.blocks.Length);
                        }
                        else
                        {
                            Help(p);
                        }
                    }
                    else if (message.Split(' ')[0].ToLower() == "count")
                    {
                        int foundNum = 0; byte foundBlock = Block.Byte(message.Split(' ')[1]);
                        if (foundBlock == Block.Zero)
                        {
                            Player.SendMessage(p, "Could not find block specified"); return;
                        }

                        for (int i = 0; i < p.level.blocks.Length; i++)
                        {
                            if (foundBlock == p.level.blocks[i])
                            {
                                foundNum++;
                            }
                        }

                        if (foundNum == 0)
                        {
                            Player.SendMessage(p, "No blocks were of type \"" + message.Split(' ')[1] + "\"");
                        }
                        else if (foundNum == 1)
                        {
                            Player.SendMessage(p, "1 block was of type \"" + message.Split(' ')[1] + "\"");
                        }
                        else
                        {
                            Player.SendMessage(p, foundNum.ToString() + " blocks were of type \"" + message.Split(' ')[1] + "\"");
                        }
                    }
                    else
                    {
                        Player.SendMessage(p, "Unable to find block or rank");
                    }
                }
            }
            catch (Exception e) { Server.ErrorLog(e); Help(p); }
        }
コード例 #8
0
ファイル: CmdView.cs プロジェクト: tyabus/MCLawl
        public override void Use(Player p, string message)
        {
            if (!Directory.Exists("extra/text/"))
            {
                Directory.CreateDirectory("extra/text");
            }
            if (message == "")
            {
                DirectoryInfo di       = new DirectoryInfo("extra/text/");
                string        allFiles = "";
                foreach (FileInfo fi in di.GetFiles("*.txt"))
                {
                    try
                    {
                        string firstLine = File.ReadAllLines("extra/text/" + fi.Name.Substring(0, fi.Name.Length - fi.Extension.Length) + ".txt")[0];
                        if (firstLine[0] == '#')
                        {
                            if (Group.Find(firstLine.Substring(1)).Permission <= p.group.Permission)
                            {
                                allFiles += ", " + fi.Name.Substring(0, fi.Name.Length - fi.Extension.Length);
                            }
                        }
                        else
                        {
                            allFiles += ", " + fi.Name;
                        }
                    } catch (Exception e) { Server.ErrorLog(e); Player.SendMessage(p, "Error"); }
                }

                if (allFiles == "")
                {
                    Player.SendMessage(p, "No files are viewable by you");
                }
                else
                {
                    Player.SendMessage(p, "Available files:");
                    Player.SendMessage(p, allFiles.Remove(0, 2));
                }
            }
            else
            {
                Player who = null;
                if (message.IndexOf(' ') != -1)
                {
                    who = Player.Find(message.Split(' ')[message.Split(' ').Length - 1]);
                    if (who != null)
                    {
                        message = message.Substring(0, message.LastIndexOf(' '));
                    }
                }
                if (who == null)
                {
                    who = p;
                }

                if (File.Exists("extra/text/" + message + ".txt"))
                {
                    try
                    {
                        string[] allLines = File.ReadAllLines("extra/text/" + message + ".txt");
                        if (allLines[0][0] == '#')
                        {
                            if (Group.Find(allLines[0].Substring(1)).Permission <= p.group.Permission)
                            {
                                for (int i = 1; i < allLines.Length; i++)
                                {
                                    Player.SendMessage(who, allLines[i]);
                                }
                            }
                            else
                            {
                                Player.SendMessage(p, "You cannot view this file");
                            }
                        }
                        else
                        {
                            for (int i = 1; i < allLines.Length; i++)
                            {
                                Player.SendMessage(who, allLines[i]);
                            }
                        }
                    } catch { Player.SendMessage(p, "An error occurred when retrieving the file"); }
                }
                else
                {
                    Player.SendMessage(p, "File specified doesn't exist");
                }
            }
        }