load score if possible when enabled after the match start + minor fixes

This commit is contained in:
Beu 2022-03-29 22:05:51 +02:00
parent ca343567f2
commit 0b8dbfbb8b
2 changed files with 43 additions and 18 deletions

View File

@ -27,7 +27,6 @@ use ManiaControl\Configurator\GameModeSettings;
use ManiaControl\Utils\Formatter;
use Maniaplanet\DedicatedServer\InvalidArgumentException;
use ManiaControl\Callbacks\TimerListener; // for pause
use ManiaControl\Maps\Map;
/**
* MatchManager Core
@ -324,7 +323,6 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
private $chatprefix = '$<$fc3$w🏆$m$> '; // Would like to create a setting but MC database doesn't support utf8mb4
private $nbmaps = 0;
private $nbrounds = 0;
private $nbspectators = 0;
private $currentgmbase = "";
private $currentcustomgm = "";
private $currentsettingmode = "";
@ -334,17 +332,13 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
// Settings to keep in memory
private $settings_nbroundsbymap = 5;
private $settings_nbwinner = 2;
private $settings_nbwinners = 2;
private $settings_nbmapsbymatch = 0;
private $settings_pointlimit = 100;
private $nbwinners = 0;
private $scriptSettings = array();
private $currentscore = array();
private $preendroundscore = array();
private $currentteamsscore = array();
private $playerpause = array();
private $pausetimer = 0;
private $pauseon = false;
@ -559,6 +553,10 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
return $this->matchStarted;
}
public function getCurrentGamemodeBase() {
return $this->currentgmbase;
}
public function getCountRound() {
return $this->nbrounds . "/" . $this->settings_nbroundsbymap;
}
@ -852,6 +850,10 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
* Function called to start the match
*/
public function MatchStart() {
if ($this->matchStarted) {
$this->maniaControl->getChat()->sendErrorToAdmins($this->chatprefix . " a match is already launched");
return;
}
try {
$this->matchid = $this->maniaControl->getServer()->login . "-" . time();
$this->currentgmbase = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_GAMEMODE_BASE);
@ -1027,7 +1029,10 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
*/
public function MatchStop() {
Logger::log("Match stop");
if (!$this->matchStarted) {
$this->maniaControl->getChat()->sendErrorToAdmins($this->chatprefix . " No match launched");
return;
}
try {
// Trigger Callback

View File

@ -9,23 +9,19 @@ use FML\Controls\Quads\Quad_Bgs1InRace;
use FML\ManiaLink;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Callbacks\Callbacks;
use ManiaControl\Callbacks\Structures\Common\BasePlayerTimeStructure;
use ManiaControl\Callbacks\Structures\TrackMania\OnScoresStructure;
use ManiaControl\Callbacks\Structures\TrackMania\OnWayPointEventStructure;
use ManiaControl\Logger;
use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager;
use ManiaControl\Plugins\Plugin;
use ManiaControl\Plugins\PluginManager;
use ManiaControl\Settings\Setting;
use ManiaControl\Settings\SettingManager;
use ManiaControl\Utils\Formatter;
if (! class_exists('MatchManagerSuite\MatchManagerCore')) {
$this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is needed to use MatchManager Widget plugin. Install it and restart Maniacontrol');
Logger::logError('MatchManager Core is needed to use MatchManager Widget plugin. Install it and restart Maniacontrol');
if (!class_exists('MatchManagerSuite\MatchManagerCore')) {
$this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is required to use one of MatchManager plugin. Install it and restart Maniacontrol');
Logger::logError('MatchManager Core is required to use one of MatchManager plugin. Install it and restart Maniacontrol');
return false;
}
use MatchManagerSuite\MatchManagerCore;
@ -127,10 +123,11 @@ class MatchManagerWidget implements ManialinkPageAnswerListener, CallbackListene
$this->MatchManagerCore = $this->maniaControl->getPluginManager()->getPlugin(self::MATCHMANAGERCORE_PLUGIN);
if ($this->MatchManagerCore == Null) {
throw new \Exception('MatchManager Core is needed to use MatchManager Widget plugin');
throw new \Exception('MatchManager Core is needed to use ' . self::PLUGIN_NAME);
}
// Callbacks
$this->maniaControl->getCallbackManager()->registerCallbackListener(PluginManager::CB_PLUGIN_UNLOADED, $this, 'handlePluginUnloaded');
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
$this->maniaControl->getCallbackManager()->registerCallbackListener(SettingManager::CB_SETTING_CHANGED, $this, 'updateSettings');
$this->maniaControl->getCallbackManager()->registerCallbackListener(MatchManagerCore::CB_MATCHMANAGER_STARTMATCH, $this, 'InitMatch');
@ -151,6 +148,15 @@ class MatchManagerWidget implements ManialinkPageAnswerListener, CallbackListene
if ($this->MatchManagerCore->getMatchStatus()) {
$this->gmbase = $this->MatchManagerCore->getCurrentGamemodeBase();
if ($this->gmbase == "Teams") {
$currentscore = $this->MatchManagerCore->getCurrentTeamsScore();
} else {
$currentscore = $this->MatchManagerCore->getCurrentScore();
}
if (count($currentscore) > 0) {
$this->generateMatchLiveWidgetData($currentscore);
}
$this->displayManialinks(false);
}
@ -164,6 +170,20 @@ class MatchManagerWidget implements ManialinkPageAnswerListener, CallbackListene
$this->closeWidgets();
}
/**
* handlePluginUnloaded
*
* @param string $pluginClass
* @param Plugin $plugin
* @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->getPluginManager()->deactivatePlugin((get_class()));
}
}
/**
* Update Widgets on Setting Changes
*
@ -376,7 +396,7 @@ class MatchManagerWidget implements ManialinkPageAnswerListener, CallbackListene
$this->closeWidgets();
}
}
}