From c9722526a42bd6c7f43c60ea9280184d415ca419 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 31 Mar 2016 11:54:32 +1100 Subject: [PATCH] Using /repeat now works with /static, also /last should show time of use. (Thanks Zingan) --- Commands/Information/CmdLastCmd.cs | 79 +++++++++++++----------------- Commands/building/CmdStatic.cs | 2 +- Commands/other/CmdRepeat.cs | 5 +- Player/Player.Handlers.cs | 7 ++- Player/Player.cs | 1 + 5 files changed, 43 insertions(+), 51 deletions(-) diff --git a/Commands/Information/CmdLastCmd.cs b/Commands/Information/CmdLastCmd.cs index 524979bc8..6dc2a7a68 100644 --- a/Commands/Information/CmdLastCmd.cs +++ b/Commands/Information/CmdLastCmd.cs @@ -1,24 +1,23 @@ /* - Copyright 2011 MCForge - - 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 MCForge + + 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 CmdLastCmd : Command - { +namespace MCGalaxy.Commands { + + public sealed class CmdLastCmd : Command { public override string name { get { return "lastcmd"; } } public override string shortcut { get { return "last"; } } public override string type { get { return CommandTypes.Information; } } @@ -26,36 +25,28 @@ namespace MCGalaxy.Commands public override LevelPermission defaultRank { get { return LevelPermission.Operator; } } public CmdLastCmd() { } - public override void Use(Player p, string message) - { - if (message == "") - { - Player[] players = PlayerInfo.Online.Items; - foreach (Player pl in players) - { - if (pl.lastCMD.Contains("setpass") || pl.lastCMD.Contains("pass")) - { - pl.lastCMD = ""; - } + public override void Use(Player p, string message) { + if (message == "") { + Player[] players = PlayerInfo.Online.Items; + foreach (Player pl in players) { if (Player.CanSee(p, pl)) - { - Player.SendMessage(p, pl.color + pl.DisplayName + " %Slast used \"" + pl.lastCMD + "\""); - } + ShowLastCommand(p, pl); } - } - else - { + } else { Player who = PlayerInfo.FindOrShowMatches(p, message); - if (who == null) return; - if (who.lastCMD.Contains("setpass") || who.lastCMD.Contains("pass")) - { - who.lastCMD = ""; - } - Player.SendMessage(p, who.color + who.DisplayName + " %Slast used \"" + who.lastCMD + "\""); + if (who != null) + ShowLastCommand(p, who); } } - public override void Help(Player p) - { + + static void ShowLastCommand(Player p, Player who) { + if (who.lastCMD == "") + Player.SendMessage(p, who.color + who.DisplayName + " %Shas not used any commands yet."); + else + Player.SendMessage(p, who.color + who.DisplayName + " %Slast used \"" + who.lastCMD + "\" on " + who.lastCmdTime); + } + + public override void Help(Player p) { Player.SendMessage(p, "/last [user] - Shows last command used by [user]"); Player.SendMessage(p, "/last by itself will show all last commands (SPAMMY)"); } diff --git a/Commands/building/CmdStatic.cs b/Commands/building/CmdStatic.cs index 89b69265e..8c3e92b46 100644 --- a/Commands/building/CmdStatic.cs +++ b/Commands/building/CmdStatic.cs @@ -32,7 +32,7 @@ namespace MCGalaxy.Commands { p.modeType = 0; Player.SendMessage(p, "Static mode: &a" + p.staticCommands); - if (message == "") return; + if (message == "" || !p.staticCommands) return; string[] parts = message.Split(new char[] { ' ' }, 2); Command cmd = Command.all.Find(parts[0]); diff --git a/Commands/other/CmdRepeat.cs b/Commands/other/CmdRepeat.cs index 44506ba02..58ef6eedf 100644 --- a/Commands/other/CmdRepeat.cs +++ b/Commands/other/CmdRepeat.cs @@ -28,11 +28,8 @@ namespace MCGalaxy.Commands { 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; - } - Player.SendMessage(p, "Using &b/" + p.lastCMD); + Player.SendMessage(p, "Repeating &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); diff --git a/Player/Player.Handlers.cs b/Player/Player.Handlers.cs index 62631e445..1261cc0bb 100644 --- a/Player/Player.Handlers.cs +++ b/Player/Player.Handlers.cs @@ -91,7 +91,7 @@ namespace MCGalaxy { int Diff = Math.Abs((pos[0] / 32) - x) + Math.Abs((pos[1] / 32) - y) + Math.Abs((pos[2] / 32) - z); - if ((Diff > ReachDistance + 4) && lastCMD != "click") { + if ((Diff > ReachDistance + 4) && (lastCMD == "click" || lastCMD == "mark")) { Server.s.Log(name + " attempted to build with a " + Diff + " distance offset"); SendMessage("You can't build that far away."); RevertBlock(x, y, z); return; @@ -1498,7 +1498,10 @@ return; SendMessage("The game or economy associated with this command is not running, " + "so this command is disabled."); return; } - if (cmd != "repeat") lastCMD = cmd + " " + message; + if (!(cmd == "repeat" || cmd == "pass" || cmd == "setpass")) { + lastCMD = cmd + " " + message; + lastCmdTime = DateTime.Now; + } if (level.IsMuseum && !command.museumUsable ) { SendMessage("Cannot use this command while in a museum!"); return; diff --git a/Player/Player.cs b/Player/Player.cs index 40414bf5e..0c5f39089 100644 --- a/Player/Player.cs +++ b/Player/Player.cs @@ -238,6 +238,7 @@ namespace MCGalaxy { public string[] cmdBind = new string[10]; public string[] messageBind = new string[10]; public string lastCMD = ""; + public DateTime lastCmdTime; public sbyte c4circuitNumber = -1; public Level level = Server.mainLevel;