User Tools

Site Tools


dev:plugin:admingroups

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

dev:plugin:admingroups [2013/02/23 19:13]
oliverde8 created
dev:plugin:admingroups [2013/07/17 10:08] (current)
Line 34: Line 34:
 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.  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**+==== Register a Chat Command ​==== 
 <code php>​AdminGroups::​addAdminCommand('​set server maxplayers',​ $this, '​setServerMaxPlayers',​ '​server_maxplayer'​);</​code>​ <code php>​AdminGroups::​addAdminCommand('​set server maxplayers',​ $this, '​setServerMaxPlayers',​ '​server_maxplayer'​);</​code>​
 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. ​ 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 :  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 : 
Line 43: Line 46:
 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. ​ 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. ​
  
-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 +==== Set an Alias ====
-<code php>​$cmd->​addchecker(1,​ \ManiaLivePlugins\eXpansion\AdminGroups\types\Interger::​getInstance());​ +
-</​code>​+
  
 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 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
 <code php>​AdminGroups::​addAlias($cmd,​ "​setmaxplayers"​);</​code>​ <code php>​AdminGroups::​addAlias($cmd,​ "​setmaxplayers"​);</​code>​
 Now the command **/admin set server maxplayers** is equivalent to **/admin 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.
 +<code php>​$cmd->​setHelp('​Sets a new maximum of players'​);​
 +$cmd->​setHelpMore('​Sets the maximum number of players who can play on this server.'​);</​code>​
 +
 +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
 +<code php>​$cmd->​addchecker(1,​ \ManiaLivePlugins\eXpansion\AdminGroups\types\Interger::​getInstance());​
 +</​code>​
 +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. 
 +
 +**Exemple**
 +<code php>​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';​
 + }
 +}</​code>​
dev/plugin/admingroups.txt · Last modified: 2013/07/17 10:08 (external edit)