当前位置: 首页>>代码示例>>C#>>正文


C# Level.Save方法代码示例

本文整理汇总了C#中MCForge.Level.Save方法的典型用法代码示例。如果您正苦于以下问题:C# Level.Save方法的具体用法?C# Level.Save怎么用?C# Level.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MCForge.Level的用法示例。


在下文中一共展示了Level.Save方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Start


//.........这里部分代码省略.........
            ml.Queue(delegate
            {
                try
                {
                    levels = new List<Level>(Server.maps);
                    MapGen = new MapGenerator();

                    Random random = new Random();

                    if (File.Exists("levels/" + Server.level + ".lvl"))
                    {
                        mainLevel = Level.Load(Server.level);
                        mainLevel.unload = false;
                        if (mainLevel == null)
                        {
                            if (File.Exists("levels/" + Server.level + ".lvl.backup"))
                            {
                                Log("Attempting to load backup.");
                                File.Copy("levels/" + Server.level + ".lvl.backup", "levels/" + Server.level + ".lvl", true);
                                mainLevel = Level.Load(Server.level);
                                if (mainLevel == null)
                                {
                                    Log("BACKUP FAILED!");
                                    Console.ReadLine(); return;
                                }
                            }
                            else
                            {
                                Log("mainlevel not found");
                                mainLevel = new Level(Server.level, 128, 64, 128, "flat");

                                mainLevel.permissionvisit = LevelPermission.Guest;
                                mainLevel.permissionbuild = LevelPermission.Guest;
                                mainLevel.Save();
                            }
                        }
                    }
                    else
                    {
                        Log("mainlevel not found");
                        mainLevel = new Level(Server.level, 128, 64, 128, "flat");

                        mainLevel.permissionvisit = LevelPermission.Guest;
                        mainLevel.permissionbuild = LevelPermission.Guest;
                        mainLevel.Save();
                    }

                    addLevel(mainLevel);

                    // fenderrock - Make sure the level does have a physics thread
                    if (mainLevel.physThread == null)
                        mainLevel.physThread = new Thread(new ThreadStart(mainLevel.Physics));

                    mainLevel.physThread.Start();
                }
                catch (Exception e) { Server.ErrorLog(e); }
            });

            ml.Queue(delegate
            {
                bannedIP = PlayerList.Load("banned-ip.txt", null);
                ircControllers = PlayerList.Load("IRC_Controllers.txt", null);
                muted = PlayerList.Load("muted.txt", null);

                foreach (Group grp in Group.GroupList)
                    grp.playerList = PlayerList.Load(grp.fileName, grp);
开发者ID:CrusaderV,项目名称:MCForge-Vanilla,代码行数:67,代码来源:Server.cs

示例2: Use

        public override void Use(Player p, string message)
        {
            if (message == "") { Help(p); return; }

            string[] parameters = message.Split(' '); // Grab the parameters from the player's message
            if (parameters.Length >= 5 && parameters.Length <= 6) // make sure there are 5 or 6 params
            {
                switch (parameters[4])
                {
                    case "flat":
                    case "pixel":
                    case "island":
                    case "mountains":
                    case "ocean":
                    case "forest":
                    case "desert":
                    case "space":
                    case "rainbow":
                    case "hell":
                    case "nether":
                        break;

                    default:
                        Player.SendMessage(p, "Valid types: island, mountains, forest, ocean, flat, pixel, desert, space, rainbow, and hell/nether"); return;
                }

                string name = parameters[0].ToLower();
                ushort x = 1, y = 1, z = 1;
                int seed = 0;
                bool useSeed = false;
                try
                {
                    x = Convert.ToUInt16(parameters[1]);
                    y = Convert.ToUInt16(parameters[2]);
                    z = Convert.ToUInt16(parameters[3]);
                }
                catch { Player.SendMessage(p, "Invalid dimensions."); return; }
                if (parameters.Length == 6)
                {
                    try { seed = Convert.ToInt32(parameters[5]); }
                    catch { seed = parameters[5].GetHashCode(); }
                    useSeed = true;
                }
                if (!isGood(x)) { Player.SendMessage(p, x + " is not a good dimension! Use a power of 2 next time."); }
                if (!isGood(y)) { Player.SendMessage(p, y + " is not a good dimension! Use a power of 2 next time."); }
                if (!isGood(z)) { Player.SendMessage(p, z + " is not a good dimension! Use a power of 2 next time."); }

                if (!Player.ValidName(name)) { Player.SendMessage(p, "Invalid name!"); return; }
                if (System.IO.File.Exists("levels/" + name + ".lvl")) { Player.SendMessage(p, "Level \"" + name + "\" already exists!"); return; }

                /*try
                {
                    if (p != null)
                    if (p.group.Permission < LevelPermission.Admin)
                    {
                        if (x * y * z > 30000000) { Player.SendMessage(p, "Cannot create a map with over 30million blocks"); return; }
                    }
                    else
                    {
                        if (x * y * z > 225000000) { Player.SendMessage(p, "You cannot make a map with over 225million blocks"); return; }
                    }
                }
                catch
                {
                    Player.SendMessage(p, "An error occured");
                }*/

                // create a new level...
                try
                {
                    using (Level lvl = new Level(name, x, y, z, parameters[4], seed, useSeed))
                    {
                        lvl.Save(true); //... and save it.
                        lvl.Dispose(); // Then take out the garbage.
                    }
                }
                finally
                {
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                }
                Player.GlobalMessage("Level \"" + name + "\" created" + (useSeed ? " with seed \"" + parameters[5] + "\"" : "")); // The player needs some form of confirmation.

            }
            else
                Help(p);
        }
开发者ID:Nerketur,项目名称:MCForge-Vanilla,代码行数:87,代码来源:CmdNewLvl.cs

示例3: Use


//.........这里部分代码省略.........
                {
                    x = Convert.ToUInt16(parameters[1]);
                    y = Convert.ToUInt16(parameters[2]);
                    z = Convert.ToUInt16(parameters[3]);
                }
                catch { Player.SendMessage(p, "Invalid dimensions."); return; }
                if (parameters.Length == 6)
                {
                    try { seed = Convert.ToInt32(parameters[5]); }
                    catch { seed = parameters[5].GetHashCode(); }
                    useSeed = true;
                }
                if (!isGood(x)) { Player.SendMessage(p, x + " is not a good dimension! Use a power of 2 next time."); }
                if (!isGood(y)) { Player.SendMessage(p, y + " is not a good dimension! Use a power of 2 next time."); }
                if (!isGood(z)) { Player.SendMessage(p, z + " is not a good dimension! Use a power of 2 next time."); }

                if (!Player.ValidName(name)) { Player.SendMessage(p, "Invalid name!"); return; }
                //if (System.IO.File.Exists("levels/" + name + ".lvl")) { Player.SendMessage(p, "Level \"" + name + "\" already exists!"); return; }

                StringBuilder dir = new StringBuilder("levels/" + name);
                dir.Append(mapnumber != 0 ? "." + mapnumber.ToString() : "");
                dir.Append(".lvl");

                while (System.IO.File.Exists(dir.ToString()))
                {
                    if (p != null)
                    {
                        if (mapnumber < p.GetMaxMaps())
                        {
                            Server.s.Log(mapnumber.ToString());
                            Server.s.Log(dir.ToString());
                            Server.s.Log(p.GetMaxMaps().ToString());
                            mapnumber++;
                            dir = null;
                            dir = new StringBuilder("levels/" + name);
                            dir.Append(mapnumber != 0 ? "." + mapnumber.ToString() : "");
                            dir.Append(".lvl");
                        }
                        else { Player.SendMessage(p, "You have used up your maps!"); return; }
                    }
                    else { Player.SendMessage(p, "Level \"" + name + "\" already exists!"); return; }
                }

                name = name + "." + mapnumber.ToString();

                /*retry:
                StringBuilder dir = new StringBuilder("levels/" + name);
                dir.Append(mapnumber != 0 ? "." + mapnumber.ToString() : "");
                dir.Append(".lvl");
                if (System.IO.File.Exists(dir.ToString()))
                {
                    if (p != null)
                    {
                        if (mapnumber <= p.GetMaxMaps())
                        {
                            mapnumber++;
                            goto retry;
                        }
                        else { Player.SendMessage(p, "You have used up your maps!"); return; }
                    }
                    else { Player.SendMessage(p, "Level \"" + name + "\" already exists!"); return; }
                }*/

                /*try
                {
                    if (p != null)
                    if (p.group.Permission < LevelPermission.Admin)
                    {
                        if (x * y * z > 30000000) { Player.SendMessage(p, "Cannot create a map with over 30million blocks"); return; }
                    }
                    else
                    {
                        if (x * y * z > 225000000) { Player.SendMessage(p, "You cannot make a map with over 225million blocks"); return; }
                    }
                }
                catch
                {
                    Player.SendMessage(p, "An error occured");
                }*/

                // create a new level...
                try
                {
                    using (Level lvl = new Level(name, x, y, z, parameters[4], seed, useSeed))
                    {
                        lvl.Save(true); //... and save it.
                        lvl.Dispose(); // Then take out the garbage.
                    }
                }
                finally
                {
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                }
                Player.GlobalMessage("Level \"" + name + "\" created" + (useSeed ? " with seed \"" + parameters[5] + "\"" : "")); // The player needs some form of confirmation.

            }
            else
                Help(p);
        }
