Work properly when opchannel is unused, also use generic RaisePlayerAction event instead of hardcoding IRC behaviour.

This commit is contained in:
UnknownShadow200 2016-05-19 16:19:30 +10:00
parent 0407666986
commit 958a16dc25
8 changed files with 53 additions and 15 deletions

View File

@ -38,7 +38,7 @@ namespace MCGalaxy.Commands
Chat.GlobalChatLevel(p, "<Level>" + 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);
}
}

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -17,6 +17,8 @@
*/
using System;
namespace MCGalaxy {
public enum PlayerAction { Joker, Unjoker, AFK, UnAFK, JoinWorld, Me };
/// <summary> This is the player object </summary>
public sealed partial class Player {
@ -133,5 +135,16 @@ namespace MCGalaxy {
public static event OnPlayerRotate PlayerRotate = null;
/// <summary> Called when the player rotates. </summary>
public event OnPlayerRotate OnRotate = null;
/// <summary> Called when the player performs an action. </summary>
public delegate void OnPlayerAction(Player p, PlayerAction action,
string message, bool stealth);
/// <summary> Called when a player performs an action. </summary>
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);
}
}
}

View File

@ -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;

View File

@ -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