Cleanup /save.

This commit is contained in:
UnknownShadow200 2016-02-11 16:09:50 +11:00
parent 4693687b55
commit 0b8cbfe91f
2 changed files with 51 additions and 66 deletions

View File

@ -103,8 +103,6 @@ namespace MCGalaxy.Commands {
Level oldLevel = p.level; Level oldLevel = p.level;
p.level = lvl; p.SendUserMOTD(); p.SendMap(oldLevel); p.level = lvl; p.SendUserMOTD(); p.SendMap(oldLevel);
GC.Collect();
ushort x = (ushort)((0.5 + lvl.spawnx) * 32); ushort x = (ushort)((0.5 + lvl.spawnx) * 32);
ushort y = (ushort)((1 + lvl.spawny) * 32); ushort y = (ushort)((1 + lvl.spawny) * 32);
ushort z = (ushort)((0.5 + lvl.spawnz) * 32); ushort z = (ushort)((0.5 + lvl.spawnz) * 32);

View File

@ -15,10 +15,10 @@
or implied. See the Licenses for the specific language governing or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses. permissions and limitations under the Licenses.
*/ */
namespace MCGalaxy.Commands namespace MCGalaxy.Commands {
{
public sealed class CmdSave : Command public sealed class CmdSave : Command {
{
public override string name { get { return "save"; } } public override string name { get { return "save"; } }
public override string shortcut { get { return ""; } } public override string shortcut { get { return ""; } }
public override string type { get { return CommandTypes.World; } } public override string type { get { return CommandTypes.World; } }
@ -36,54 +36,41 @@ namespace MCGalaxy.Commands
} }
Player.GlobalMessage("All levels have been saved."); Player.GlobalMessage("All levels have been saved.");
} else { } else {
if (message == "") { // for empty string/no parameters. string[] args = message.Split(' ');
if (p == null) { if (message == "") {
if (p == null)
Use(p, "all"); Use(p, "all");
} else { else
p.level.Save(true); Save(p, p.level, "");
Player.SendMessage(p, "Level \"" + p.level.name + "\" saved."); } else if (args.Length <= 2) {
Level lvl = LevelInfo.Find(args[0]);
int backupNumber = p.level.Backup(true); string restore = args.Length > 1 ? args[1].ToLower() : "";
if (backupNumber != -1) { if (lvl != null)
// Notify console and the player who called /save Save(p, lvl, restore);
Player.SendMessage(null, "Backup " + backupNumber + " saved for " + p.level.name); else
if (p != null)
p.level.ChatLevel("Backup " + backupNumber + " saved.");
}
}
} else if (message.Split(' ').Length == 1) { //Just save level given
Level foundLevel = LevelInfo.Find(message);
if (foundLevel != null) {
foundLevel.Save(true);
Player.SendMessage(p, "Level \"" + foundLevel.name + "\" saved.");
int backupNumber = foundLevel.Backup(true);
if (backupNumber != -1) {
// Notify console and the player who called /save
Player.SendMessage(null, "Backup " + backupNumber + " saved for " + foundLevel.name);
if (p != null)
p.level.ChatLevel("Backup " + backupNumber + " saved.");
}
} else {
Player.SendMessage(p, "Could not find level specified"); Player.SendMessage(p, "Could not find level specified");
}
} else if (message.Split(' ').Length == 2) {
Level foundLevel = LevelInfo.Find(message.Split(' ')[0]);
string restoreName = message.Split(' ')[1].ToLower();
if (foundLevel != null) {
foundLevel.Save(true);
int backupNumber = p.level.Backup(true, restoreName);
Player.GlobalMessage(foundLevel.name + " had a backup created named &b" + restoreName);
Player.SendMessage(null, foundLevel.name + " had a backup created named &b" + restoreName);
} else { } else {
Player.SendMessage(p, "Could not find level specified");
}
} else { // Invalid number of arguments
Help(p); Help(p);
} }
} }
} }
public override void Help(Player p)
{ static void Save(Player p, Level lvl, string restoreName) {
lvl.Save(true);
Player.SendMessage(p, "Level \"" + lvl.name + "\" saved.");
int num = lvl.Backup(true, restoreName);
if (num == -1) return;
if (restoreName == "") {
Server.s.Log("Backup " + num + " saved for " + lvl.name);
Player.GlobalMessage("Backup " + num + " saved for " + lvl.name);
} else {
Server.s.Log(lvl.name + " had a backup created named &b" + restoreName);
Player.GlobalMessage(lvl.name + " had a backup created named &b" + restoreName);
}
}
public override void Help(Player p) {
Player.SendMessage(p, "/save - Saves the level you are currently in"); Player.SendMessage(p, "/save - Saves the level you are currently in");
Player.SendMessage(p, "/save all - Saves all loaded levels."); Player.SendMessage(p, "/save all - Saves all loaded levels.");
Player.SendMessage(p, "/save <map> - Saves the specified map."); Player.SendMessage(p, "/save <map> - Saves the specified map.");