开发者ID:Cazzar,项目名称:MCaznowl-Build,代码行数:101,代码来源:CmdNewLvl.cs

示例4: Use

        public override void Use(Player p, string message)
        {
            if (message == "") { Help(p); return; }

            string[] parameters = message.Split(' '); // Grab the parameters from the player's message
            if (parameters.Length == 5) // make sure there are 5 params
            {
                switch (parameters[4])
                {
                    case "flat":
                    case "pixel":
                    case "island":
                    case "mountains":
                    case "ocean":
                    case "forest":
                    case "desert":
                    case "space":
                        break;

                    default:
                        Player.SendMessage(p, "Valid types: island, mountains, forest, ocean, flat, pixel, desert, space"); return;
                }

                string name = parameters[0].ToLower();
                ushort x = 1, y = 1, z = 1;
                try
                {
                    x = Convert.ToUInt16(parameters[1]);
                    y = Convert.ToUInt16(parameters[2]);
                    z = Convert.ToUInt16(parameters[3]);
                }
                catch { Player.SendMessage(p, "Invalid dimensions."); return; }
                if (!isGood(x)) { Player.SendMessage(p, x + " is not a good dimension! Use a power of 2 next time."); }
                if (!isGood(y)) { Player.SendMessage(p, y + " is not a good dimension! Use a power of 2 next time."); }
                if (!isGood(z)) { Player.SendMessage(p, z + " is not a good dimension! Use a power of 2 next time."); }

                if (!Player.ValidName(name)) { Player.SendMessage(p, "Invalid name!"); return; }

                try
                {
                    if (p != null)
                    if (p.group.Permission < LevelPermission.Admin)
                    {
                        if (x * y * z > 30000000) { Player.SendMessage(p, "Cannot create a map with over 30million blocks"); return; }
                    }
                    else
                    {
                        if (x * y * z > 225000000) { Player.SendMessage(p, "You cannot make a map with over 225million blocks"); return; }
                    }
                }
                catch
                {
                    Player.SendMessage(p, "An error occured");
                }

                // create a new level...
                try
                {
                    using(Level lvl = new Level(name, x, y, z, parameters[4]))
                        lvl.Save(true); //... and save it.
                }
                finally
                {
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                }
                Player.GlobalMessage("Level " + name + " created"); // The player needs some form of confirmation.
            }
            else
                Help(p);
        }
