diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..598dd721 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*] +end_of_line = crlf +insert_final_newline = true + +[*.cs] +indent_style = tab +trim_trailing_whitespace = true diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index a2c925d7..ce231c60 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -244,7 +244,8 @@ namespace TShockAPI add(Permissions.savessi, SaveSSI, "savessi"); add(Permissions.savessi, OverrideSSI, "overridessi", "ossi"); add(Permissions.xmas, ForceXmas, "forcexmas"); - add(Permissions.settempgroup, TempGroup, "tempgroup"); + add(Permissions.settempgroup, TempGroup, "tempgroup"); + add(null, Aliases, "aliases"); //add(null, TestCallbackCommand, "test"); TShockCommands = new ReadOnlyCollection(tshockCommands); @@ -282,7 +283,7 @@ namespace TShockAPI { if (!cmd.CanRun(player)) { - TShock.Utils.SendLogs(string.Format("{0} tried to execute /{1}.", player.Name, cmdText), Color.Red); + TShock.Utils.SendLogs(string.Format("{0} tried to execute /{1}.", player.Name, cmdText), Color.PaleVioletRed, player); player.SendErrorMessage("You do not have access to that command."); } else if (!cmd.AllowServer && !player.RealPlayer) @@ -292,7 +293,7 @@ namespace TShockAPI else { if (cmd.DoLog) - TShock.Utils.SendLogs(string.Format("{0} executed: /{1}.", player.Name, cmdText), Color.Red); + TShock.Utils.SendLogs(string.Format("{0} executed: /{1}.", player.Name, cmdText), Color.PaleVioletRed, player); cmd.Run(cmdText, player, args); } } @@ -1288,8 +1289,9 @@ namespace TShockAPI { message += " " + args.Parameters[i]; } - - TShock.Utils.Broadcast("(Server Broadcast)" + message, Color.Red); + + Color color = new Color(TShock.Config.BroadcastRGB[0], TShock.Config.BroadcastRGB[1], TShock.Config.BroadcastRGB[2]); + TShock.Utils.Broadcast("(Server Broadcast)" + message, color); return; } @@ -2879,7 +2881,7 @@ namespace TShockAPI args.Player, pageNumber, lines, new PaginationTools.Settings { HeaderFormat = string.Format("Information About Region \"{0}\" ({{0}}/{{1}}):", region.Name), - FooterFormat = "Type /region info {0} for more information." + FooterFormat = string.Format("Type /region info {0} {{0}} for more information.", regionName) } ); @@ -3372,6 +3374,41 @@ namespace TShockAPI args.Player.SendSuccessMessage("Annoying " + ply.Name + " for " + annoy + " seconds."); (new Thread(ply.Whoopie)).Start(annoy); } + } + + private static void Aliases(CommandArgs args) + { + if (args.Parameters.Count < 1) + { + args.Player.SendErrorMessage("Invalid syntax! Proper syntax: /aliases "); + return; + } + + string givenCommandName = string.Join(" ", args.Parameters); + if (string.IsNullOrWhiteSpace(givenCommandName)) { + args.Player.SendErrorMessage("Please enter a proper command name or alias."); + return; + } + + string commandName; + if (givenCommandName[0] == '/') + commandName = givenCommandName.Substring(1); + else + commandName = givenCommandName; + + bool didMatch = false; + foreach (Command matchingCommand in ChatCommands.Where(cmd => cmd.Names.IndexOf(commandName) != -1)) { + if (matchingCommand.Names.Count > 1) + args.Player.SendInfoMessage( + "Aliases of /{0}: /{1}", matchingCommand.Name, string.Join(", /", matchingCommand.Names.Skip(1))); + else + args.Player.SendInfoMessage("/{0} defines no aliases.", matchingCommand.Name); + + didMatch = true; + } + + if (!didMatch) + args.Player.SendErrorMessage("No command or command alias matching \"{0}\" found.", givenCommandName); } #endregion General Commands diff --git a/TShockAPI/ConfigFile.cs b/TShockAPI/ConfigFile.cs index dec09a6d..304de298 100644 --- a/TShockAPI/ConfigFile.cs +++ b/TShockAPI/ConfigFile.cs @@ -251,7 +251,10 @@ namespace TShockAPI [Description("The path of the directory where logs should be written into.")] public string LogPath = "tshock"; - [Description("Prevents players from placing tiles with an invalid style.")] public bool PreventInvalidPlaceStyle = true; + [Description("Prevents players from placing tiles with an invalid style.")] public bool PreventInvalidPlaceStyle = true; + + [Description("#.#.#. = Red/Blue/Green - RGB Colors for broadcasts. Max value: 255.")] public float[] BroadcastRGB = + {127,255,212}; /// /// Reads a configuration file from a given path diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index e8ff6d65..bd77b273 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -2922,7 +2922,7 @@ namespace TShockAPI break; } - TShock.Utils.SendLogs(string.Format("{0} summoned {1}", args.Player.Name, boss), Color.Red); + TShock.Utils.SendLogs(string.Format("{0} summoned {1}", args.Player.Name, boss), Color.PaleVioletRed, args.Player); return false; } } diff --git a/TShockAPI/Log.cs b/TShockAPI/Log.cs index 9e54c53a..b04bc4c9 100644 --- a/TShockAPI/Log.cs +++ b/TShockAPI/Log.cs @@ -70,6 +70,16 @@ namespace TShockAPI public static void Data(String message) { Write(message, LogLevel.Data); + } + + /// + /// Writes data to the log file. + /// + /// The format of the message to be written. + /// The format arguments. + public static void Data(String format, params String[] args) + { + Data(String.Format(format, args)); } /// @@ -79,6 +89,16 @@ namespace TShockAPI public static void Error(String message) { Write(message, LogLevel.Error); + } + + /// + /// Writes an error to the log file. + /// + /// The format of the message to be written. + /// The format arguments. + public static void Error(String format, params String[] args) + { + Error(String.Format(format, args)); } /// @@ -91,6 +111,16 @@ namespace TShockAPI Console.WriteLine(message); Console.ForegroundColor = ConsoleColor.Gray; Write(message, LogLevel.Error); + } + + /// + /// Writes an error to the log file. + /// + /// The format of the message to be written. + /// The format arguments. + public static void ConsoleError(String format, params String[] args) + { + ConsoleError(String.Format(format, args)); } /// @@ -100,6 +130,16 @@ namespace TShockAPI public static void Warn(String message) { Write(message, LogLevel.Warning); + } + + /// + /// Writes a warning to the log file. + /// + /// The format of the message to be written. + /// The format arguments. + public static void Warn(String format, params String[] args) + { + Warn(String.Format(format, args)); } /// @@ -109,6 +149,16 @@ namespace TShockAPI public static void Info(String message) { Write(message, LogLevel.Info); + } + + /// + /// Writes an informative string to the log file. + /// + /// The format of the message to be written. + /// The format arguments. + public static void Info(String format, params String[] args) + { + Info(String.Format(format, args)); } /// @@ -121,6 +171,16 @@ namespace TShockAPI Console.WriteLine(message); Console.ForegroundColor = ConsoleColor.Gray; Write(message, LogLevel.Info); + } + + /// + /// Writes an informative string to the log file. Also outputs to the console. + /// + /// The format of the message to be written. + /// The format arguments. + public static void ConsoleInfo(String format, params String[] args) + { + ConsoleInfo(String.Format(format, args)); } /// @@ -130,6 +190,16 @@ namespace TShockAPI public static void Debug(String message) { Write(message, LogLevel.Debug); + } + + /// + /// Writes a debug string to the log file. + /// + /// The format of the message to be written. + /// The format arguments. + public static void Debug(String format, params String[] args) + { + Debug(String.Format(format, args)); } /// diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index 986d3147..bd13cfd4 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -899,6 +899,10 @@ namespace TShockAPI public void StrikeNPC(int npcid, int damage, float knockBack, int hitDirection) { + // Main.rand is thread static. + if (Main.rand == null) + Main.rand = new Random(); + Main.npc[npcid].StrikeNPC(damage, knockBack, hitDirection); NetMessage.SendData((int) PacketTypes.NpcStrike, -1, -1, "", npcid, damage, knockBack, hitDirection); } diff --git a/TShockAPI/Utils.cs b/TShockAPI/Utils.cs index f98cb284..5f0d8706 100644 --- a/TShockAPI/Utils.cs +++ b/TShockAPI/Utils.cs @@ -218,18 +218,19 @@ namespace TShockAPI } /// - /// Sends message to all users with 'logs' permission. + /// Sends message to all players with 'logs' permission. /// /// Message to send - /// Color of the message - public void SendLogs(string log, Color color) + /// Color of the message + /// The player to not send the message to. + public void SendLogs(string log, Color color, TSPlayer excludedPlayer = null) { Log.Info(log); TSPlayer.Server.SendMessage(log, color); foreach (TSPlayer player in TShock.Players) { - if (player != null && player.Active && player.Group.HasPermission(Permissions.logs) && player.DisplayLogs && - TShock.Config.DisableSpewLogs == false) + if (player != null && player != excludedPlayer && player.Active && player.Group.HasPermission(Permissions.logs) && + player.DisplayLogs && TShock.Config.DisableSpewLogs == false) player.SendMessage(log, color); } }