public override void Use(Player p, string message) { //if (message == "") { Help(p); return; } string[] parameters = { p.name, "64", "64", "64", "flat" }; // message.Split(' '); // Grab the parameters from the player's message if (p != null) { if (p.group.Permission <= LevelPermission.Operator) { //some advanced coding for more custom params defaults will be player.name 64 64 64 flat user can specify the own params string[] parameters2 = message.Split(' '); switch (message.Split(' ').Length) { case 0: //attempted workaround for "invalid dimensions" parameters[1] = "64"; parameters[2] = "64"; parameters[3] = "64"; parameters[4] = "flat"; break; case 1: //set width to be first param parameters[1] = parameters2[0]; break; case 2: //set width to be first param parameters[1] = parameters2[0]; //set height to be 2nd param parameters[2] = parameters2[1]; break; case 3: //set width to be first param parameters[1] = parameters2[0]; //set height to be 2nd param parameters[2] = parameters2[1]; //set depth to be 3rd param parameters[3] = parameters2[2]; break; case 4: //set width to be first param parameters[1] = parameters2[0]; //set height to be 2nd param parameters[2] = parameters2[1]; //set depth to be 3rd param parameters[3] = parameters2[2]; //set level type to be 4th param parameters[4] = parameters2[3]; break; case 5: //set width to be first param parameters[1] = parameters2[0]; //set height to be 2nd param parameters[2] = parameters2[1]; //set depth to be 3rd param parameters[3] = parameters2[2]; //set level type to be 4th param parameters[4] = parameters2[3]; //set level seed to be last param parameters[5] = parameters2[4]; break; default: Player.SendMessage(p, "Too many parameters"); Help(p); return; } } else { parameters = message.Split(' '); } } else { parameters = message.Split(' '); } 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": break; default: Player.SendMessage(p, "Valid types: island, mountains, forest, ocean, flat, pixel, desert, space, rainbow, and hell"); return; } string name = parameters[0].ToLower(); int mapnumber = 0; 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; } 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); }