diff --git a/MatchManagerSuite/MatchManagerAutomaticLauncher.php b/MatchManagerSuite/MatchManagerAutomaticLauncher.php index 3606b99..6ba9710 100644 --- a/MatchManagerSuite/MatchManagerAutomaticLauncher.php +++ b/MatchManagerSuite/MatchManagerAutomaticLauncher.php @@ -18,7 +18,7 @@ if (!class_exists('MatchManagerSuite\MatchManagerCore')) { } /** - * MatchManager Automatic Launche + * MatchManager Automatic Launcher * * @author Beu * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 @@ -28,7 +28,7 @@ class MatchManagerAutomaticLauncher implements CallbackListener, TimerListener, * Constants */ const PLUGIN_ID = 172; - const PLUGIN_VERSION = 1.0; + const PLUGIN_VERSION = 1.1; const PLUGIN_NAME = 'MatchManager Automatic Launcher'; const PLUGIN_AUTHOR = 'Beu'; @@ -144,8 +144,8 @@ class MatchManagerAutomaticLauncher implements CallbackListener, TimerListener, * @return void */ public function handlePluginUnloaded(string $pluginClass, Plugin $plugin) { - $this->maniaControl->getChat()->sendErrorToAdmins(self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled"); if ($pluginClass == self::MATCHMANAGERCORE_PLUGIN) { + $this->maniaControl->getChat()->sendErrorToAdmins(self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled"); $this->maniaControl->getPluginManager()->deactivatePlugin((get_class())); } } diff --git a/MatchManagerSuite/MatchManagerGSheet.php b/MatchManagerSuite/MatchManagerGSheet.php index 45ecff3..16a4b06 100644 --- a/MatchManagerSuite/MatchManagerGSheet.php +++ b/MatchManagerSuite/MatchManagerGSheet.php @@ -35,7 +35,7 @@ class MatchManagerGSheet implements CallbackListener, TimerListener, CommandLis * Constants */ const PLUGIN_ID = 156; - const PLUGIN_VERSION = 1.3; + const PLUGIN_VERSION = 1.4; const PLUGIN_NAME = 'MatchManager GSheet'; const PLUGIN_AUTHOR = 'Beu'; @@ -186,8 +186,8 @@ class MatchManagerGSheet implements CallbackListener, TimerListener, CommandLis * @return void */ public function handlePluginUnloaded(string $pluginClass, Plugin $plugin) { - $this->maniaControl->getChat()->sendErrorToAdmins(self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled"); if ($pluginClass == self::MATCHMANAGERCORE_PLUGIN) { + $this->maniaControl->getChat()->sendErrorToAdmins(self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled"); $this->maniaControl->getPluginManager()->deactivatePlugin((get_class())); } } @@ -266,9 +266,9 @@ class MatchManagerGSheet implements CallbackListener, TimerListener, CommandLis $asyncHttpRequest = new AsyncHttpRequest($this->maniaControl, 'https://oauth2.googleapis.com/device/code?scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fspreadsheets&client_id=' . $clientid); $asyncHttpRequest->setContentType("application/x-www-form-urlencoded"); $asyncHttpRequest->setCallable(function ($json, $error) use ($player) { - if (!$json) { - Logger::logError('Impossible to Google API: ' . $json); - $this->maniaControl->getChat()->sendError('Impossible to Google API: ' . $json, $player); + if (!$json || $error) { + Logger::logError('Error from Google API: ' . $error); + $this->maniaControl->getChat()->sendError('Error from Google API: ' . $error, $player); return; } $data = json_decode($json); @@ -316,9 +316,9 @@ class MatchManagerGSheet implements CallbackListener, TimerListener, CommandLis $asyncHttpRequest->setContentType("application/x-www-form-urlencoded"); $asyncHttpRequest->setHeaders(array("Content-Length: 0")); $asyncHttpRequest->setCallable(function ($json, $error) use ($player) { - if (!$json) { - Logger::logError('Impossible to Google API: ' . $json); - $this->maniaControl->getChat()->sendError('Impossible to Google API: ' . $json, $player); + if (!$json || $error) { + Logger::logError('Error from Google API: ' . $error); + $this->maniaControl->getChat()->sendError('Error from Google API: ' . $error, $player); return; } $data = json_decode($json); @@ -357,8 +357,10 @@ class MatchManagerGSheet implements CallbackListener, TimerListener, CommandLis if (time() >= $expire) { $response = WebReader::postUrl('https://oauth2.googleapis.com/token?grant_type=refresh_token&client_id=' . $clientid . '&client_secret=' . $clientsecret . '&refresh_token=' . $refreshtoken); $json = $response->getContent(); - if (!$json) { - Logger::logError('Impossible to Google API: ' . $json); + $error = $response->getError(); + if (!$json || $error) { + Logger::logError('Error during token refresh: ' . $error); + $this->maniaControl->getChat()->sendErrorToAdmins('Error during token refresh: ' . $error); return; } $data = json_decode($json); @@ -419,7 +421,7 @@ class MatchManagerGSheet implements CallbackListener, TimerListener, CommandLis $asyncHttpRequest->setContentType(AsyncHttpRequest::CONTENT_TYPE_JSON); $asyncHttpRequest->setHeaders(array("Authorization: Bearer " . $this->access_token)); $asyncHttpRequest->setCallable(function ($json, $error) use ($player) { - if ($error) { + if (!$json || $error) { Logger::logError('Error: ' . $error); $this->maniaControl->getChat()->sendError('Error: ' . $error, $player); return; @@ -500,13 +502,15 @@ class MatchManagerGSheet implements CallbackListener, TimerListener, CommandLis $asyncHttpRequest->setHeaders(array("Authorization: Bearer " . $this->access_token)); $asyncHttpRequest->setContent(json_encode($data)); $asyncHttpRequest->setCallable(function ($json, $error) use ($sheetname, $currentscore, $currentteamsscore, $matchstatus) { - if ($error) { - Logger::logError('Error: ' . $error); + if (!$json || $error) { + Logger::logError('Error from Google API: ' . $error); + $this->maniaControl->getChat()->sendErrorToAdmins('Error from Google API: ' . $error); return; } $data = json_decode($json); if (!$data) { Logger::logError('Json parse error: ' . $json); + $this->maniaControl->getChat()->sendErrorToAdmins('Json parse error: ' . $json); return; } @@ -526,13 +530,15 @@ class MatchManagerGSheet implements CallbackListener, TimerListener, CommandLis $asyncHttpRequest->setHeaders(array("Authorization: Bearer " . $this->access_token)); $asyncHttpRequest->setContent(json_encode($data)); $asyncHttpRequest->setCallable(function ($json, $error) use ($sheetname, $currentscore, $currentteamsscore) { - if ($error) { - Logger::logError('Error: ' . $error); + if (!$json || $error) { + Logger::logError('Error from Google API: ' . $error); + $this->maniaControl->getChat()->sendErrorToAdmins('Error from Google API: ' . $error); return; } $data = json_decode($json); if (!$data) { Logger::logError('Json parse error: ' . $json); + $this->maniaControl->getChat()->sendErrorToAdmins('Json parse error: ' . $json); return; } @@ -552,9 +558,16 @@ class MatchManagerGSheet implements CallbackListener, TimerListener, CommandLis $asyncHttpRequest->setHeaders(array("Authorization: Bearer " . $this->access_token)); $asyncHttpRequest->setContent(json_encode($data)); $asyncHttpRequest->setCallable(function ($json, $error) { + if (!$json || $error) { + Logger::logError('Error from Google API: ' . $error); + $this->maniaControl->getChat()->sendErrorToAdmins('Error from Google API: ' . $error); + return; + } $data = json_decode($json); - if ($error || !$data) { - Logger::logError('Error while Sending data: ' . print_r($error, true)); + if (!$data) { + Logger::logError('Json parse error: ' . $json); + $this->maniaControl->getChat()->sendErrorToAdmins('Json parse error: ' . $json); + return; } }); $asyncHttpRequest->postData(1000); @@ -595,13 +608,15 @@ class MatchManagerGSheet implements CallbackListener, TimerListener, CommandLis $asyncHttpRequest->setContentType(AsyncHttpRequest::CONTENT_TYPE_JSON); $asyncHttpRequest->setHeaders(array("Authorization: Bearer " . $this->access_token)); $asyncHttpRequest->setCallable(function ($json, $error) { - if ($error) { - Logger::logError('Error: ' . $error); + if (!$json || $error) { + Logger::logError('Error from Google API: ' . $error); + $this->maniaControl->getChat()->sendErrorToAdmins('Error from Google API: ' . $error); return; } $data = json_decode($json); if (!$data) { Logger::logError('Json parse error: ' . $json); + $this->maniaControl->getChat()->sendErrorToAdmins('Json parse error: ' . $json); return; } @@ -758,17 +773,31 @@ class MatchManagerGSheet implements CallbackListener, TimerListener, CommandLis $asyncHttpRequest->setHeaders(array("Authorization: Bearer " . $this->access_token)); $asyncHttpRequest->setContent(json_encode($data)); $asyncHttpRequest->setCallable(function ($json, $error) use ($sheetname) { + if (!$json || $error) { + Logger::logError('Error from Google API: ' . $error); + $this->maniaControl->getChat()->sendErrorToAdmins('Error from Google API: ' . $error); + return; + } $data = json_decode($json); - if ($error || !$data) { - Logger::logError('Error while Sending data: ' . print_r($error, true)); + if (!$data) { + Logger::logError('Json parse error: ' . $json); + $this->maniaControl->getChat()->sendErrorToAdmins('Json parse error: ' . $json); + return; } // Clear Scoreboards data $asyncHttpRequest = new AsyncHttpRequest($this->maniaControl, 'https://sheets.googleapis.com/v4/spreadsheets/' . $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCHMANAGERGSHEET_SPREADSHEET) . '/values/' . urlencode("'". $sheetname . "'") . '!A1:Z300:clear'); $asyncHttpRequest->setHeaders(array("Authorization: Bearer " . $this->access_token)); $asyncHttpRequest->setCallable(function ($json, $error) use ($sheetname) { + if (!$json || $error) { + Logger::logError('Error from Google API: ' . $error); + $this->maniaControl->getChat()->sendErrorToAdmins('Error from Google API: ' . $error); + return; + } $data = json_decode($json); - if ($error || !$data) { - Logger::logError('Error while Sending data: ' . print_r($error, true)); + if (!$data) { + Logger::logError('Json parse error: ' . $json); + $this->maniaControl->getChat()->sendErrorToAdmins('Json parse error: ' . $json); + return; } // Add headers data $data = new \stdClass; @@ -790,10 +819,17 @@ class MatchManagerGSheet implements CallbackListener, TimerListener, CommandLis $asyncHttpRequest->setContentType(AsyncHttpRequest::CONTENT_TYPE_JSON); $asyncHttpRequest->setHeaders(array("Authorization: Bearer " . $this->access_token)); $asyncHttpRequest->setContent(json_encode($data)); - $asyncHttpRequest->setCallable(function ($json, $error) use ($sheetname) { + $asyncHttpRequest->setCallable(function ($json, $error) { + if (!$json || $error) { + Logger::logError('Error from Google API: ' . $error); + $this->maniaControl->getChat()->sendErrorToAdmins('Error from Google API: ' . $error); + return; + } $data = json_decode($json); - if ($error || !$data) { - Logger::logError('Error while Sending data: ' . print_r($error, true)); + if (!$data) { + Logger::logError('Json parse error: ' . $json); + $this->maniaControl->getChat()->sendErrorToAdmins('Json parse error: ' . $json); + return; } }); $asyncHttpRequest->postData(1000); diff --git a/MatchManagerSuite/MatchManagerPlayersPause.php b/MatchManagerSuite/MatchManagerPlayersPause.php index fd1b177..7b6db02 100644 --- a/MatchManagerSuite/MatchManagerPlayersPause.php +++ b/MatchManagerSuite/MatchManagerPlayersPause.php @@ -28,7 +28,7 @@ if (!class_exists('MatchManagerSuite\MatchManagerCore')) { /** - * MatchManager Widgets + * MatchManager Players Pause * * @author Beu * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 @@ -38,7 +38,7 @@ class MatchManagerPlayersPause implements ManialinkPageAnswerListener, CommandLi * Constants */ const PLUGIN_ID = 159; - const PLUGIN_VERSION = 1.1; + const PLUGIN_VERSION = 1.2; const PLUGIN_NAME = 'MatchManager Players Pause'; const PLUGIN_AUTHOR = 'Beu'; @@ -165,8 +165,8 @@ class MatchManagerPlayersPause implements ManialinkPageAnswerListener, CommandLi * @return void */ public function handlePluginUnloaded(string $pluginClass, Plugin $plugin) { - $this->maniaControl->getChat()->sendErrorToAdmins(self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled"); if ($pluginClass == self::MATCHMANAGERCORE_PLUGIN) { + $this->maniaControl->getChat()->sendErrorToAdmins(self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled"); $this->maniaControl->getPluginManager()->deactivatePlugin((get_class())); } } diff --git a/MatchManagerSuite/MatchManagerReadyButton.php b/MatchManagerSuite/MatchManagerReadyButton.php index cbf3f95..3a3dcd0 100644 --- a/MatchManagerSuite/MatchManagerReadyButton.php +++ b/MatchManagerSuite/MatchManagerReadyButton.php @@ -27,7 +27,7 @@ if (!class_exists('MatchManagerSuite\MatchManagerCore')) { /** - * MatchManager Widgets + * MatchManager Ready Button * * @author Beu * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 @@ -37,7 +37,7 @@ class MatchManagerReadyButton implements ManialinkPageAnswerListener, CommandLis * Constants */ const PLUGIN_ID = 158; - const PLUGIN_VERSION = 1.1; + const PLUGIN_VERSION = 1.2; const PLUGIN_NAME = 'MatchManager Ready Button'; const PLUGIN_AUTHOR = 'Beu'; @@ -157,8 +157,8 @@ class MatchManagerReadyButton implements ManialinkPageAnswerListener, CommandLis * @return void */ public function handlePluginUnloaded(string $pluginClass, Plugin $plugin) { - $this->maniaControl->getChat()->sendErrorToAdmins(self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled"); if ($pluginClass == self::MATCHMANAGERCORE_PLUGIN) { + $this->maniaControl->getChat()->sendErrorToAdmins(self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled"); $this->maniaControl->getPluginManager()->deactivatePlugin((get_class())); } } diff --git a/MatchManagerSuite/MatchManagerWidget.php b/MatchManagerSuite/MatchManagerWidget.php index b9ed78a..faa143c 100644 --- a/MatchManagerSuite/MatchManagerWidget.php +++ b/MatchManagerSuite/MatchManagerWidget.php @@ -38,7 +38,7 @@ class MatchManagerWidget implements ManialinkPageAnswerListener, CallbackListene * Constants */ const PLUGIN_ID = 153; - const PLUGIN_VERSION = 1.6; + const PLUGIN_VERSION = 1.7; const PLUGIN_NAME = 'MatchManager Widget'; const PLUGIN_AUTHOR = 'Beu'; @@ -178,8 +178,8 @@ class MatchManagerWidget implements ManialinkPageAnswerListener, CallbackListene * @return void */ public function handlePluginUnloaded(string $pluginClass, Plugin $plugin) { - $this->maniaControl->getChat()->sendErrorToAdmins(self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled"); if ($pluginClass == self::MATCHMANAGERCORE_PLUGIN) { + $this->maniaControl->getChat()->sendErrorToAdmins(self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled"); $this->maniaControl->getPluginManager()->deactivatePlugin((get_class())); } }