Cleanup /copylvl and /repeat.

This commit is contained in:
UnknownShadow200 2016-02-15 15:41:34 +11:00
parent 7f9ef3a0b3
commit a559823de3
10 changed files with 94 additions and 119 deletions

View File

@ -26,7 +26,6 @@ namespace MCGalaxy.Commands {
public override string type { get { return CommandTypes.World; } }
public override bool museumUsable { get { return false; } }
public override LevelPermission defaultRank { get { return LevelPermission.Admin; } }
public CmdClearBlockChanges() { }
public override void Use(Player p, string message) {
if (p == null && message == "") {

View File

@ -1,85 +1,69 @@
/*
Written by Jack1312
Copyright 2011 MCGalaxy
Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php
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.
Copyright 2011 MCGalaxy
Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php
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.
*/
using System;
using System.IO;
namespace MCGalaxy.Commands
{
public class CmdCopyLVL : Command
{
namespace MCGalaxy.Commands {
public class CmdCopyLVL : Command {
public override string name { get { return "copylvl"; } }
public override string shortcut { get { return ""; } }
public override string type { get { return CommandTypes.World; } }
public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
public CmdCopyLVL() { }
public override void Use(Player p, string message)
{
string msg1 = String.Empty;
string msg2 = String.Empty;
try
{
msg1 = message.Split(' ')[0];
msg2 = message.Split(' ')[1];
public override void Use(Player p, string message) {
if (message == "") { Help(p); return; }
string[] args = message.ToLower().Split(' ');
if (args.Length < 2) {
Player.SendMessage(p, "You did not specify the destination level name."); return;
}
catch { }
if (!p.group.CanExecute(Command.all.Find("newlvl")))
{
Player.SendMessage(p, "You cannot use this command, unless you can use /newlvl!");
return;
}
int number = message.Split(' ').Length;
if (message == "")
{
Help(p);
return;
}
if (number < 2)
{
Player.SendMessage(p, "You did not specify the level it would be copied to as!");
return;
string src = args[0], dst = args[1];
if (!p.group.CanExecute(Command.all.Find("newlvl"))) {
Player.SendMessage(p, "You cannot use /copylvl as you cannot use /newlvl."); return;
}
if (!Player.ValidName(src)) { Player.SendMessage(p, "\"" + src + "\" is not a valid level name."); return; }
if (!Player.ValidName(dst)) { Player.SendMessage(p, "\"" + dst + "\" is not a valid level name."); return; }
if (!LevelInfo.ExistsOffline(src)) { Player.SendMessage(p, "The level \"" + src + "\" does not exist."); return; }
if (LevelInfo.ExistsOffline(dst)) { Player.SendMessage(p, "The level \"" + dst + "\" already exists."); return; }
try {
File.Copy("levels/" + msg1 + ".lvl", "levels/" + msg2 + ".lvl");
File.Copy("levels/level properties/" + msg1 + ".properties", "levels/level properties/" + msg2 + ".properties", false);
if (File.Exists("blockdefs/lvl_" + msg1 + ".json"))
File.Copy("blockdefs/lvl_" + msg1 + ".json", "blockdefs/lvl_" + msg2 + ".json");
File.Copy("levels/" + src + ".lvl", "levels/" + dst + ".lvl");
if (File.Exists("levels/level properties/" + src + ".properties"))
File.Copy("levels/level properties/" + src + ".properties", "levels/level properties/" + dst + ".properties", false);
if (File.Exists("blockdefs/lvl_" + src + ".json"))
File.Copy("blockdefs/lvl_" + src + ".json", "blockdefs/lvl_" + dst + ".json");
} catch (System.IO.FileNotFoundException) {
Player.SendMessage(p, msg2 + " does not exist!");
return;
Player.SendMessage(p, dst + " does not exist!"); return;
} catch (System.IO.IOException) {
Player.SendMessage(p, "The level, &c" + msg2 + " &e already exists!");
return;
} catch (System.ArgumentException) {
Player.SendMessage(p, "One or both level names are either invalid, or corrupt.");
return;
Player.SendMessage(p, "The level &c" + dst + " %S already exists!"); return;
}
Player.SendMessage(p, "The level, &c" + msg1 + " &ehas been copied to &c" + msg2 + "!");
Player.SendMessage(p, "The level &a" + src + " %Shas been copied to &a" + dst + ".");
}
public override void Help(Player p)
{
Player.SendMessage(p, "/copylvl [Level] [Copied Level] - Makes a copy of [Level] called [Copied Level].");
public override void Help(Player p) {
Player.SendMessage(p, "%T/copylvl [level] [copied level]");
Player.SendMessage(p, "%HMakes a copy of [level] called [copied Level].");
Player.SendMessage(p, "%HNote: Only the level file and level properties are copied.");
}
}
}

View File

@ -28,7 +28,6 @@ namespace MCGalaxy.Commands {
public override string type { get { return CommandTypes.World; } }
public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Admin; } }
public CmdDeleteLvl() { }
public override void Use(Player p, string message) {
if (message == "" || message.Split(' ').Length > 1) { Help(p); return; }

View File

@ -26,13 +26,11 @@ namespace MCGalaxy.Commands {
public override string type { get { return CommandTypes.World; } }
public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
public CmdEnvironment() { }
public override void Use(Player p, string message) {
message = message.ToLower();
if (message == "preset" || message == "l preset" || message == "level preset") {
SendPresetsMessage(p);
return;
SendPresetsMessage(p); return;
}
string[] args = message.Split(' ');

View File

@ -25,7 +25,6 @@ namespace MCGalaxy.Commands
public override string type { get { return CommandTypes.World; } }
public override bool museumUsable { get { return false; } }
public override LevelPermission defaultRank { get { return LevelPermission.Admin; } }
public CmdFixGrass() { }
public override void Use(Player p, string message) {
int totalFixed = 0;

View File

@ -27,12 +27,9 @@ namespace MCGalaxy.Commands
public override string type { get { return CommandTypes.World; } }
public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
public CmdImport() { }
public override void Use(Player p, string message) {
if (message == "") {
Help(p); return;
}
if (message == "") { Help(p); return; }
string fileName = "extra/import/" + message + ".dat";
if (!Directory.Exists("extra/import"))

View File

@ -35,13 +35,13 @@ namespace MCGalaxy.Commands
if (parts.Length == 1) {
if (!int.TryParse(parts[0], out seconds)) {
seconds = 30;
lvl = LevelInfo.Find(parts[0].ToLower());
lvl = LevelInfo.Find(parts[0]);
}
} else {
if (!int.TryParse(parts[0], out seconds)) {
Player.SendMessage(p, "You must specify pause time in seconds"); return;
}
lvl = LevelInfo.Find(parts[1].ToLower());
lvl = LevelInfo.Find(parts[1]);
}
}

View File

@ -25,7 +25,6 @@ namespace MCGalaxy.Commands {
public override string type { get { return CommandTypes.Other; } }
public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
public CmdTexture() { }
public override void Use(Player p, string message) {
if (message == "") { Help(p); return; }

View File

@ -1,24 +1,24 @@
/*
Copyright 2011 MCGalaxy
Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php
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 CmdRepeat : Command
{
Copyright 2011 MCGalaxy
Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php
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 CmdRepeat : Command {
public override string name { get { return "repeat"; } }
public override string shortcut { get { return "m"; } }
public override string type { get { return CommandTypes.Other; } }
@ -26,30 +26,30 @@ namespace MCGalaxy.Commands
public override LevelPermission defaultRank { get { return LevelPermission.Guest; } }
public CmdRepeat() { }
public override void Use(Player p, string message)
{
try
{
if (p.lastCMD == "") { Player.SendMessage(p, "No commands used yet."); return; }
if (p.lastCMD.Length > 5)
if (p.lastCMD.Substring(0, 6) == "static") { Player.SendMessage(p, "Can't repeat static"); return; }
Player.SendMessage(p, "Using &b/" + p.lastCMD);
if (p.lastCMD.IndexOf(' ') == -1)
{
Command.all.Find(p.lastCMD).Use(p, "");
}
else
{
Command.all.Find(p.lastCMD.Substring(0, p.lastCMD.IndexOf(' '))).Use(p, p.lastCMD.Substring(p.lastCMD.IndexOf(' ') + 1));
}
public override void Use(Player p, string message) {
if (p.lastCMD == "") { Player.SendMessage(p, "No commands used yet."); return; }
if (p.lastCMD.Length > 5 && p.lastCMD.Substring(0, 6) == "static") {
Player.SendMessage(p, "Can't repeat static"); return;
}
catch { Player.SendMessage(p, "An error occured!"); }
Player.SendMessage(p, "Using &b/" + p.lastCMD);
int argsIndex = p.lastCMD.IndexOf(' ');
string cmdName = argsIndex == -1 ? p.lastCMD : p.lastCMD.Substring(0, argsIndex);
string cmdMsg = argsIndex == -1 ? "" : p.lastCMD.Substring(argsIndex + 1);
Command cmd = Command.all.Find(cmdName);
if (cmd == null) {
Player.SendMessage(p, "Unknown command \"" + cmdName + "\".");
}
if (p != null && !p.group.CanExecute(cmd)) {
Player.SendMessage(p, "You are not allowed to use \"" + cmdName + "\"."); return;
}
cmd.Use(p, cmdMsg);
}
public override void Help(Player p)
{
Player.SendMessage(p, "/repeat - Repeats the last used command");
public override void Help(Player p) {
Player.SendMessage(p, "%T/repeat");
Player.SendMessage(p, "%HRepeats the last used command");
}
}
}

View File

@ -1527,7 +1527,7 @@ return;
void UseCommand(Command command, string cmd, string message) {
if (!group.CanExecute(command)) {
SendMessage("You are not allowed to use \"" + cmd + "\"."); return;
}
}
if (cmd != "repeat") lastCMD = cmd + " " + message;
if (level.name.Contains("Museum " + Server.DefaultColor) && !command.museumUsable ) {