From f7c6056828577bd836dc0600f4bb03e36f89d259 Mon Sep 17 00:00:00 2001 From: Beu Date: Sun, 13 Jun 2021 16:14:59 +0200 Subject: [PATCH] add nickname to sheet & 2 minor fixes --- MatchManagerGSheet.zip | Bin 0 -> 4824 bytes MatchManagerSuite/MatchManagerGSheet.php | 145 ++++++++++++++--------- 2 files changed, 91 insertions(+), 54 deletions(-) create mode 100644 MatchManagerGSheet.zip diff --git a/MatchManagerGSheet.zip b/MatchManagerGSheet.zip new file mode 100644 index 0000000000000000000000000000000000000000..3d691dbe6a309097ae748c8a1d7c9bf29e1b0d4e GIT binary patch literal 4824 zcmaLbiT!bDsS0`~g2LHLPbZ0000UfV`_+XTr;3=#&fqU~~ikI05tkbxSX6 z2X#wVOM6=nU2jJ(Ti*Y?DC;`d+Iqclb8yqw!v|ocQr21={gd8b2mu(+cCi3}|1O6n zPXP#}nJ3yOO5=Xw!u|nv$JKz71)d%lk|d0=8@0$WEN|0*V;Zh-(eLV?@$_J4_tA>& z86KUey4h7L;SVqvoCOBoj2(>xKRJqI9Uh1cq}~Zy!xmb};@Ed0t>aqfNg*MOhX>(O zQog_Oi#cr(Y0y2yR?xPfbU` zUP?9JEZ`em5lf`?2m2bOk=D1<8I-dIqNV9)O$;~`N6+9xc)ylX-6?zC!-wn>BV>?wW$Nh;0olhaHz;K87|==sY7#*%39 zi?foE(oD-Ct2W&S4|K(%nitjvCN0QpxE>a(>>>pAFaJLRj5J_=XrbiyRX6Q>x_u%YBs*=Lq-6Mu@^`6bMr<1~^`yjiKYX z0@{TpI25VB22SX{OHS%E2wT7yFyU1R7*{Bhy;$22_fn!cHdJT|>?X&F*R1H?$7MYG zVOvdSM9y@F`Newo?byzxH-rkeu&AAA34>#Vzu}d!xLDgRI5LAtGU^%smJXB6kIoc& zZ&i)AFc4mbD$}=9aJbmk;}FzNRw|6OOy50beAT|1nr{}5$mg(Cci{VUxS#88CeSU5 z$jx2j#%pzpZLrhhtVVQEm`YO0ApWm;U|p{(U)_CY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?q^HWa`)<1XrBAeQ_trx8&BC4)8if`=P z+C52>KQeXNA8Hu#9ka|I2O`|Pbe@ijGyJQ*sDP>h_|cm~Gx$E0@nHS&I+TwrMywa1 z?9S@bOF{i{a)lVumwoUcsyX>#T2w0n0MXZ^q&Bqi< z?9k!IU8SF+Z6P#9Ux47KVJ~sbGXTAQABwW{~ zmhX2HFkh`Up4KiA3CRms#H_t-H~d6*zHLYb`${Ux*os6Tf482k4Ij+~E~6yY>4_G1 z0IAu1W>*=%mKDhaW#F+k!7E*ror}33Qy~hrxJNlv{@U&S_DL3QKDz>^M_y&+~1y^QCsnyQ+_0u z!Al|=b%Q9?v7W~#*PM&A7Jc{Nf)hv+ZWipVbt1fR8aAz;a$!=#y$p&W`7myO$RI=G`ynOe{8FB<@$&)@c?(%?l%eh z>>iqfK*ZuyzZnD)(*+~n@T?DE40ctY&{#YbVqBtsIS6p%ekH0)V7laoNhyFHMiN}m z4NoVTPij)zliowT)0mYx>^XR|voftslhX5BWw%J2j3S{WwLX1f%v&R`ITeaK=XK7X z>22;A9rD=4f~?aduW`>Fy|^qNuX|h-Y|H#x^yc!Afq-blmow5Q0%9&dY0G&yS4^C8w4=I}W!EF#{g>4}ZakQud>sfzd{6PU z(4*ahcv5fu~ literal 0 HcmV?d00001 diff --git a/MatchManagerSuite/MatchManagerGSheet.php b/MatchManagerSuite/MatchManagerGSheet.php index f09c146..5e33182 100644 --- a/MatchManagerSuite/MatchManagerGSheet.php +++ b/MatchManagerSuite/MatchManagerGSheet.php @@ -11,12 +11,18 @@ use ManiaControl\Players\Player; use ManiaControl\Plugins\Plugin; use ManiaControl\Settings\Setting; use ManiaControl\Settings\SettingManager; -use MatchManagerSuite\MatchManagerCore; use ManiaControl\Utils\WebReader; use ManiaControl\Files\AsyncHttpRequest; use ManiaControl\Commands\CommandListener; use ManiaControl\Admin\AuthenticationManager; +if (! class_exists('MatchManagerSuite\MatchManagerCore')) { + $this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is needed to use MatchManagerGSheet plugin. Install it and restart Maniacontrol'); + Logger::logError('MatchManager Core is needed to use MatchManager GSheet plugin. Install it and restart Maniacontrol'); + return false; +} +use MatchManagerSuite\MatchManagerCore; + /** * MatchManager GSheet @@ -29,7 +35,7 @@ class MatchManagerGSheet implements CallbackListener, CommandListener, Plugin { * Constants */ const PLUGIN_ID = 156; - const PLUGIN_VERSION = 0.1; + const PLUGIN_VERSION = 0.2; const PLUGIN_NAME = 'MatchManager GSheet'; const PLUGIN_AUTHOR = 'Beu'; @@ -107,9 +113,12 @@ class MatchManagerGSheet implements CallbackListener, CommandListener, Plugin { $this->initTables(); $this->MatchManagerCore = $this->maniaControl->getPluginManager()->getPlugin(self::MATCHMANAGERCORE_PLUGIN); + if ($this->MatchManagerCore == Null) { + throw new \Exception('MatchManager Core is needed to use MatchManager GSheet plugin'); + } + // Callbacks $this->maniaControl->getCallbackManager()->registerCallbackListener(SettingManager::CB_SETTING_CHANGED, $this, 'updateSettings'); - $this->maniaControl->getCallbackManager()->registerCallbackListener(MatchManagerCore::CB_MATCHMANAGER_STARTMATCH, $this, 'CheckAndPrepareSheet'); $this->maniaControl->getCallbackManager()->registerCallbackListener(MatchManagerCore::CB_MATCHMANAGER_ENDROUND, $this, 'onCallbackEndRound'); $this->maniaControl->getCallbackManager()->registerCallbackListener(MatchManagerCore::CB_MATCHMANAGER_ENDMATCH, $this, 'onCallbackEndMatch'); @@ -134,7 +143,6 @@ class MatchManagerGSheet implements CallbackListener, CommandListener, Plugin { * @see \ManiaControl\Plugins\Plugin::unload() */ public function unload() { - $this->closeWidgets(); } /** @@ -394,12 +402,22 @@ class MatchManagerGSheet implements CallbackListener, CommandListener, Plugin { $data->data[0]->values = array(array($this->matchstatus),array($this->MatchManagerCore->getCountMap()),array($this->MatchManagerCore->getCountRound())); $data->data[1] = new \stdClass; - $data->data[1]->range = "'" . $sheetname . "'!D2"; - $data->data[1]->values = $currentscore; + $data->data[1]->range = "'" . $sheetname . "'!A7"; + + $players = []; + foreach ($this->maniaControl->getPlayerManager()->getPlayers() as $player) { + array_push($players,array($player->login, $player->nickname)); + } + + $data->data[1]->values = $players; $data->data[2] = new \stdClass; - $data->data[2]->range = "'" . $sheetname . "'!K2"; - $data->data[2]->values = $currentteamsscore; + $data->data[2]->range = "'" . $sheetname . "'!D2"; + $data->data[2]->values = $currentscore; + + $data->data[3] = new \stdClass; + $data->data[3]->range = "'" . $sheetname . "'!K2"; + $data->data[3]->values = $currentteamsscore; $asyncHttpRequest = new AsyncHttpRequest($this->maniaControl, 'https://sheets.googleapis.com/v4/spreadsheets/' . $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCHMANAGERGSHEET_SPREADSHEET) . '/values:batchUpdate'); $asyncHttpRequest->setContentType(AsyncHttpRequest::CONTENT_TYPE_JSON); @@ -472,14 +490,13 @@ class MatchManagerGSheet implements CallbackListener, CommandListener, Plugin { } private function PrepareSheet(String $sheetname, array $sheetsid) { - if ($this->refreshTokenIfNeeded()) { - Logger::Log("Creating new Sheet: " . $sheetname); - + if ($this->refreshTokenIfNeeded()) { $data = new \stdClass; $data->requests = array(); $i = 0; if (count($sheetsid) > 1 || (count($sheetsid) == 1 && $sheetsid[0] == "0")) { + Logger::Log("Creating new Sheet: " . $sheetname); $sheetid = rand(1000000000,2147483646); while (in_array($sheetid, $sheetsid)) { $sheetid = rand(1000000000,2147483646); @@ -524,7 +541,26 @@ class MatchManagerGSheet implements CallbackListener, CommandListener, Plugin { $data->requests[$i]->repeatCell->cell->userEnteredFormat->textFormat = new \stdClass; $data->requests[$i]->repeatCell->cell->userEnteredFormat->textFormat->bold = true; $data->requests[$i]->repeatCell->fields = "userEnteredFormat(backgroundColor,textFormat)"; + $i++; + //Player list + $data->requests[$i] = new \stdClass; + $data->requests[$i]->repeatCell = new \stdClass; + $data->requests[$i]->repeatCell->range = new \stdClass; + $data->requests[$i]->repeatCell->range->sheetId = $sheetid; + $data->requests[$i]->repeatCell->range->startRowIndex = 5; + $data->requests[$i]->repeatCell->range->endRowIndex = 6; + $data->requests[$i]->repeatCell->range->startColumnIndex = 0; + $data->requests[$i]->repeatCell->range->endColumnIndex = 2; + $data->requests[$i]->repeatCell->cell = new \stdClass; + $data->requests[$i]->repeatCell->cell->userEnteredFormat = new \stdClass; + $data->requests[$i]->repeatCell->cell->userEnteredFormat->backgroundColor = new \stdClass; + $data->requests[$i]->repeatCell->cell->userEnteredFormat->backgroundColor->red = 0.6; + $data->requests[$i]->repeatCell->cell->userEnteredFormat->backgroundColor->green = 0.9; + $data->requests[$i]->repeatCell->cell->userEnteredFormat->backgroundColor->blue = 0.6; + $data->requests[$i]->repeatCell->cell->userEnteredFormat->textFormat = new \stdClass; + $data->requests[$i]->repeatCell->cell->userEnteredFormat->textFormat->bold = true; + $data->requests[$i]->repeatCell->fields = "userEnteredFormat(backgroundColor,textFormat)"; $i++; //Score Table @@ -573,56 +609,57 @@ class MatchManagerGSheet implements CallbackListener, CommandListener, Plugin { $asyncHttpRequest->setContentType(AsyncHttpRequest::CONTENT_TYPE_JSON); $asyncHttpRequest->setHeaders(array("Authorization: Bearer " . $this->access_token)); $asyncHttpRequest->setContent(json_encode($data)); - $asyncHttpRequest->setCallable(function ($json, $error) { - $data = json_decode($json); - if ($error || !$data) { - Logger::logError('Error while Sending data: ' . print_r($error, true)); - } - }); - $asyncHttpRequest->postData(1000); - - - // Add headers data - $data = new \stdClass; - $data->valueInputOption = "USER_ENTERED"; - - $data->data[0] = new \stdClass; - $data->data[0]->range = "'" . $sheetname . "'!A1"; - $data->data[0]->values = array(array("Informations"),array("Match status:", $this->matchstatus),array("Maps:","0/0"),array("Rounds:","0/0")); - - $data->data[1] = new \stdClass; - $data->data[1]->range = "'" . $sheetname . "'!D1"; - $data->data[1]->values = array(array("Rank","Login", "MatchPoints", "RoundPoints","Time","Team")); - - $data->data[2] = new \stdClass; - $data->data[2]->range = "'" . $sheetname . "'!K1"; - $data->data[2]->values = array(array("Rank","Team ID", "Name", "MatchPoints")); - - $asyncHttpRequest = new AsyncHttpRequest($this->maniaControl, 'https://sheets.googleapis.com/v4/spreadsheets/' . $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCHMANAGERGSHEET_SPREADSHEET) . '/values:batchUpdate'); - $asyncHttpRequest->setContentType(AsyncHttpRequest::CONTENT_TYPE_JSON); - $asyncHttpRequest->setHeaders(array("Authorization: Bearer " . $this->access_token)); - $asyncHttpRequest->setContent(json_encode($data)); - $asyncHttpRequest->setCallable(function ($json, $error) { - $data = json_decode($json); - if ($error || !$data) { - Logger::logError('Error while Sending data: ' . print_r($error, true)); - } - }); - - $asyncHttpRequest->postData(1000); - - // 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 . "'") . '!D2:N300:clear'); - $asyncHttpRequest->setHeaders(array("Authorization: Bearer " . $this->access_token)); - $asyncHttpRequest->setCallable(function ($json, $error) { + $asyncHttpRequest->setCallable(function ($json, $error) use ($sheetname) { var_dump($json); $data = json_decode($json); if ($error || !$data) { Logger::logError('Error while Sending data: ' . print_r($error, true)); } + + // Add headers data + $data = new \stdClass; + $data->valueInputOption = "USER_ENTERED"; + + $data->data[0] = new \stdClass; + $data->data[0]->range = "'" . $sheetname . "'!A1"; + $data->data[0]->values = array(array("Informations"),array("Match status:", $this->matchstatus),array("Maps:","0/0"),array("Rounds:","0/0"),array(),array("Login:","Nickname:")); + + $data->data[1] = new \stdClass; + $data->data[1]->range = "'" . $sheetname . "'!D1"; + $data->data[1]->values = array(array("Rank","Login", "MatchPoints", "RoundPoints","Time","Team")); + + $data->data[2] = new \stdClass; + $data->data[2]->range = "'" . $sheetname . "'!K1"; + $data->data[2]->values = array(array("Rank","Team ID", "Name", "MatchPoints")); + + $asyncHttpRequest = new AsyncHttpRequest($this->maniaControl, 'https://sheets.googleapis.com/v4/spreadsheets/' . $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCHMANAGERGSHEET_SPREADSHEET) . '/values:batchUpdate'); + $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) { + var_dump($json); + $data = json_decode($json); + if ($error || !$data) { + Logger::logError('Error while Sending data: ' . print_r($error, true)); + } + + // 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 . "'") . '!D2:N300:clear'); + $asyncHttpRequest->setHeaders(array("Authorization: Bearer " . $this->access_token)); + $asyncHttpRequest->setCallable(function ($json, $error) { + $data = json_decode($json); + if ($error || !$data) { + var_dump($json); + Logger::logError('Error while Sending data: ' . print_r($error, true)); + } + }); + + $asyncHttpRequest->postData(1000); + }); + $asyncHttpRequest->postData(1000); }); - $asyncHttpRequest->postData(1000); + } } }