User Tools

Site Tools


As indicated by it's name the purpose of this plugin is to group the admins in order to set different permissions to each of them. But this plugin has also it's own admin chat command handling system.


Admin Permissions

One of the main reason you might wan't to use this plugin while developing yours is to restrict access to the functionality of your plugin. To do this you have 3 options

  • Use a /admin chat command
  • Use a window or click item

We will see how to add a chat command later on, wright now how do we are interested in the second part. You have 2 different way of handling this for 2 different situations

Prevent a Call

A function is called by the user, you wan't to prevent it, and at the same time send a messge to the user that used it. In this case you should use the public getPermission method. This methods will check if the user has the correct permission. If he doesn't it will send him a message and return false for you to stop the call.

Exemple :

public function matchSettings($login) {
	if($this->callPublicMethod('eXpansion\AdminGroups', 'getPermission', $login, 'game_settings')){
		$window = Gui\Windows\MatchSettings::Create($login);
		$window->setTitle('Match Settings');
		$window->setSize(120, 100);

Hide a Call

Another thing you may want to do is hide a content if the player doesn't have the necessary permissions to see. In this case you wouldn't want to send a message to the user. In this case you will use the static hasPermission methof.

Exemple :

$this->serverName->setVisibility(AdminGroups::hasPermission($login, 'server_name')); 

Admin Commands

Even if we trying to minimize the use of commands, they still might be practical and some people may still won't to use them as they can be faster to use.

Register a Chat Command

AdminGroups::addAdminCommand('set server maxplayers', $this, 'setServerMaxPlayers', 'server_maxplayer');

Will register a admin command. the command is /admin set server maxplayers and it will call the setServerMaxPlayers function if the player has the server_maxplayer permission.

Define Minimum Input

What we would like now is to have at least 1 parameter in input, we can of crouse check it in the unBlacklist function but we can also ask AdminGroups to do it :

$cmd = AdminGroups::addAdminCommand('set server maxplayers', $this, 'setServerMaxPlayers', 'server_maxplayer');

This way if the user forgets to give a login there will be an error message sent to him and the function will not be called.

Set an Alias

The /admin set server maxplayers command is quite long, we would like to have an alias that does the same thing but is shorter. Easy

AdminGroups::addAlias($cmd, "setmaxplayers");

Now the command /admin set server maxplayers is equivalent to /admin setmaxplayers

Set Help Text

It is important that users understands what does a command, for that reason you need to define the help of a command.

$cmd->setHelp('Sets a new maximum of players');
$cmd->setHelpMore('Sets the maximum number of players who can play on this server.');

The first Help will be shown on the admin command list while the second will be shown on the window dedicated to the command.

Check Input

Now we would like to prevent the user to send a string instead of a integer, Once more we could do this in our function but we also can do it here. To do it we will just add a checker

$cmd->addchecker(1, \ManiaLivePlugins\eXpansion\AdminGroups\types\Interger::getInstance());

We have added the checker to the first input, we could check different checkers to different inputs.

Creating Checker

If you need to make the same checking a few times for different commands you might won't create a checker not to do it.


class Time_ms extends \ManiaLivePlugins\eXpansion\AdminGroups\types\absChecker{
	public function check($data) {
		$v = explode(':',$data);
		return isset($v[0])&&isset($v[1])&&is_numeric($v[0])&&is_numeric($v[1]);
	public function getErrorMsg() {
		return 'use time in format %variable%m:ss';
dev/plugin/admingroups.txt · Last modified: 2013/07/17 10:08 (external edit)