开发者ID:Jack13122,项目名称:MCForge-Vanilla,代码行数:71,代码来源:CmdNewLvl.cs

示例5: Load

        public static Level Load(Stream lvlStream, string fileName)
        {
            byte[] temp = new byte[8];
            using (Level lvl = new Level(fileName, 0, 0, 0, "empty"))
            {
                byte[] data;
                int length;
                try
                {
                    lvlStream.Seek(-4, SeekOrigin.End);
                    lvlStream.Read(temp, 0, sizeof(int));
                    lvlStream.Seek(0, SeekOrigin.Begin);
                    length = BitConverter.ToInt32(temp, 0);
                    data = new byte[length];
                    using (GZipStream reader = new GZipStream(lvlStream, CompressionMode.Decompress, true))
                    {
                        reader.Read(data, 0, length);
                    }

                    for (int i = 0; i < length - 1; i++)
                    {
                        if (data[i] == 0xAC && data[i + 1] == 0xED)
                        {

                            // bypassing the header crap
                            int pointer = i + 6;
                            Array.Copy(data, pointer, temp, 0, sizeof(short));
                            pointer += IPAddress.HostToNetworkOrder(BitConverter.ToInt16(temp, 0));
                            pointer += 13;

                            int headerEnd = 0;
                            // find the end of serialization listing
                            for (headerEnd = pointer; headerEnd < data.Length - 1; headerEnd++)
                            {
                                if (data[headerEnd] == 0x78 && data[headerEnd + 1] == 0x70)
                                {
                                    headerEnd += 2;
                                    break;
                                }
                            }

                            // start parsing serialization listing
                            int offset = 0;
                            while (pointer < headerEnd)
                            {
                                if (data[pointer] == 'Z') offset++;
                                else if (data[pointer] == 'I' || data[pointer] == 'F') offset += 4;
                                else if (data[pointer] == 'J') offset += 8;

                                pointer += 1;
                                Array.Copy(data, pointer, temp, 0, sizeof(short));
                                short skip = IPAddress.HostToNetworkOrder(BitConverter.ToInt16(temp, 0));
                                pointer += 2;

                                // look for relevant variables
                                Array.Copy(data, headerEnd + offset - 4, temp, 0, sizeof(int));
                                if (MemCmp(data, pointer, "width"))
                                {
                                    lvl.width = (ushort)IPAddress.HostToNetworkOrder(BitConverter.ToInt32(temp, 0));
                                }
                                else if (MemCmp(data, pointer, "depth"))
                                {
                                    lvl.depth = (ushort)IPAddress.HostToNetworkOrder(BitConverter.ToInt32(temp, 0));
                                }
                                else if (MemCmp(data, pointer, "height"))
                                {
                                    lvl.height = (ushort)IPAddress.HostToNetworkOrder(BitConverter.ToInt32(temp, 0));
                                }

                                pointer += skip;
                            }

                            lvl.spawnx = (ushort)(lvl.width / 1.3);
                            lvl.spawny = (ushort)(lvl.depth / 1.3);
                            lvl.spawnz = (ushort)(lvl.height / 1.3);

                            // find the start of the block array
                            bool foundBlockArray = false;
                            offset = Array.IndexOf<byte>(data, 0x00, headerEnd);
                            while (offset != -1 && offset < data.Length - 2)
                            {
                                if (data[offset] == 0x00 && data[offset + 1] == 0x78 && data[offset + 2] == 0x70)
                                {
                                    foundBlockArray = true;
                                    pointer = offset + 7;
                                }
                                offset = Array.IndexOf<byte>(data, 0x00, offset + 1);
                            }

                            // copy the block array... or fail
                            if (foundBlockArray)
                            {
                                lvl.CopyBlocks(data, pointer);
                                lvl.Save(true);
                            }
                            else
                            {
                                throw new Exception("Could not locate block array.");
                            }
                            break;
//.........这里部分代码省略.........
开发者ID:Goodlyay,项目名称:MCForge-Vanilla-Redux,代码行数:101,代码来源:ConvertDAT.cs

示例6: Use


//.........这里部分代码省略.........
                            {
                                x = Convert.ToUInt16(128);
                                y = Convert.ToUInt16(64);
                                z = Convert.ToUInt16(128);
                            }
                            catch { }
                            if (num >= 2)
                            {
                                usePixel = true;
                            }
                        }
                        else if (Str == "2")
                        {
                            try
                            {
                                x = Convert.ToUInt16(128);
                                y = Convert.ToUInt16(128);
                                z = Convert.ToUInt16(128);
                            }
                            catch { }
                            if (num >= 2)
                            {
                                usePixel = true;
                            }
                        }
                        else
                        {
                            try
                            {
                                x = Convert.ToUInt16(64);
                                y = Convert.ToUInt16(64);
                                z = Convert.ToUInt16(64);
                            }
                            catch { }
                            if (num >= 2)
                            {
                                usePixel = true;
                            }
                        }
                    }
                    else if (strings[0] == "pixel")
                    {
                        try
                        {
                            x = Convert.ToUInt16(64);
                            y = Convert.ToUInt16(64);
                            z = Convert.ToUInt16(64);
                        }
                        catch { }
                        usePixel = true;
                    }
                    else
                    {
                        Help(p);
                        return;
                    }
                }
            }
            else
            {
                try
                {
                    x = Convert.ToUInt16(64);
                    y = Convert.ToUInt16(64);
                    z = Convert.ToUInt16(64);
                }
                catch { }
            }
            string name = p.name.ToLower();

            // create a new level...
            try
            {
                if (usePixel)
                {
                    using (Level lvl = new Level(name, x, y, z, "pixel"))
                    {
                        lvl.permissionbuild = LevelPermission.Guest;
                        lvl.Save(true); //... and save it.
                    }
                }
                else
                {
                    using (Level lvl = new Level(name, x, y, z, "flat"))
                    {
                        lvl.permissionbuild = LevelPermission.Guest;
                        lvl.Save(true); //... and save it.
                    }
                }

            }
            finally
            {
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
            Player.GlobalMessage(p.group.color + p.name + Server.DefaultColor + " created a new level!");
            Command.all.Find("load").Use(p, p.name);
            Command.all.Find("goto").Use(p, p.name);
        }
开发者ID:WanX,项目名称:MCaznowl-Build,代码行数:101,代码来源:CmdNewLvl.cs


注:本文中的MCForge.Level.Save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。