add autoload plugin setting

This commit is contained in:
Beu
2025-09-18 20:30:26 +02:00
parent 1ea9abfcda
commit 7a552971fe

View File

@@ -44,7 +44,7 @@ class MatchManagerMultipleConfigManager implements ManialinkPageAnswerListener,
* Constants * Constants
*/ */
const PLUGIN_ID = 171; const PLUGIN_ID = 171;
const PLUGIN_VERSION = 1.7; const PLUGIN_VERSION = 1.8;
const PLUGIN_NAME = 'MatchManager Multiple Config Manager'; const PLUGIN_NAME = 'MatchManager Multiple Config Manager';
const PLUGIN_AUTHOR = 'Beu'; const PLUGIN_AUTHOR = 'Beu';
@@ -69,6 +69,8 @@ class MatchManagerMultipleConfigManager implements ManialinkPageAnswerListener,
const CB_LOADCONFIG = 'MatchManager.MultiConfigManager.LoadConfig'; const CB_LOADCONFIG = 'MatchManager.MultiConfigManager.LoadConfig';
const CB_SAVECONFIG = 'MatchManager.MultiConfigManager.SaveConfig'; const CB_SAVECONFIG = 'MatchManager.MultiConfigManager.SaveConfig';
const SETTING_ENABLE_PLUGINS_WHEN_LOADING = 'Enable installed plugins when loading config';
/* /*
* Private properties * Private properties
*/ */
@@ -133,6 +135,8 @@ class MatchManagerMultipleConfigManager implements ManialinkPageAnswerListener,
throw new \Exception('MatchManager Core is needed to use MatchManager Players Pause plugin'); throw new \Exception('MatchManager Core is needed to use MatchManager Players Pause plugin');
} }
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_ENABLE_PLUGINS_WHEN_LOADING, false, 'Enable installed plugins when loading config');
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::AFTERINIT, $this, 'handleAfterInit'); $this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::AFTERINIT, $this, 'handleAfterInit');
$this->maniaControl->getCallbackManager()->registerCallbackListener(PluginManager::CB_PLUGIN_LOADED, $this, 'handlePluginLoaded'); $this->maniaControl->getCallbackManager()->registerCallbackListener(PluginManager::CB_PLUGIN_LOADED, $this, 'handlePluginLoaded');
$this->maniaControl->getCallbackManager()->registerCallbackListener(PluginManager::CB_PLUGIN_UNLOADED, $this, 'handlePluginUnloaded'); $this->maniaControl->getCallbackManager()->registerCallbackListener(PluginManager::CB_PLUGIN_UNLOADED, $this, 'handlePluginUnloaded');
@@ -335,13 +339,24 @@ class MatchManagerMultipleConfigManager implements ManialinkPageAnswerListener,
if ($allconfigs != null) { if ($allconfigs != null) {
$this->log("Loading config: " . $id); $this->log("Loading config: " . $id);
$someconfignotloaded = false; $someconfignotloaded = false;
foreach ($allconfigs as $plugin => $configs) { $pluginClasses = $this->maniaControl->getPluginManager()->getPluginClasses();
$pluginclass = $this->maniaControl->getPluginManager()->getPlugin($plugin); $enablePlugins = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_ENABLE_PLUGINS_WHEN_LOADING);
if ($pluginclass != null) { foreach ($allconfigs as $pluginClass => $configs) {
if ($pluginClass === get_class($this)) continue;
$plugin = $this->maniaControl->getPluginManager()->getPlugin($pluginClass);
if (in_array($pluginClass, $pluginClasses, true)) {
if ($plugin === null && $enablePlugins) {
$this->log("Loading plugin " . $pluginClass);
$this->maniaControl->getPluginManager()->activatePlugin($pluginClass);
$plugin = $this->maniaControl->getPluginManager()->getPlugin($pluginClass);
}
if ($plugin !== null) {
foreach ($configs as $name => $value) { foreach ($configs as $name => $value) {
// When loading setting, cache could be wrong compared to the data stored in the database. So force clear everytime to be sure to have the good value // When loading setting, cache could be wrong compared to the data stored in the database. So force clear everytime to be sure to have the good value
$this->maniaControl->getSettingManager()->clearStorage(); $this->maniaControl->getSettingManager()->clearStorage();
$setting = $this->maniaControl->getSettingManager()->getSettingObject($pluginclass, $name); $setting = $this->maniaControl->getSettingManager()->getSettingObject($plugin, $name);
if ($setting != null) { if ($setting != null) {
if ($setting->value != $value) { if ($setting->value != $value) {
$this->log("Saving new setting " . $name); $this->log("Saving new setting " . $name);
@@ -355,6 +370,7 @@ class MatchManagerMultipleConfigManager implements ManialinkPageAnswerListener,
} }
} }
} }
}
if ($someconfignotloaded) { if ($someconfignotloaded) {
$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'One or more settings could not be imported'); $this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'One or more settings could not be imported');
} }
@@ -625,6 +641,7 @@ class MatchManagerMultipleConfigManager implements ManialinkPageAnswerListener,
$plugins = $this->maniaControl->getSettingManager()->getSettingClasses(); $plugins = $this->maniaControl->getSettingManager()->getSettingClasses();
foreach ($plugins as $class) { foreach ($plugins as $class) {
if ($class === get_class($this)) continue;
if (strpos($class, "MatchManagerSuite\\") !== 0) { if (strpos($class, "MatchManagerSuite\\") !== 0) {
continue; continue;
} }