diff --git a/Beu/SimpleSkinsRemover.php b/Beu/SimpleSkinsRemover.php new file mode 100644 index 0000000..5aefea4 --- /dev/null +++ b/Beu/SimpleSkinsRemover.php @@ -0,0 +1,169 @@ +maniaControl = $maniaControl;iaControl\Plugins\Plugin::getAuthor() + */ + public static function getAuthor() { + return self::PLUGIN_AUTHOR; + } + + /** + * @see \ManiaControl\Plugins\Plugin::getDescription() + */ + public static function getDescription() { + return 'Allows to disable skins very easily, manually or automatically depending on the number of players on the server'; + } + + /** + * @see \ManiaControl\Plugins\Plugin::load() + */ + public function load(ManiaControl $maniaControl) { + $this->maniaControl = $maniaControl; + + $this->maniaControl->getCallbackManager()->registerCallbackListener(SettingManager::CB_SETTING_CHANGED, $this, 'updateSettings'); + $this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnectOrDisconnect'); + $this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'handlePlayerConnectOrDisconnect'); + $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_SIMPLESKINSREMOVER_DISABLE_SKINS, false, "Disable skins (ignore automatic disabling)"); + $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_SIMPLESKINSREMOVER_AUTOMATIC, false, "Disable skins depending on the number of players"); + $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_SIMPLESKINSREMOVER_AUTOMATIC_VALUE, 50, "Number of players before deactivating the skins"); + + $this->maniaControl->getCommandManager()->registerCommandListener('skinsstatus', $this, 'skinsstatus', false, 'Check if skins are really disabled'); + + $this->UpdateSkinsRemover(); + + return true; + } + + /** + * @see \ManiaControl\Plugins\Plugin::unload() + */ + public function unload() { + $this->maniaControl->getClient()->execute('DisableProfileSkins', array(false)); + } + + /** + * Update Widgets on Setting Changes + * + * @param Setting $setting + */ + public function updateSettings(Setting $setting) { + if ($setting->belongsToClass($this)) { + $this->UpdateSkinsRemover(); + } + } + + /** + * Enables or disables skins, depending on conditions + * + */ + private function UpdateSkinsRemover() { + $currentstatus = $this->maniaControl->getClient()->execute('AreProfileSkinsDisabled', array()); + if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SIMPLESKINSREMOVER_DISABLE_SKINS)) { + if ($currentstatus == false) { + $this->maniaControl->getClient()->execute('DisableProfileSkins', array(true)); + $this->maniaControl->getChat()->sendSuccess(' Skins are now disabled on this server to improve the quality of life of all players'); + } + } else if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SIMPLESKINSREMOVER_AUTOMATIC) && $this->maniaControl->getPlayerManager()->getPlayerCount(false,false) >= $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SIMPLESKINSREMOVER_AUTOMATIC_VALUE)) { + if ($currentstatus == false) { + $this->maniaControl->getClient()->execute('DisableProfileSkins', array(true)); + $this->maniaControl->getChat()->sendSuccess(' Skins are now disabled on this server to improve the quality of life of all players'); + } + } else { + if ($currentstatus == true) { + $this->maniaControl->getClient()->execute('DisableProfileSkins', array(false)); + $this->maniaControl->getChat()->sendSuccess(' Skins are now enabled on this server'); + } + } + } + + /** + * Informs if the skins are activated or not + * + * @param array $chat + * @param \ManiaControl\Players\Player $player + */ + public function skinsstatus(Array $chat, Player $player) { + if ($this->maniaControl->getClient()->execute('AreProfileSkinsDisabled', array())) { + $this->maniaControl->getChat()->sendSuccess(' Skins are disabled', $player); + } else { + $this->maniaControl->getChat()->sendError(' Skins are enabled', $player); + } + } + + /** + * Handle when a player connect + * + * @param \ManiaControl\Players\Player $player + */ + public function handlePlayerConnectOrDisconnect(Player $player) { + $currentstatus = $this->maniaControl->getClient()->execute('AreProfileSkinsDisabled', array()); + $this->UpdateSkinsRemover(); + if ($currentstatus == $this->maniaControl->getClient()->execute('AreProfileSkinsDisabled', array()) && $currentstatus == true) { + $this->maniaControl->getChat()->sendSuccess(' Skins are disabled on this server to improve the quality of life of all players', $player); + } + } +}