Multiple Features to improve ManiaControl usability (#234)
* ServerUIPropertiesMenu for Configurator to edit builtin UIProperties of MP * fixed unregister-functions of CallbackManager * Reducing menuItemHeight in Configurator to avoid overlapping of the menu items * Fully rebuild the admins menu after a player rights changed * Added function to FileUtil to improve realpath, so symbolic links can be resolved * Fixed indentation * Update FileUtil.php Fixed error in case of an absolute path on Unix-like systems. * New CallQueue which runs once inbetween the MC-loops * Added important queued call to be executed earlier * ErrorMethod made optional, as in some cases, there might be nothing to fail * Clean up repository from unnecessary files * Added easy installation script for DB on Unix-like systems * Replaced deprecated is_real by is_float * Add milliseconds with dot instead of double colon * Resolved deprecated curly braces error * gitignore all hidden files (except git and gitignore) * Update MC-update-check-interval, so that a restart is not required * Update gitignore to not ignore changes in MCTeam-Plugins * Update gitignore again * And another try * fixed MasterAdmin //delrec, added personal /delrec-command with permission-setting * Increase version number of local records plugin * Add Permission to delete any record * Reworked notifications of locals, removed private only, added private at rank * Fix formatting * Allow AuthenticationManager to store Plugin Permissions * Method to check, if a named function call is already queued * Added command disable feature * Reset timer if DeltaTime updated, so it does not try to catch up missed timings * Added private notification setting * To reduce load of multiple records (especially in rounds), queue call chat notifications * Added internal function to plugin manager to return plugin menu * restore .idea codestyle files * Update MC-Version number to 0.250
This commit is contained in:
@ -28,8 +28,12 @@ class CommandManager implements CallbackListener, UsageInformationAble {
|
||||
private $helpManager = array();
|
||||
/** @var Listening[][] $commandListenings */
|
||||
private $commandListenings = array();
|
||||
/** @var CommandListener[][] $disabledCommands */
|
||||
private $disabledCommands = array();
|
||||
/** @var Listening[][] $adminCommandListenings */
|
||||
private $adminCommandListenings = array();
|
||||
/** @var CommandListener[][] $disabledAdminCommands */
|
||||
private $disabledAdminCommands = array();
|
||||
|
||||
/**
|
||||
* Construct a new Commands Manager
|
||||
@ -116,6 +120,138 @@ class CommandManager implements CallbackListener, UsageInformationAble {
|
||||
array_push($listeningsArray[$command], $listening);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable the command(s) by the given listener.
|
||||
* The specific listener has to also manually reenable the commands, before the command can be used again.
|
||||
* @param mixed $commandName
|
||||
* @param bool $adminCommand
|
||||
* @param CommandListener $listener
|
||||
*/
|
||||
public function disableCommand($commandName, bool $adminCommand, CommandListener $listener) {
|
||||
if (is_array($commandName)) {
|
||||
foreach ($commandName as $command) {
|
||||
$this->disableCommand($command, $adminCommand, $listener);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
$command = strtolower(trim($commandName));
|
||||
// first, check if the command actually exists
|
||||
if (!array_key_exists($command, $this->commandListenings) && !array_key_exists($command, $this->adminCommandListenings)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$disabledCommands = null;
|
||||
if ($adminCommand) {
|
||||
$disabledCommands = &$this->disabledAdminCommands;
|
||||
} else {
|
||||
$disabledCommands = &$this->disabledCommands;
|
||||
}
|
||||
|
||||
if (!array_key_exists($command, $disabledCommands)) {
|
||||
$disabledCommands[$command] = array();
|
||||
}
|
||||
|
||||
if (!in_array($listener, $disabledCommands[$command])) {
|
||||
array_push($disabledCommands[$command], $listener);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable the command(s) by the given listener.
|
||||
* @param mixed $commandName
|
||||
* @param bool $adminCommand
|
||||
* @param CommandListener $listener
|
||||
*/
|
||||
public function enableCommand($commandName, bool $adminCommand, CommandListener $listener) {
|
||||
if (is_array($commandName)) {
|
||||
foreach ($commandName as $command) {
|
||||
$this->enableCommand($command, $adminCommand, $listener);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
$command = strtolower(trim($commandName));
|
||||
|
||||
$disabledCommands = null;
|
||||
if ($adminCommand) {
|
||||
$disabledCommands = &$this->disabledAdminCommands;
|
||||
} else {
|
||||
$disabledCommands = &$this->disabledCommands;
|
||||
}
|
||||
|
||||
if (!array_key_exists($command, $disabledCommands)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (($key = array_search($listener, $disabledCommands[$command])) !== false) {
|
||||
unset($disabledCommands[$command][$key]);
|
||||
if (empty($disabledCommands[$command])) {
|
||||
unset($disabledCommands[$command]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a command is enabled.
|
||||
* @param mixed $commandName
|
||||
* @param bool $adminCommand
|
||||
* @return bool|array
|
||||
*/
|
||||
public function isCommandEnabled($commandName, bool $adminCommand) {
|
||||
if (is_array($commandName)) {
|
||||
$results = array();
|
||||
foreach ($commandName as $command) {
|
||||
array_push($results, $this->isCommandEnabled($command, $adminCommand));
|
||||
}
|
||||
$resultsUnique = array_unique($results);
|
||||
if (count($resultsUnique) === 1) {
|
||||
return $resultsUnique[0];
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
$command = strtolower(trim($commandName));
|
||||
|
||||
$disabledCommands = null;
|
||||
if ($adminCommand) {
|
||||
$disabledCommands = &$this->disabledAdminCommands;
|
||||
} else {
|
||||
$disabledCommands = &$this->disabledCommands;
|
||||
}
|
||||
|
||||
if (!array_key_exists($command, $disabledCommands)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// if the command is disabled, there should be at least one listener in the array
|
||||
assert(!empty($disabledCommands[$command]));
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the given CommandListener blocking commands.
|
||||
*
|
||||
* @param array &$disabledCommands
|
||||
* @param CommandListener $listener
|
||||
* @return bool
|
||||
*/
|
||||
private function removeDisabledCommandListener(array &$disabledCommands, CommandListener $listener) {
|
||||
$removed = false;
|
||||
foreach ($disabledCommands as $command => $disableListeners) {
|
||||
if (($key = array_search($listener, $disableListeners)) !== false) {
|
||||
unset($disabledCommands[$command][$key]);
|
||||
$removed = true;
|
||||
|
||||
if (empty($disabledCommands[$command])) {
|
||||
unset($disabledCommands[$command]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $removed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister a Command Listener
|
||||
*
|
||||
@ -130,6 +266,12 @@ class CommandManager implements CallbackListener, UsageInformationAble {
|
||||
if ($this->removeCommandListener($this->adminCommandListenings, $listener)) {
|
||||
$removed = true;
|
||||
}
|
||||
if ($this->removeDisabledCommandListener($this->disabledCommands, $listener)) {
|
||||
$removed = true;
|
||||
}
|
||||
if ($this->removeDisabledCommandListener($this->disabledAdminCommands, $listener)) {
|
||||
$removed = true;
|
||||
}
|
||||
return $removed;
|
||||
}
|
||||
|
||||
@ -178,9 +320,11 @@ class CommandManager implements CallbackListener, UsageInformationAble {
|
||||
if (!$command) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$isAdminCommand = null;
|
||||
if (substr($message, 0, 2) === '//' || $command === 'admin') {
|
||||
// Admin command
|
||||
$isAdminCommand = true;
|
||||
$commandListenings = $this->adminCommandListenings;
|
||||
|
||||
if ($command === 'admin') {
|
||||
@ -197,6 +341,7 @@ class CommandManager implements CallbackListener, UsageInformationAble {
|
||||
$callback[1][2] = $message;
|
||||
} else {
|
||||
// User command
|
||||
$isAdminCommand = false;
|
||||
$commandListenings = $this->commandListenings;
|
||||
}
|
||||
|
||||
@ -205,6 +350,12 @@ class CommandManager implements CallbackListener, UsageInformationAble {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$this->isCommandEnabled($command, $isAdminCommand)) {
|
||||
$prefix = $isAdminCommand ? '//' : '/';
|
||||
$this->maniaControl->getChat()->sendError('The command $<$fff'.$prefix.$command.'$> is currently disabled!', $player);
|
||||
return;
|
||||
}
|
||||
|
||||
// Inform command listeners
|
||||
foreach ($commandListenings[$command] as $listening) {
|
||||
/** @var Listening $listening */
|
||||
|
Reference in New Issue
Block a user