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

@ -1,7 +1,7 @@
/* /*
Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy) Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy)
Dual-licensed under the Educational Community License, Version 2.0 and Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at obtain a copy of the Licenses at
@ -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

@ -1,27 +1,27 @@
/* /*
Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy) Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy)
Dual-licensed under the Educational Community License, Version 2.0 and Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
namespace MCGalaxy.Commands {
public sealed class CmdSave : Command {
Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
namespace MCGalaxy.Commands
{
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; } }
public override bool museumUsable { get { return false; } } public override bool museumUsable { get { return false; } }
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } } public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
public CmdSave() { } public CmdSave() { }
@ -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 {
} 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 {
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.");