From 037534411ec0b4a2f7c603fe8097ae05c354fa69 Mon Sep 17 00:00:00 2001 From: Alexander Nell Date: Tue, 19 May 2020 14:30:31 +0200 Subject: [PATCH] Add setting to change dedi message format --- plugins/MCTeam/Dedimania/DedimaniaPlugin.php | 22 ++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/plugins/MCTeam/Dedimania/DedimaniaPlugin.php b/plugins/MCTeam/Dedimania/DedimaniaPlugin.php index e5a3ea08..ebc81d40 100644 --- a/plugins/MCTeam/Dedimania/DedimaniaPlugin.php +++ b/plugins/MCTeam/Dedimania/DedimaniaPlugin.php @@ -49,8 +49,9 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene const SETTING_WIDGET_LINE_COUNT = 'Widget Displayed Lines Count'; const SETTING_WIDGET_LINE_HEIGHT = 'Widget Line Height'; const SETTING_DEDIMANIA_CODE = '$l[http://dedimania.net/tm2stats/?do=register]Dedimania Code for '; - const SETTING_NOTIFY_BEST_RECORDS_PUBLIC = 'Notify Publicly only for the X Best Records'; + const SETTING_NOTIFICATION_MESSAGE_PREFIX = 'Notification Message Prefix'; const SETTING_NOTIFY_BEST_RECORDS_PRIVATE = 'Notify Privately only for the X Best Records'; + const SETTING_NOTIFY_BEST_RECORDS_PUBLIC = 'Notify Publicly only for the X Best Records'; const SETTING_MAX_RECORDS = 'Max Records, only increase if you bought a rank update from Dedimania!'; const CB_DEDIMANIA_CHANGED = 'Dedimania.Changed'; @@ -104,6 +105,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_WIDTH, 40); $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_LINE_HEIGHT, 4); $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_LINE_COUNT, 12); + $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_NOTIFICATION_MESSAGE_PREFIX, '$3c0'); $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_NOTIFY_BEST_RECORDS_PRIVATE, 30); $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_NOTIFY_BEST_RECORDS_PUBLIC, 15); $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MAX_RECORDS, 30); @@ -382,15 +384,27 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene $notifyName = 'You'; } - $message = '$390$<$fff' . $notifyName . '$> ' . $improvement . ' $<$ff0' . $newRecord->rank . '.$> Dedimania Record: $<$fff' . Formatter::formatTime($newRecord->best) . '$>'; + $messagePrefix = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_NOTIFICATION_MESSAGE_PREFIX); + $message = $messagePrefix . '$<$fff' . $notifyName . '$> ' . $improvement . ' $<$ff0' . $newRecord->rank . '.$> Dedimania Record: $<$fff' . Formatter::formatTime($newRecord->best) . '$>'; if (!$oldRecord->nullRecord) { $message .= ' ($<$ff0' . $oldRecord->rank . '.$> $<$fff-' . Formatter::formatTime(($oldRecord->best - $recTime)) . '$>)'; } + $message .= '!'; if ($newRecord->rank <= $notifyOnlyBestRecordsPublic) { - $this->maniaControl->getChat()->sendInformation($message . '!'); + $this->maniaControl->getCallQueueManager()->registerListening( + $this, + function () use ($message) { + $this->maniaControl->getChat()->sendInformation($message); + } + ); } elseif ($newRecord->rank <= $notifyOnlyBestRecordsPrivate) { - $this->maniaControl->getChat()->sendInformation($message . '!', $player); + $this->maniaControl->getCallQueueManager()->registerListening( + $this, + function () use ($message, $player) { + $this->maniaControl->getChat()->sendInformation($message, $player); + } + ); } $this->webHandler->maniaLinkUpdateNeeded();