/resizelvl - resizes a level

/resizelvl - resizes a level

Postby PlatinumKiller » 24 Jun 2011, 23:55

Author: TheMusiKid

Code: Select all
using System;
using System.IO;
namespace MCDzienny
{
    public class CmdResizeLvl : Command
    {
        public override string name { get { return "resizelvl"; } }
        public override string shortcut { get { return "rlvl"; } }
        public override string type { get { return "mod"; } }
        public override LevelPermission defaultRank { get { return LevelPermission.Admin; } }
        public override bool museumUsable { get { return true; } }
        public CmdResizeLvl() { }
        public override void Use(Player p, string message)
        {
            if (p == null) { Player.SendMessage(null, "The console cannot use this command!"); return; }
            if (!Directory.Exists("levels/backups/resized_levels/")) { Directory.CreateDirectory("levels/backups/resized_levels/"); }
            string[] split = message.Split(' ');
            if (split.Length != 4) { Help(p); return; }
            string levelName = split[0];
            bool fromCenter = (levelName.StartsWith("@"));
            if (fromCenter) { levelName = levelName.Substring(1); }
            Level level = Level.Find(levelName);
            if (level == null) { Player.SendMessage(p, "There is no level \"" + levelName + "\"!"); return; }
            if (level == Server.mainLevel) { Player.SendMessage(p, "You cannot resize the main level. Sorry for the inconvenience."); return; }
            string pLevel = p.level.name;
            int iOldX = level.width;
            int iOldY = level.height;
            int iOldZ = level.depth;
            try
            {
                Command move = Command.all.Find("move");
                Command click = Command.all.Find("click");
                int iNewX = Convert.ToInt32(split[1]);
                int iNewY = Convert.ToInt32(split[2]);
                int iNewZ = Convert.ToInt32(split[3]);
                if (iOldX - iNewX > 128 || iOldY - iNewY > 100 || iOldZ - iNewZ > 128) { Player.SendMessage(p, "New size is too much smaller than old size. Sorry about that."); return; }
                string tempLevelName = levelName + "_temp";
                Command.all.Find("newlvl").Use(p, tempLevelName + " " + iNewX + " " + iNewY + " " + iNewZ + " pixel");
                Command load = Command.all.Find("load");
                load.Use(null, tempLevelName);
                System.Threading.Thread.Sleep(2000);
                Level tempLevel = Level.Find(tempLevelName);
                tempLevel.unload = false;
                if (p.level != level) { move.Use(null, p.name + " " + level.name); while (p.Loading) { } }
                string copyCommand = "air";
                if (fromCenter) { copyCommand = "@ " + copyCommand; }
                Command.all.Find("copy").Use(p, copyCommand);
                int pMaxBlocks = p.group.maxBlocks;
                p.group.maxBlocks = 5000000;
                click.Use(p, "0 0 0");
                click.Use(p, (iOldX - 1) + " " + (iOldY - 1) + " " + (iOldZ - 1));
                if (fromCenter) { click.Use(p, (iOldX / 2) + " 0 " + (iOldZ / 2)); }
                move.Use(null, p.name + " " + tempLevel.name);
                while (p.Loading) { }
                tempLevel.Instant = true;
                Command.all.Find("cuboid").Use(p, "air walls");
                click.Use(p, "0 0 0");
                click.Use(p, (iNewX - 1) + " " + (iNewY - 1) + " " + (iNewZ - 1));
                Command.all.Find("paste").Use(p, "");
                if (fromCenter) { click.Use(p, (iNewX / 2) + " 0 " + (iNewZ / 2)); }
                else { click.Use(p, "0 0 0"); }
                p.group.maxBlocks = pMaxBlocks;
                tempLevel.Instant = false;
                if (p.level.name != pLevel) { move.Use(null, p.name + " " + pLevel); while (p.Loading) { } }
                string file1 = "levels/" + level.name + ".lvl";
                string file2 = "levels/backups/resized_" + file1;
                File.Copy(file1, file2, true);
                Command.all.Find("deletelvl").Use(null, level.name);
                System.Threading.Thread.Sleep(2000);
                Command.all.Find("renamelvl").Use(null, tempLevel.name + " " + levelName);
                Player.SendMessage(p, "The map \"" + levelName + "\" was resized. Backup of previous size was stored as '" + file2 + "'");
            }
            catch (Exception ex) { Player.SendMessage(p, "Something went wrong. Are you sure used valid dimensions?"); Server.ErrorLog(ex); }
        }
        public override void Help(Player p)
        {
            Player.SendMessage(p, "/resizelvl <[@]level> <x> <y> <z> - Resizes <level> to the new dimensions (shortcut = /rlvl)");
            Player.SendMessage(p, "If an '@' symbol is added to the beginning of <level> the level will be resized around the middle");
            Player.SendMessage(p, "If not, the level will be resized from the corner");
        }
    }
}
Image
User avatar
PlatinumKiller
 
Posts: 388
Joined: 22 Jun 2011, 22:55
Location: MCDzienny Forums

Re: /resizelvl <level> <x> <y> <z> - Resizes a level.Hope u

Postby jkl139 » 26 Jun 2011, 17:47

