// Code to run when used by a player public override void Use(Player p, string message) { if (message != "") { string strBackupLevel = "levels/backups/" + p.level.name + "/" + message + "/" + p.level.name + ".lvl"; string strCurrentLevel = "levels/" + p.level.name + ".lvl"; Logger.Log(strBackupLevel, LogType.Debug); if (File.Exists(strBackupLevel)) { try { File.Copy(strBackupLevel, strCurrentLevel, true); Map temp = Map.Load(p.level.name); if (temp != null) { p.level.spawnx = temp.spawnx; p.level.spawny = temp.spawny; p.level.spawnz = temp.spawnz; p.level.height = temp.height; p.level.width = temp.width; p.level.depth = temp.depth; p.level.blocks = temp.blocks; // Disable physics before restoring p.level.Physics = Physics.Off; p.level.ClearPhysics(); ushort x, y, z; foreach (var pl in Player.players) { if (pl.level == p.level) { pl.Loading = true; //Kills current player list for player foreach (Player pl2 in Player.players) { if (pl.level == pl2.level && pl != pl2) { pl.SendDie(pl2.id); } } pl.ClearBlockchange(); pl.BlockAction = 0; pl.painting = false; Player.GlobalDie(pl, true); pl.SendMotd(); pl.SendMap(); x = (ushort)((0.5 + pl.level.spawnx) * 32); y = (ushort)((1 + pl.level.spawny) * 32); z = (ushort)((0.5 + pl.level.spawnz) * 32); if (!pl.hidden) { Player.GlobalSpawn(pl, x, y, z, pl.level.rotx, pl.level.roty, true); } else { unchecked { pl.SendPos((byte)-1, x, y, z, pl.level.rotx, pl.level.roty); } } foreach (Player pl2 in Player.players) { if (pl2.level == pl.level && pl != pl2 && !pl2.hidden) { pl.SendSpawn(pl2.id, pl2.color + pl2.name, pl2.pos[0], pl2.pos[1], pl2.pos[2], pl2.rot[0], pl2.rot[1]); } } pl.Loading = false; } GC.Collect(); GC.WaitForPendingFinalizers(); } } else { Logger.Log("Restore didn't work, attempting last backup", LogType.Debug); File.Copy(strCurrentLevel + ".backup", strCurrentLevel, true); } } catch { Logger.Log("Restore fail", LogType.Error); } } else { p.SendMessage("Backup " + message + " does not exist."); } } else { if (Directory.Exists("levels/backups/" + p.level.name)) { int backupNumber = Directory.GetDirectories("levels/backups/" + p.level.name).Length; p.SendMessage(p.level.name + " has " + backupNumber.ToString() + " backups ."); } else { p.SendMessage(p.level.name + " has no backups yet."); } } }
// Code to run when used by console public override void Use(string message) { bool blnLevelFound = false; Map targetLevel = null; foreach (Map level in Server.levels) { if (level.name.ToLower() == message.ToLower()) { targetLevel = level; blnLevelFound = true; } } if (blnLevelFound) { if (targetLevel != Server.mainLevel) { foreach (var pl in Player.players) { if (pl.level == targetLevel) { Player.GlobalDie(pl, true); } } foreach (var pl in Player.players) { if (pl.level == targetLevel) { pl.SendMotd(); } } ushort x = (ushort)((0.5 + Server.mainLevel.spawnx) * 32); ushort y = (ushort)((1 + Server.mainLevel.spawny) * 32); ushort z = (ushort)((0.5 + Server.mainLevel.spawnz) * 32); List <Player> userList = new List <Player>(); foreach (Player pl in Player.players) { if (pl.level == targetLevel) { userList.Add(pl); } } foreach (Player pl in userList) { Command.all.Find("goto").Use(pl, "main"); pl.SendMessage("Map unloaded, you were sent back to the main level."); } targetLevel.Save(); Server.levels.Remove(targetLevel); GC.Collect(); GC.WaitForPendingFinalizers(); Logger.Log("Map \"" + targetLevel.name + "\" unloaded.", LogType.ConsoleOutput); } else { Logger.Log("You can't unload the main level.", LogType.ConsoleOutput); } } else { Logger.Log("There is no level \"" + message + "\" loaded.", LogType.ConsoleOutput); } }
// Code to run when used by a player public override void Use(Player p, string message) { //p.SendMessage("Sorry this command is temporarily disabled"); if (message != "" && message.Split(' ').Length <= 2) { int pos = message.IndexOf(' '); if (pos != -1) { Player target = Player.Find(message.Substring(0, pos)); if (target == null) { p.SendMessage("There is no player \"" + message.Substring(0, pos) + "\"!"); } else { string color = ChatColor.Parse(message.Substring(pos + 1)); if (color == "") { p.SendMessage("There is no color \"" + message + "\"."); } else if (color == target.color) { p.SendMessage(target.name + " already has that color."); } else { Player.GlobalChat(target, target.color + "*" + FormatName(target.name) + " color changed to " + color + ChatColor.Name(color) + "&e.", false); target.color = color; Player.GlobalDie(target, false); Player.GlobalSpawn(target, target.pos[0], target.pos[1], target.pos[2], target.rot[0], target.rot[1], false); } } } else { string color = ChatColor.Parse(message); if (color == "") { p.SendMessage("There is no color \"" + message + "\"."); } else if (color == p.color) { p.SendMessage("You already have that color."); } else { Player.GlobalChat(p, p.color + "*" + FormatName(p.name) + " color changed to " + color + ChatColor.Name(color) + "&e.", false); p.color = color; Player.GlobalDie(p, false); Player.GlobalSpawn(p, p.pos[0], p.pos[1], p.pos[2], p.rot[0], p.rot[1], false); } } } else { Help(p); } }