- 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");
}
}
}