Send message to all admins and ops?

Send message to all admins and ops?

Postby joppiesaus » 10 Jan 2014, 20:49

So, I am making a command that clears all of your player data, but it needs to be "approved" by a admin / op, how do I send I a message to every guy in that ranklist?
Thanks!
joppiesaus
 
Posts: 379
Joined: 20 Aug 2012, 07:28
Location: in a obsedian house, with glass in it so i can see the lava!

Re: Send message to all admins and ops?

Postby dzienny » 10 Jan 2014, 22:17

The code below shows how to get a list of players that are ranked Op. It then checks, if they are online. If yes it sends them a message. This code makes use of powerful LINQ.
Code: Select all
var operatorGroup = Group.groupList.Where(g => g.Permission == LevelPermission.Operator).First();
var operators = operatorGroup.playerList.All();
foreach (var op in operators)
{
    var opOnline = Player.Find(op);
    if (opOnline == null)
        continue;
    Player.SendMessage(opOnline, "Some message");
}


If you want to get a list of Op+ players, then replace the two first lines with this:
Code: Select all
var operatorPlusGroup = Group.groupList.Where(g => g.Permission >= LevelPermission.Operator);
var operatorsPlus = operatorPlusGroup.SelectMany(g => g.playerList.All());


Well, you can do the same without LINQ (below), but I recommend LINQ because it's more readable and concise.
Code: Select all
Group operatorGroup = null;
foreach (Group g in Group.groupList)
{
    if (g.Permission == LevelPermission.Operator)
    {
        operatorGroup = g;
        break;
    }
}
List<string> operators = operatorGroup.playerList.All();


*I haven't tested it, but it should work.
User avatar
dzienny
Administrator
 
Posts: 1181
Joined: 23 Jan 2011, 14:27

Re: Send message to all admins and ops?

Postby joppiesaus » 11 Jan 2014, 19:11

Thanks very much Dzienny! I'll post it soon! :D
joppiesaus
 
Posts: 379
Joined: 20 Aug 2012, 07:28
Location: in a obsedian house, with glass in it so i can see the lava!


Return to Help in Coding

Who is online

Users browsing this forum: No registered users and 1 guest

cron