From 8bcc24da7e5961f2c8c35604818cae642fb8dbf8 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sun, 27 May 2012 10:19:52 -0600 Subject: [PATCH] Added some code to enable chat above heads --- TShockAPI/ConfigFile.cs | 3 +++ TShockAPI/TSPlayer.cs | 13 +++++++++++++ TShockAPI/TShock.cs | 6 +++++- TShockAPI/Utils.cs | 15 +++++++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/TShockAPI/ConfigFile.cs b/TShockAPI/ConfigFile.cs index 9ed1bd7e..4ac35b59 100644 --- a/TShockAPI/ConfigFile.cs +++ b/TShockAPI/ConfigFile.cs @@ -234,6 +234,9 @@ namespace TShockAPI [Description("Prevent players from interacting with the world if dead")] public bool PreventDeadModification = false; + [Description("Displays chat messages above players' heads, but will disable chat prefixes to compensate.")] public + bool EnableChatAboveHeads = false; + /// /// Reads a configuration file from a given path /// diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index 3df802d3..a35c9447 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -422,6 +422,11 @@ namespace TShockAPI SendData(PacketTypes.ChatText, msg, 255, red, green, blue); } + public virtual void SendMessageFromPlayer(string msg, byte red, byte green, byte blue, int ply) + { + SendDataFromPlayer(PacketTypes.ChatText, ply, msg, 255, red, green, blue); + } + public virtual void DamagePlayer(int damage) { NetMessage.SendData((int) PacketTypes.PlayerDamage, -1, -1, "", Index, ((new Random()).Next(-1, 1)), damage, @@ -481,6 +486,14 @@ namespace TShockAPI NetMessage.SendData((int) msgType, Index, -1, text, number, number2, number3, number4, number5); } + public virtual void SendDataFromPlayer(PacketTypes msgType, int ply, string text = "", int number = 0, float number2 = 0f, float number3 = 0f, float number4 = 0f, int number5 = 0) + { + if (RealPlayer && !ConnectionAlive) + return; + + NetMessage.SendData((int) msgType, Index, ply, text, number, number2, number3, number4, number5); + } + public virtual bool SendRawData(byte[] data) { if (!RealPlayer || !ConnectionAlive) diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 464e5823..f4c493b9 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -801,12 +801,16 @@ namespace TShockAPI Log.Error(ex.ToString()); } } - else if (!tsplr.mute) + else if (!tsplr.mute && !TShock.Config.EnableChatAboveHeads) { Utils.Broadcast( String.Format(Config.ChatFormat, tsplr.Group.Name, tsplr.Group.Prefix, tsplr.Name, tsplr.Group.Suffix, text), tsplr.Group.R, tsplr.Group.G, tsplr.Group.B); e.Handled = true; + } else if (!tsplr.mute && TShock.Config.EnableChatAboveHeads) + { + Utils.Broadcast(ply, text, tsplr.Group.R, tsplr.Group.G, tsplr.Group.B); + e.Handled = true; } else if (tsplr.mute) { diff --git a/TShockAPI/Utils.cs b/TShockAPI/Utils.cs index 6c974788..dd3c1966 100644 --- a/TShockAPI/Utils.cs +++ b/TShockAPI/Utils.cs @@ -171,6 +171,21 @@ namespace TShockAPI Broadcast(msg, color.R, color.G, color.B); } + /// + /// Broadcasts a message from a player, not TShock + /// + /// TSPlayer ply - the player that will send the packet + /// string msg - the message + /// r + /// g + /// b + public void Broadcast(int ply, string msg, byte red, byte green, byte blue) + { + TSPlayer.All.SendMessageFromPlayer(msg, red, green, blue, ply); + TSPlayer.Server.SendMessage(msg, red, green, blue); + Log.Info(string.Format("Broadcast: {0}", msg)); + } + /// /// Sends message to all users with 'logs' permission. ///