PlatinumKiller wrote:
Code: Select all
using System;
using System.IO;
namespace MCDzienny
{
    public class CmdResizeLvl : Command
    {
        public override string name { get { return "resizelvl"; } }
        public override string shortcut { get { return "rlvl"; } }
        public override string type { get { return "mod"; } }
        public override LevelPermission defaultRank { get { return LevelPermission.Admin; } }
        public override bool museumUsable { get { return true; } }
        public CmdResizeLvl() { }
        public override void Use(Player p, string message)
        {
            if (p == null) { Player.SendMessage(null, "The console cannot use this command!"); return; }
            if (!Directory.Exists("levels/backups/resized_levels/")) { Directory.CreateDirectory("levels/backups/resized_levels/"); }
            string[] split = message.Split(' ');
            if (split.Length != 4) { Help(p); return; }
            string levelName = split[0];
            bool fromCenter = (levelName.StartsWith("@"));
            if (fromCenter) { levelName = levelName.Substring(1); }
            Level level = Level.Find(levelName);
            if (level == null) { Player.SendMessage(p, "There is no level \"" + levelName + "\"!"); return; }
            if (level == Server.mainLevel) { Player.SendMessage(p, "You cannot resize the main level. Sorry for the inconvenience."); return; }
            string pLevel = p.level.name;
            int iOldX = level.width;
            int iOldY = level.height;
            int iOldZ = level.depth;
            try
            {
                Command move = Command.all.Find("move");
                Command click = Command.all.Find("click");
                int iNewX = Convert.ToInt32(split[1]);
                int iNewY = Convert.ToInt32(split[2]);
                int iNewZ = Convert.ToInt32(split[3]);
                if (iOldX - iNewX > 128 || iOldY - iNewY > 100 || iOldZ - iNewZ > 128) { Player.SendMessage(p, "New size is too much smaller than old size. Sorry about that."); return; }
                string tempLevelName = levelName + "_temp";
                Command.all.Find("newlvl").Use(p, tempLevelName + " " + iNewX + " " + iNewY + " " + iNewZ + " pixel");
                Command load = Command.all.Find("load");
                load.Use(null, tempLevelName);
                System.Threading.Thread.Sleep(2000);
                Level tempLevel = Level.Find(tempLevelName);
                tempLevel.unload = false;
                if (p.level != level) { move.Use(null, p.name + " " + level.name); while (p.Loading) { } }
                string copyCommand = "air";
                if (fromCenter) { copyCommand = "@ " + copyCommand; }
                Command.all.Find("copy").Use(p, copyCommand);
                int pMaxBlocks = p.group.maxBlocks;
                p.group.maxBlocks = 5000000;
                click.Use(p, "0 0 0");
                click.Use(p, (iOldX - 1) + " " + (iOldY - 1) + " " + (iOldZ - 1));
                if (fromCenter) { click.Use(p, (iOldX / 2) + " 0 " + (iOldZ / 2)); }
                move.Use(null, p.name + " " + tempLevel.name);
                while (p.Loading) { }
                tempLevel.Instant = true;
                Command.all.Find("cuboid").Use(p, "air walls");
                click.Use(p, "0 0 0");
                click.Use(p, (iNewX - 1) + " " + (iNewY - 1) + " " + (iNewZ - 1));
                Command.all.Find("paste").Use(p, "");
                if (fromCenter) { click.Use(p, (iNewX / 2) + " 0 " + (iNewZ / 2)); }
                else { click.Use(p, "0 0 0"); }
                p.group.maxBlocks = pMaxBlocks;
                tempLevel.Instant = false;
                if (p.level.name != pLevel) { move.Use(null, p.name + " " + pLevel); while (p.Loading) { } }
                string file1 = "levels/" + level.name + ".lvl";
                string file2 = "levels/backups/resized_" + file1;
                File.Copy(file1, file2, true);
                Command.all.Find("deletelvl").Use(null, level.name);
                System.Threading.Thread.Sleep(2000);
                Command.all.Find("renamelvl").Use(null, tempLevel.name + " " + levelName);
                Player.SendMessage(p, "The map \"" + levelName + "\" was resized. Backup of previous size was stored as '" + file2 + "'");
            }
            catch (Exception ex) { Player.SendMessage(p, "Something went wrong. Are you sure used valid dimensions?"); Server.ErrorLog(ex); }
        }
        public override void Help(Player p)
        {
            Player.SendMessage(p, "/resizelvl <[@]level> <x> <y> <z> - Resizes <level> to the new dimensions (shortcut = /rlvl)");
            Player.SendMessage(p, "If an '@' symbol is added to the beginning of <level> the level will be resized around the middle");
            Player.SendMessage(p, "If not, the level will be resized from the corner");
        }
    }
}


U CHANGED YOUR SIGNATURE BIATCH! :D
Image
Image
User avatar
jkl139
 
Posts: 444
Joined: 13 Jun 2011, 11:46
Location: MCDzienny Forum

Re: /resizelvl <level> <x> <y> <z> - Resizes a level.Hope u

Postby PlatinumKiller » 26 Jun 2011, 17:57

Lol, thanks for the command update.
Image
User avatar
PlatinumKiller
 
Posts: 388
Joined: 22 Jun 2011, 22:55
Location: MCDzienny Forums

Re: /resizelvl <level> <x> <y> <z> - Resizes a level.Hope u

Postby jkl139 » 26 Jun 2011, 18:02

PlatinumKiller wrote:Lol, thanks for the command update.


Oh, btw. Do maps over 64x64x64 lag for you too? i got a 64x128x64 map (planetoids) and it lags everytime we play on it
Image
Image
User avatar
jkl139
 
Posts: 444
Joined: 13 Jun 2011, 11:46
Location: MCDzienny Forum


Return to Custom Commands

Who is online

Users browsing this forum: No registered users and 6 guests

cron