From e072024ce5b00e09c00442ee27f24086e87902a5 Mon Sep 17 00:00:00 2001 From: kremsy Date: Sun, 21 May 2017 20:30:26 +0200 Subject: [PATCH] Some minor fixes on Player and Plugin Manager --- core/Communication/CommunicationManager.php | 18 +++++++++--------- core/Players/PlayerManager.php | 2 +- core/Plugins/PluginManager.php | 4 ++++ 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/core/Communication/CommunicationManager.php b/core/Communication/CommunicationManager.php index cf59cfe0..57c5ea4c 100644 --- a/core/Communication/CommunicationManager.php +++ b/core/Communication/CommunicationManager.php @@ -112,20 +112,20 @@ class CommunicationManager implements CallbackListener, UsageInformationAble { /** * Register a new Communication Listener * - * @param string $callbackName + * @param string $communicationName * @param CommunicationListener $listener * @param string $method * @return bool */ - public function registerCommunicationListener($echoName, CommunicationListener $listener, $method) { + public function registerCommunicationListener($communicationName, CommunicationListener $listener, $method) { if (!Listening::checkValidCallback($listener, $method)) { $listenerClass = get_class($listener); - trigger_error("Given Listener '{$listenerClass}' can't handle Callback '{$echoName}': No callable Method '{$method}'!"); + trigger_error("Given Listener '{$listenerClass}' can't handle Callback '{$communicationName}': No callable Method '{$method}'!"); return false; } - if (!array_key_exists($echoName, $this->communicationListenings)) { - $this->communicationListenings[$echoName] = new Listening($listener, $method); + if (!array_key_exists($communicationName, $this->communicationListenings)) { + $this->communicationListenings[$communicationName] = new Listening($listener, $method); } else { //TODO say which is already listening and other stuff trigger_error("Only one Listener can listen on a specific Communication Message"); @@ -173,10 +173,10 @@ class CommunicationManager implements CallbackListener, UsageInformationAble { */ private function removeCommunicationListener(array &$listeningsArray, CommunicationListener $listener) { $removed = false; - foreach ($listeningsArray as &$listening) { - if ($listening->listener === $listener) { - unset($listening); - $removed = true; + + foreach ($listeningsArray as $key => &$listening) { + if($listening->listener === $listener){ + unset($listeningsArray[$key]); } } return $removed; diff --git a/core/Players/PlayerManager.php b/core/Players/PlayerManager.php index 306ecb8d..7b757682 100644 --- a/core/Players/PlayerManager.php +++ b/core/Players/PlayerManager.php @@ -589,7 +589,7 @@ class PlayerManager implements CallbackListener, TimerListener, CommunicationLis $players = array(); foreach ($this->players as $player) { if (!$player->isSpectator) { - $players[] = $players; + $players[] = $player; } } diff --git a/core/Plugins/PluginManager.php b/core/Plugins/PluginManager.php index 69d9b3f6..638c6a26 100644 --- a/core/Plugins/PluginManager.php +++ b/core/Plugins/PluginManager.php @@ -6,6 +6,7 @@ use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\EchoListener; use ManiaControl\Callbacks\TimerListener; use ManiaControl\Commands\CommandListener; +use ManiaControl\Communication\CommunicationListener; use ManiaControl\Files\AsyncHttpRequest; use ManiaControl\Files\FileUtil; use ManiaControl\Logger; @@ -190,6 +191,9 @@ class PluginManager { if($plugin instanceof SidebarMenuEntryListener){ $this->maniaControl->getManialinkManager()->getSidebarMenuManager()->deleteMenuEntries($plugin); } + if($plugin instanceof CommunicationListener){ + $this->maniaControl->getCommunicationManager()->unregisterCommunicationListener($plugin); + } $this->savePluginStatus($pluginClass, false);