diff --git a/Commands/Chat/CmdMe.cs b/Commands/Chat/CmdMe.cs index 222433603..dd88f78bf 100644 --- a/Commands/Chat/CmdMe.cs +++ b/Commands/Chat/CmdMe.cs @@ -38,7 +38,7 @@ namespace MCGalaxy.Commands Chat.GlobalChatLevel(p, "" + p.color + "*" + Colors.StripColours(p.DisplayName) + " " + message, false); } else { Player.SendChatFrom(p, p.color + "*" + Colors.StripColours(p.DisplayName) + " " + message, false); - Server.IRC.Say("*" + p.DisplayName + " " + message); + Player.RaisePlayerAction(p, PlayerAction.Me, message); } } diff --git a/Commands/Information/CmdAfk.cs b/Commands/Information/CmdAfk.cs index 9b9afd1ad..a59616277 100644 --- a/Commands/Information/CmdAfk.cs +++ b/Commands/Information/CmdAfk.cs @@ -51,12 +51,12 @@ namespace MCGalaxy.Commands p.afkMessage = message; p.IsAfk = true; Player.GlobalMessage("-" + p.ColoredName + "%S- is AFK " + message); - Server.IRC.Say(p.DisplayName + " is AFK " + message); + Player.RaisePlayerAction(p, PlayerAction.AFK, message); } else { p.IsAfk = false; p.afkMessage = null; Player.GlobalMessage("-" + p.ColoredName + "%S- is no longer AFK"); - Server.IRC.Say(p.DisplayName + " is no longer AFK"); + Player.RaisePlayerAction(p, PlayerAction.UnAFK, message); } TabList.Update(p, true); } diff --git a/Commands/Moderation/CmdJoker.cs b/Commands/Moderation/CmdJoker.cs index 79b15bd33..a223bcc97 100644 --- a/Commands/Moderation/CmdJoker.cs +++ b/Commands/Moderation/CmdJoker.cs @@ -47,14 +47,14 @@ namespace MCGalaxy.Commands { } else { Player.SendChatFrom(who, who.ColoredName + " %Sis now a &aJ&bo&ck&5e&9r%S.", false); } - Server.IRC.Say(who.ColoredName + " %Sis now a &aJ&bo&ck&5e&9r%S.", stealth); + Player.RaisePlayerAction(p, PlayerAction.Joker, null, stealth); } else { if (stealth) { Chat.GlobalMessageOps(who.ColoredName + " %Sis now STEALTH unjokered."); } else { Player.SendChatFrom(who, who.ColoredName + " %Sis no longer a &aJ&bo&ck&5e&9r%S.", false); } - Server.IRC.Say(who.ColoredName + " %Sis no longer a &aJ&bo&ck&5e&9r%S.", stealth); + Player.RaisePlayerAction(p, PlayerAction.Unjoker, null, stealth); } who.joker = !who.joker; } diff --git a/Commands/World/CmdGoto.cs b/Commands/World/CmdGoto.cs index ea4639090..600207435 100644 --- a/Commands/World/CmdGoto.cs +++ b/Commands/World/CmdGoto.cs @@ -137,7 +137,7 @@ namespace MCGalaxy.Commands { bool showJoin = p.level.ShouldSaveChanges() || (oldLevel != null && oldLevel.ShouldSaveChanges()); if (!p.hidden && showJoin) { Player.SendChatFrom(p, p.color + "*" + p.DisplayName + " %Swent to &b" + lvl.name, false); - Server.IRC.Say(p.ColoredName + " %rwent to &8" + lvl.name, false, true); + Player.RaisePlayerAction(p, PlayerAction.JoinWorld, lvl.name); } return true; } diff --git a/Commands/World/CmdPhysics.cs b/Commands/World/CmdPhysics.cs index 2f8e7541b..ce52393c4 100644 --- a/Commands/World/CmdPhysics.cs +++ b/Commands/World/CmdPhysics.cs @@ -53,15 +53,13 @@ namespace MCGalaxy.Commands } level.setPhysics(state); - if (state == 0) - level.ClearPhysics(); + if (state == 0) level.ClearPhysics(); string stateDesc = states[state]; - Player.GlobalMessage("Physics are now " + stateDesc + "%S on &b" + level.name + "%S."); - stateDesc = stateDesc.Substring( 2 ); + level.ChatLevel("Physics are now " + stateDesc + "%S on &b" + level.name + "%S."); + stateDesc = stateDesc.Substring( 2 ); string logInfo = "Physics are now " + stateDesc + " on " + level.name + "."; Server.s.Log(logInfo); - Server.IRC.Say(logInfo); level.changed = true; } diff --git a/Events/Player.Events.cs b/Events/Player.Events.cs index d7e285ad4..5e83cf907 100644 --- a/Events/Player.Events.cs +++ b/Events/Player.Events.cs @@ -17,9 +17,11 @@ */ using System; namespace MCGalaxy { + public enum PlayerAction { Joker, Unjoker, AFK, UnAFK, JoinWorld, Me }; + /// This is the player object public sealed partial class Player { - + internal bool cancelcommand = false; internal bool cancelchat = false; internal bool cancelmove = false; @@ -133,5 +135,16 @@ namespace MCGalaxy { public static event OnPlayerRotate PlayerRotate = null; /// Called when the player rotates. public event OnPlayerRotate OnRotate = null; + + /// Called when the player performs an action. + public delegate void OnPlayerAction(Player p, PlayerAction action, + string message, bool stealth); + /// Called when a player performs an action. + public static event OnPlayerAction DoPlayerAction = null; + public static void RaisePlayerAction(Player p, PlayerAction action, + string message = null, bool stealth = false) { + OnPlayerAction change = DoPlayerAction; + if (change != null) change(p, action, message, stealth); + } } } diff --git a/IRC/ForgeBot.cs b/IRC/ForgeBot.cs index b2fce0890..3ddd2818c 100644 --- a/IRC/ForgeBot.cs +++ b/IRC/ForgeBot.cs @@ -53,6 +53,7 @@ namespace MCGalaxy { Player.PlayerChat += Player_PlayerChat; Player.PlayerConnect += Player_PlayerConnect; Player.PlayerDisconnect += Player_PlayerDisconnect; + Player.DoPlayerAction += Player_PlayerAction; // Regster events for incoming connection.Listener.OnNick += Listener_OnNick; @@ -81,7 +82,9 @@ namespace MCGalaxy { File.Delete("text/ircbancmd.txt"); } else { if (!File.Exists("text/irccmdblacklist.txt")) - File.WriteAllLines("text/irccmdblacklist.txt", new String[] { "#Here you can put commands that cannot be used from the IRC bot.", "#Lines starting with \"#\" are ignored." }); + File.WriteAllLines("text/irccmdblacklist.txt", new [] { + "#Here you can put commands that cannot be used from the IRC bot.", + "#Lines starting with \"#\" are ignored." }); foreach (string line in File.ReadAllLines("text/irccmdblacklist.txt")) if (line[0] != '#') banCmd.Add(line); } @@ -91,7 +94,10 @@ namespace MCGalaxy { public void Say(string message, bool opchat = false, bool color = true) { if (!Server.irc || !IsConnected()) return; message = ConvertMessage(message, color); - connection.Sender.PublicMessage(opchat ? opchannel : channel, message); + + string chan = opchat ? opchannel : channel; + if (!String.IsNullOrEmpty(chan)) + connection.Sender.PublicMessage(chan, message); } public void Pm(string user, string message, bool color = true) { @@ -159,6 +165,27 @@ namespace MCGalaxy { #region In-game event handlers + void Player_PlayerAction(Player p, PlayerAction action, + string message, bool stealth) { + if (!Server.irc || !IsConnected()) return; + string msg = null; + if (action == PlayerAction.AFK) + msg = p.ColoredName + " %ris AFK " + message; + else if (action == PlayerAction.UnAFK) + msg = p.ColoredName + " %ris no longer AFK"; + else if (action == PlayerAction.Joker) + msg = p.ColoredName + " %ris now a &aJ&bo&ck&5e&9r%S"; + else if (action == PlayerAction.Unjoker) + msg = p.ColoredName + " %ris no longer a &aJ&bo&ck&5e&9r%S"; + else if (action == PlayerAction.JoinWorld) + msg = p.ColoredName + " %rwent to &8" + message; + else if (action == PlayerAction.Me) + msg = "*" + p.DisplayName + " " + message; + + if (msg != null) + Say(msg, stealth); + } + void Player_PlayerDisconnect(Player p, string reason) { if (!Server.irc || !IsConnected()) return; if (!Server.guestLeaveNotify && p.group.Permission <= LevelPermission.Guest) return; diff --git a/Player/Player.Handlers.cs b/Player/Player.Handlers.cs index 739686ab8..0c1141f62 100644 --- a/Player/Player.Handlers.cs +++ b/Player/Player.Handlers.cs @@ -1013,7 +1013,7 @@ try { SendBlockchange(pos1.x, pos1.y, pos1.z, Block.waterstill); } catch { } IsAfk = false; afkMessage = null; Player.GlobalMessage("-" + ColoredName + "%S- is no longer AFK"); - Server.IRC.Say(DisplayName + " is no longer AFK"); + RaisePlayerAction(this, PlayerAction.UnAFK, null, false); TabList.Update(this, true); } // Typing //Command appears in chat as /command