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
|
|
|
/**
|
|
|
|
* ManiaControl Chat-Message Plugin
|
|
|
|
*
|
|
|
|
* @author kremsy and steeffeen
|
|
|
|
*/
|
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
|
|
|
|
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'handleOnInit');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function handleOnInit(array $callback) {
|
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
|
|
|
|
$message = '$sSupported Admin Commands: ';
|
|
|
|
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
|
|
|
|
$message = '$sSupported Player Commands: ';
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|