MCLawl.Group.saveGroups C# (CSharp) Method

saveGroups() public static method

public static saveGroups ( List givenList ) : void
givenList List
return void
        public static void saveGroups(List<Group> givenList)
        {
            StreamWriter SW = new StreamWriter(File.Create("properties/ranks.properties"));
            SW.WriteLine("#RankName = string");
            SW.WriteLine("#     The name of the rank, use capitalization.");
            SW.WriteLine("#");
            SW.WriteLine("#Permission = num");
            SW.WriteLine("#     The \"permission\" of the rank. It's a number.");
            SW.WriteLine("#		There are pre-defined permissions already set. (for the old ranks)");
            SW.WriteLine("#		Banned = -20, Guest = 0, Builder = 30, AdvBuilder = 50, Operator = 80");
            SW.WriteLine("#		SuperOP = 100, Nobody = 120");
            SW.WriteLine("#		Must be greater than -50 and less than 120");
            SW.WriteLine("#		The higher the number, the more commands do (such as undo allowing more seconds)");
            SW.WriteLine("#Limit = num");
            SW.WriteLine("#     The command limit for the rank (can be changed in-game with /limit)");
            SW.WriteLine("#		Must be greater than 0 and less than 10000000");
            SW.WriteLine("#Color = char");
            SW.WriteLine("#     A single letter or number denoting the color of the rank");
            SW.WriteLine("#	    Possibilities:");
            SW.WriteLine("#		    0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f");
            SW.WriteLine("#FileName = string.txt");
            SW.WriteLine("#     The file which players of this rank will be stored in");
            SW.WriteLine("#		It doesn't need to be a .txt file, but you may as well");
            SW.WriteLine("#		Generally a good idea to just use the same file name as the rank name");
            SW.WriteLine();
            SW.WriteLine();

            foreach (Group grp in givenList)
            {
                if (grp.name != "nobody")
                {
                    SW.WriteLine("RankName = " + grp.trueName);
                    SW.WriteLine("Permission = " + (int)grp.Permission);
                    SW.WriteLine("Limit = " + grp.maxBlocks);
                    SW.WriteLine("Color = " + grp.color[1]);
                    SW.WriteLine("FileName = " + grp.fileName);
                    SW.WriteLine();
                }
            }

            SW.Flush();
            SW.Close();
        }

Usage Example

Beispiel #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;
                }
            }
        }