fixed doubled reopening of plugin menu
This commit is contained in:
@ -19,7 +19,7 @@ use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
||||
use ManiaControl\Players\Player;
|
||||
|
||||
/**
|
||||
* Configurator for enabling and disabling Plugins
|
||||
* Configurator for installing Plugins
|
||||
*
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
@ -29,11 +29,16 @@ class PluginInstallMenu implements CallbackListener, ConfiguratorMenu, Manialink
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
const SETTING_PERMISSION_INSTALL_PLUGINS = 'Install plugins';
|
||||
const SETTING_PERMISSION_INSTALL_PLUGINS = 'Install Plugins';
|
||||
const ACTION_PREFIX_INSTALLPLUGIN = 'PluginInstallMenu.Install.';
|
||||
|
||||
/*
|
||||
* Private Properties
|
||||
*/
|
||||
private $maniaControl = null;
|
||||
|
||||
/**
|
||||
* Create a new plugin menu instance
|
||||
* Create a new Plugin Install Menu
|
||||
*
|
||||
* @param ManiaControl $maniaControl
|
||||
*/
|
||||
@ -44,22 +49,14 @@ class PluginInstallMenu implements CallbackListener, ConfiguratorMenu, Manialink
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Menu Title
|
||||
*
|
||||
* @return string
|
||||
* @see \ManiaControl\Configurators\ConfiguratorMenu::getTitle()
|
||||
*/
|
||||
public function getTitle() {
|
||||
return 'Install Plugins';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Configurator Menu Frame
|
||||
*
|
||||
* @param float $width
|
||||
* @param float $height
|
||||
* @param Script $script
|
||||
* @param Player $player
|
||||
* @return \FML\Controls\Frame
|
||||
* @see \ManiaControl\Configurators\ConfiguratorMenu::getMenu()
|
||||
*/
|
||||
public function getMenu($width, $height, Script $script, Player $player) {
|
||||
$paging = new Paging();
|
||||
@ -175,10 +172,7 @@ class PluginInstallMenu implements CallbackListener, ConfiguratorMenu, Manialink
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the Config Data
|
||||
*
|
||||
* @param array $configData
|
||||
* @param Player $player
|
||||
* @see \ManiaControl\Configurators\ConfiguratorMenu::saveConfigData()
|
||||
*/
|
||||
public function saveConfigData(array $configData, Player $player) {
|
||||
// TODO: Implement saveConfigData() method.
|
||||
|
@ -364,47 +364,46 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
|
||||
* @param array $callback
|
||||
*/
|
||||
public function handleManialinkPageAnswer(array $callback) {
|
||||
$actionId = $callback[1][2];
|
||||
$enable = (strpos($actionId, self::ACTION_PREFIX_ENABLEPLUGIN) === 0);
|
||||
$disable = (strpos($actionId, self::ACTION_PREFIX_DISABLEPLUGIN) === 0);
|
||||
$settings = (strpos($actionId, self::ACTION_PREFIX_SETTINGS) === 0);
|
||||
$boolSetting = (strpos($actionId, self::ACTION_SETTING_BOOL) === 0);
|
||||
|
||||
if (!$enable && !$disable && !$settings && !$boolSetting) {
|
||||
return;
|
||||
}
|
||||
$login = $callback[1][1];
|
||||
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||
if (!$player) {
|
||||
return;
|
||||
}
|
||||
|
||||
$actionId = $callback[1][2];
|
||||
$enable = (strpos($actionId, self::ACTION_PREFIX_ENABLEPLUGIN) === 0);
|
||||
$disable = (strpos($actionId, self::ACTION_PREFIX_DISABLEPLUGIN) === 0);
|
||||
$settings = (strpos($actionId, self::ACTION_PREFIX_SETTINGS) === 0);
|
||||
$boolSetting = (strpos($actionId, self::ACTION_SETTING_BOOL) === 0);
|
||||
if (!$enable && !$disable && !$settings && !$boolSetting) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($enable) {
|
||||
$pluginClass = substr($actionId, strlen(self::ACTION_PREFIX_ENABLEPLUGIN));
|
||||
/** @var Plugin $pluginClass */
|
||||
$activated = $this->maniaControl->pluginManager->activatePlugin($pluginClass, $player->login);
|
||||
if ($activated) {
|
||||
$this->maniaControl->chat->sendSuccess($pluginClass::getName() . ' activated!', $player->login);
|
||||
$this->maniaControl->configurator->showMenu($player);
|
||||
$this->maniaControl->log(Formatter::stripCodes("{$player->login} activated '{$pluginClass}'!"));
|
||||
$this->maniaControl->chat->sendSuccess($pluginClass::getName() . ' activated!', $player);
|
||||
$this->maniaControl->log("{$player->login} activated '{$pluginClass}'!", true);
|
||||
} else {
|
||||
$this->maniaControl->chat->sendError('Error activating ' . $pluginClass::getName() . '!', $player->login);
|
||||
$this->maniaControl->chat->sendError('Error activating ' . $pluginClass::getName() . '!', $player);
|
||||
}
|
||||
} else if ($disable) {
|
||||
$pluginClass = substr($actionId, strlen(self::ACTION_PREFIX_DISABLEPLUGIN));
|
||||
/** @var Plugin $pluginClass */
|
||||
$deactivated = $this->maniaControl->pluginManager->deactivatePlugin($pluginClass);
|
||||
if ($deactivated) {
|
||||
$this->maniaControl->chat->sendSuccess($pluginClass::getName() . ' deactivated!', $player->login);
|
||||
$this->maniaControl->configurator->showMenu($player);
|
||||
$this->maniaControl->log(Formatter::stripCodes("{$player->login} deactivated '{$pluginClass}'!"));
|
||||
$this->maniaControl->chat->sendSuccess($pluginClass::getName() . ' deactivated!', $player);
|
||||
$this->maniaControl->log("{$player->login} deactivated '{$pluginClass}'!", true);
|
||||
} else {
|
||||
$this->maniaControl->chat->sendError('Error deactivating ' . $pluginClass::getName() . '!', $player->login);
|
||||
$this->maniaControl->chat->sendError('Error deactivating ' . $pluginClass::getName() . '!', $player);
|
||||
}
|
||||
} else if ($settings) { //Open Settings Menu
|
||||
} else if ($settings) {
|
||||
// Open Settings Menu
|
||||
$pluginClass = substr($actionId, strlen(self::ACTION_PREFIX_SETTINGS));
|
||||
$this->settingsClass = $pluginClass;
|
||||
} else if ($boolSetting) {
|
||||
|
||||
$actionArray = explode(".", $actionId);
|
||||
$setting = $actionArray[1];
|
||||
|
||||
@ -415,38 +414,32 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
|
||||
$this->saveConfigData($callback[1], $player);
|
||||
}
|
||||
|
||||
//Reopen the Menu
|
||||
|
||||
// Reopen the Menu
|
||||
$menuId = $this->maniaControl->configurator->getMenuId($this->getTitle());
|
||||
|
||||
$this->maniaControl->configurator->reopenMenu($player, $menuId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle a Boolean Value
|
||||
*
|
||||
* @param $setting
|
||||
* @param int $settingIndex
|
||||
* @param Player $player
|
||||
*/
|
||||
public function toggleBooleanSetting($setting, Player $player) {
|
||||
public function toggleBooleanSetting($settingIndex, Player $player) {
|
||||
if (!$this->maniaControl->authenticationManager->checkPermission($player, self::SETTING_PERMISSION_CHANGE_PLUGIN_SETTINGS)) {
|
||||
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
||||
return;
|
||||
}
|
||||
|
||||
$oldSetting = $this->maniaControl->settingManager->getSettingByIndex($setting);
|
||||
$oldSetting = $this->maniaControl->settingManager->getSettingByIndex($settingIndex);
|
||||
|
||||
if (!isset($oldSetting)) {
|
||||
var_dump('no setting ' . $setting);
|
||||
var_dump('no setting with index: ' . $settingIndex);
|
||||
return;
|
||||
}
|
||||
|
||||
//Toggle value
|
||||
if ($oldSetting->value == "1") {
|
||||
$this->maniaControl->settingManager->setSetting($oldSetting->class, $oldSetting->setting, "0");
|
||||
} else {
|
||||
$this->maniaControl->settingManager->setSetting($oldSetting->class, $oldSetting->setting, "1");
|
||||
}
|
||||
// Toggle value
|
||||
$this->maniaControl->settingManager->setSetting($oldSetting->class, $oldSetting->setting, !$oldSetting->value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user