diff --git a/Commands/World/CmdClearBlockChanges.cs b/Commands/World/CmdClearBlockChanges.cs index ac5a8b04f..547ec2fb4 100644 --- a/Commands/World/CmdClearBlockChanges.cs +++ b/Commands/World/CmdClearBlockChanges.cs @@ -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 == "") { diff --git a/Commands/World/CmdCopyLVL.cs b/Commands/World/CmdCopyLVL.cs index d0dac08b5..827318393 100644 --- a/Commands/World/CmdCopyLVL.cs +++ b/Commands/World/CmdCopyLVL.cs @@ -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."); } } } diff --git a/Commands/World/CmdDeleteLvl.cs b/Commands/World/CmdDeleteLvl.cs index 403a1db8e..157cb7907 100644 --- a/Commands/World/CmdDeleteLvl.cs +++ b/Commands/World/CmdDeleteLvl.cs @@ -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; } diff --git a/Commands/World/CmdEnvironment.cs b/Commands/World/CmdEnvironment.cs index a32ed42e5..d20875494 100644 --- a/Commands/World/CmdEnvironment.cs +++ b/Commands/World/CmdEnvironment.cs @@ -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(' '); diff --git a/Commands/World/CmdFixGrass.cs b/Commands/World/CmdFixGrass.cs index e210ef9b1..58b80bb29 100644 --- a/Commands/World/CmdFixGrass.cs +++ b/Commands/World/CmdFixGrass.cs @@ -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; diff --git a/Commands/World/CmdImport.cs b/Commands/World/CmdImport.cs index 13eb6d727..716eac380 100644 --- a/Commands/World/CmdImport.cs +++ b/Commands/World/CmdImport.cs @@ -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")) diff --git a/Commands/World/CmdPause.cs b/Commands/World/CmdPause.cs index a7535136a..76e2434a4 100644 --- a/Commands/World/CmdPause.cs +++ b/Commands/World/CmdPause.cs @@ -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]); } } diff --git a/Commands/World/CmdTexture.cs b/Commands/World/CmdTexture.cs index ab54a2151..732280a69 100644 --- a/Commands/World/CmdTexture.cs +++ b/Commands/World/CmdTexture.cs @@ -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; } diff --git a/Commands/other/CmdRepeat.cs b/Commands/other/CmdRepeat.cs index 451186a02..ade91e51e 100644 --- a/Commands/other/CmdRepeat.cs +++ b/Commands/other/CmdRepeat.cs @@ -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"); } } } diff --git a/Player/Player.Handlers.cs b/Player/Player.Handlers.cs index 21ca1dc54..8f36b4e58 100644 --- a/Player/Player.Handlers.cs +++ b/Player/Player.Handlers.cs @@ -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 ) {