/adminchat

/adminchat

Postby ismellike » 20 Jul 2013, 02:21

Here is a nice little command that was suggested.
/adminchat or /achat allows you to only talk to the admins in game.
It has the same feel as opchat.
I had some stuff in there for debugging purposes like /achat admins or /achat remove, so just ignore them. I left them in there in case you wanted to see who is considered admin easily.

Code: Select all
using System;
namespace MCDzienny
{
    public class CmdAdminchat : Command
    {
        public override string name { get { return "adminchat"; } }
        public override string shortcut { get { return "achat"; } }
        public override string type { get { return "mod"; } }
        public override bool museumUsable { get { return false; } }
        public override LevelPermission defaultRank { get { return LevelPermission.Admin; } }
        public override bool ConsoleAccess { get { return false; } }
        public override void Init()
        {
            Player.ChatOther += new EventHandler<ChatOtherEventArgs>(ChatOE);
            Player.Joined += new EventHandler<PlayerEventArgs>(PlayerJE);
            Player.PlayerChatEvent += AddStuff;
            Player.players.ForEach(delegate(Player pl)
            {
                AddVars(pl);
            });
        }
        void AddStuff(Player p, ref string message, ref bool stopIt)
        {
            if (message[0] == '^' || message[2] == '^') //take in mind color chat people :)
            {
                SendAdmins(p, null, message);
                stopIt = true;
            }
        }
        void SendAdmins(Player p, Player who, string message)
        {
            if (who == null)
            {
                message = message.Substring(message.IndexOf('^') + 1);
                Player.players.ForEach(delegate(Player pl)
                {
                    if (pl.group.Permission >= LevelPermission.Admin || pl == p)
                        pl.SendMessage("%eTo Admins %f-" + p.color + p.PublicName + "%f- " + message);
                });
            }
            else
            {
                who.SendMessage("%eTo Admins %f-" + p.color + p.PublicName + "%f- " + message);
            }
        }
        string admins()
        {
            string builder = "Admins: ";
            Player.players.ForEach(delegate(Player pl)
            {
                if (pl.group.Permission >= LevelPermission.Admin)
                    builder += pl.PublicName + ", ";
            });
            return builder;
        }
        public override void Use(Player p, string message)
        {
            switch (message)
            {
                case "admins":
                    Player.SendMessage(p, admins());
                    break;
                case "remove":
                    Player.ChatOther -= ChatOE;
                    Player.Joined -= PlayerJE;
                    Player.PlayerChatEvent -= AddStuff;
                    Player.SendMessage(p, "Events removed");
                    break;
                default:
                    p.ExtraData["achat"] = !(bool)p.ExtraData["achat"];
                    Player.SendMessage(p, "Admin chat has been set to " + p.ExtraData["achat"].ToString() + ".");
                    break;
            }
        }
        public override void Help(Player p)
        {
            Player.SendMessage(p, "/%aadminchat" + Server.DefaultColor + " -- turns admin chat on/off");
            Player.SendMessage(p, "Shortcut: /achat or use ^ as first letter in message");
        }
        public void AddVars(Player p)
        {
            if (!p.ExtraData.ContainsKey("achat"))
                p.ExtraData.Add("achat", false);
        }
        public void PlayerJE(object sender, PlayerEventArgs e)
        {
            AddVars(e.Player);
        }
        public void ChatOE(object sender, ChatOtherEventArgs e)
        {
            if ((bool)e.From.ExtraData["achat"] == true)
            {
                if (e.To.group.Permission >= LevelPermission.Admin)
                {
                    string message = e.Message.Substring(e.Message.IndexOf(':') + 1);
                    SendAdmins(e.From, e.To, message);
                }
                e.Handled = true;
            }
        }
    }
}

What a beast...
User avatar
ismellike
Coder
 
Posts: 731
Joined: 31 Oct 2012, 04:04
Location: Kansas

Re: /adminchat

Postby Clowny » 20 Jul 2013, 03:11

Nice a lot of people will finds this usefull <ok>
Founder Of MC Classic Hosting Community http://mcclassichosting.webs.com
Founder of MC Classic Software MCReborn http://mcreborn.tk
Professional Hoster and Basic C# Coder
Image
User avatar
Clowny
 
Posts: 112
Joined: 14 Jul 2013, 03:53

Re: /adminchat

Postby Leeizazombie » 20 Jul 2013, 03:12

Very nice! I wana ask.. is void like a triggered event? like when you click a button, it can trigger it?
Owner of:
LeeIzaZombie Freebuild and Lava Survival V2 (Shut Down and updated)
LeeIzaZombie Survival (Comming back soon)

Contact:
Skype: leeizazombie
IRC: irc.geekshed.net, #leeizazombie, #mcclassichosting
User avatar
Leeizazombie
 
Posts: 536
Joined: 10 Jun 2013, 17:45
Location: Ireland.

Re: /adminchat

Postby ismellike » 20 Jul 2013, 03:19

Leeizazombie wrote:Very nice! I wana ask.. is void like a triggered event? like when you click a button, it can trigger it?


I think of a void more as a chunk. Whenever you call up a void, it does everything that is inside. Buttons need a Click event to call up a void on click.
What a beast...
User avatar
ismellike
Coder
 
Posts: 731
Joined: 31 Oct 2012, 04:04
Location: Kansas


Return to Custom Commands

Who is online

Users browsing this forum: No registered users and 6 guests

cron