TrackManiaControl/application/core/Commands/HelpManager.php

93 lines
2.6 KiB
PHP
Raw Normal View History

2014-01-14 19:47:40 +01:00
<?php
namespace ManiaControl\Commands;
2014-01-14 20:02:35 +01:00
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
2014-01-14 19:47:40 +01:00
use ManiaControl\ManiaControl;
use ManiaControl\Players\Player;
2014-01-14 20:13:52 +01:00
/**
* Help Manager
2014-01-14 20:13:52 +01:00
*
* @author kremsy
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
2014-01-14 20:13:52 +01:00
*/
2014-01-14 20:02:35 +01:00
class HelpManager implements CommandListener, CallbackListener {
/*
2014-01-14 19:47:40 +01:00
* Private Properties
*/
private $maniaControl = null;
private $playerCommands = array();
private $adminCommands = array();
/**
* Construct a new Commands Manager
*
* @param \ManiaControl\ManiaControl $maniaControl
*/
2014-01-14 20:02:35 +01:00
public function __construct(ManiaControl $maniaControl) {
2014-01-14 19:47:40 +01:00
$this->maniaControl = $maniaControl;
2014-01-14 20:02:35 +01:00
// Register for callbacks
2014-02-19 12:53:06 +01:00
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_ONINIT, $this, 'handleOnInit');
2014-01-14 20:02:35 +01:00
}
/**
* Handle ManiaControl OnInit Callback
*/
public function handleOnInit() {
2014-01-14 19:47:40 +01:00
//Register the help command
2014-01-14 20:02:35 +01:00
$this->maniaControl->commandManager->registerCommandListener('help', $this, 'command_playerHelp', false);
$this->maniaControl->commandManager->registerCommandListener('help', $this, 'command_adminHelp', true);
2014-01-14 19:47:40 +01:00
}
2014-01-14 20:02:35 +01:00
/**
* Shows a list of Admin Commands
*
* @param array $chat
* @param Player $player
*/
public function command_adminHelp(array $chat, Player $player) {
//TODO only show first command in command arrays
2014-04-27 14:58:58 +02:00
$message = 'Supported Admin Commands: ';
2014-01-14 20:02:35 +01:00
foreach(array_reverse($this->adminCommands) as $command) {
$message .= $command['Name'] . ',';
}
$message = substr($message, 0, -1);
$this->maniaControl->chat->sendChat($message, $player->login);
}
2014-01-14 19:47:40 +01:00
2014-01-14 20:02:35 +01:00
/**
* Shows a list of Player Commands
*
* @param array $chat
* @param Player $player
*/
2014-01-14 19:47:40 +01:00
public function command_playerHelp(array $chat, Player $player) {
2014-01-14 20:02:35 +01:00
//TODO only show first command in command arrays
2014-04-27 14:58:58 +02:00
$message = 'Supported Player Commands: ';
2014-01-14 20:02:35 +01:00
foreach(array_reverse($this->playerCommands) as $command) {
$message .= $command['Name'] . ',';
2014-01-14 19:47:40 +01:00
}
2014-01-14 20:02:35 +01:00
$message = substr($message, 0, -1);
$this->maniaControl->chat->sendChat($message, $player->login);
2014-01-14 19:47:40 +01:00
}
/**
* Registers a new Command
*
* @param $name
* @param $adminCommand
* @param $description
*/
public function registerCommand($name, $adminCommand = false, $description = '') {
if($adminCommand) {
array_push($this->adminCommands, array("Name" => $name, "Description" => $description));
} else {
array_push($this->playerCommands, array("Name" => $name, "Description" => $description));
}
}
}