updated playerlist, avoided multiple triggers

This commit is contained in:
kremsy 2017-05-21 18:36:01 +02:00
parent 2ec6fdbed9
commit 5ae7a7c20d
3 changed files with 23 additions and 9 deletions

View File

@ -84,7 +84,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
$this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
// Update Widget Events
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERINFOCHANGED, $this, 'updateWidget');
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERINFOSCHANGED, $this, 'updateWidget');
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'updateWidget');
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'updateWidget');
$this->maniaControl->getCallbackManager()->registerCallbackListener(AuthenticationManager::CB_AUTH_LEVEL_CHANGED, $this, 'updateWidget');
@ -819,9 +819,8 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
/**
* Reopen the widget on PlayerInfoChanged / Player Connect and Disconnect
*
* @param Player $player
*/
public function updateWidget(Player $player) {
public function updateWidget() {
foreach ($this->playersListShown as $login => $shown) {
if (!$shown) {
continue;

View File

@ -35,7 +35,9 @@ class PlayerManager implements CallbackListener, TimerListener, CommunicationLis
*/
const CB_PLAYERCONNECT = 'PlayerManagerCallback.PlayerConnect';
const CB_PLAYERDISCONNECT = 'PlayerManagerCallback.PlayerDisconnect';
/** @use CB_PlayerInfosChanged in favour to avoid multiple triggers at once */
const CB_PLAYERINFOCHANGED = 'PlayerManagerCallback.PlayerInfoChanged';
const CB_PLAYERINFOSCHANGED = 'PlayerManagerCallback.PlayerInfosChanged';
const CB_SERVER_EMPTY = 'PlayerManagerCallback.ServerEmpty';
const TABLE_PLAYERS = 'mc_players';
const SETTING_JOIN_LEAVE_MESSAGES = 'Enable Join & Leave Messages';
@ -70,6 +72,8 @@ class PlayerManager implements CallbackListener, TimerListener, CommunicationLis
/** @var AdminLists $adminLists */
private $adminLists = null;
private $playerInfosChangedTime = 0;
/**
* Construct a new Player Manager
*
@ -505,6 +509,16 @@ class PlayerManager implements CallbackListener, TimerListener, CommunicationLis
// Trigger own callback
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_PLAYERINFOCHANGED, $player);
//Avoid Multiple Triggers
if ((microtime(true) - 0.5) > $this->playerInfosChangedTime) {
//Delay Callback by a short Time (200ms) to be sure that different changes get submitted the same time
$this->maniaControl->getTimerManager()->registerOneTimeListening($this, function () {
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_PLAYERINFOSCHANGED);
}, 200);
}
$this->playerInfosChangedTime = microtime(true);
}
/**

View File

@ -130,7 +130,7 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::MP_PODIUMSTART, $this, 'handleOnEndMap');
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'updateWidgets');
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERINFOCHANGED, $this, 'updateWidgets');
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERINFOSCHANGED, $this, 'updateWidgets');
$this->maniaControl->getCallbackManager()->registerCallbackListener(SettingManager::CB_SETTING_CHANGED, $this, 'updateSettings');
// Settings
@ -559,6 +559,7 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SERVERINFO_WIDGET_ACTIVATED)) {
$time = time();
//Update Max once per second
//TODO the one time can be removed due the new PlayerInfosChanged Callback
if ($this->lastWidgetUpdateTime < ($time - 1)) {
$this->displayServerInfoWidget();
$this->lastWidgetUpdateTime = $time;