fixed unregister manialinkpageanswerslistener....
This commit is contained in:
parent
c5beeab0eb
commit
7b17f51606
@ -92,12 +92,17 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
|
|||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function unregisterManialinkPageAnswerListener(ManialinkPageAnswerListener $listener) {
|
public function unregisterManialinkPageAnswerListener(ManialinkPageAnswerListener $listener) {
|
||||||
$keys = array_keys($this->pageAnswerListeners, $listener);
|
$removed = false;
|
||||||
foreach($keys as $key) {
|
foreach($this->pageAnswerListeners as &$listeners) {
|
||||||
unset($this->pageAnswerListeners[$key]);
|
foreach($listeners as $key => &$listenerCallback) {
|
||||||
|
if($listenerCallback[0] != $listener) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
unset($listeners[$key]);
|
||||||
return true;
|
$removed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $removed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -137,15 +137,18 @@ class PluginManager {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$plugin = new $pluginClass();
|
$plugin = new $pluginClass();
|
||||||
|
$this->activePlugins[$pluginClass] = $plugin;
|
||||||
|
$this->savePluginStatus($pluginClass, true);
|
||||||
try {
|
try {
|
||||||
$plugin->load($this->maniaControl);
|
$plugin->load($this->maniaControl);
|
||||||
} catch(\Exception $e) {
|
} catch(\Exception $e) {
|
||||||
$this->maniaControl->chat->sendError('Error while plugin activating ' . $pluginClass . ': ' . $e->getMessage(), $adminLogin);
|
$this->maniaControl->chat->sendError('Error while plugin activating ' . $pluginClass . ': ' . $e->getMessage(), $adminLogin);
|
||||||
$this->maniaControl->log('Error while plugin activation: ' . $pluginClass . ': ' . $e->getMessage());
|
$this->maniaControl->log('Error while plugin activation: ' . $pluginClass . ': ' . $e->getMessage());
|
||||||
|
unset($this->activePlugins[$pluginClass]);
|
||||||
|
$this->savePluginStatus($pluginClass, false);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->activePlugins[$pluginClass] = $plugin;
|
|
||||||
$this->savePluginStatus($pluginClass, true);
|
$this->savePluginStatus($pluginClass, true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
143
application/core/Statistics/SimpleStatsList.php
Normal file
143
application/core/Statistics/SimpleStatsList.php
Normal file
@ -0,0 +1,143 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace ManiaControl\Statistics;
|
||||||
|
|
||||||
|
|
||||||
|
use FML\Controls\Control;
|
||||||
|
use FML\Controls\Frame;
|
||||||
|
use FML\Controls\Label;
|
||||||
|
use FML\Controls\Quad;
|
||||||
|
use FML\Controls\Quads\Quad_BgsPlayerCard;
|
||||||
|
use FML\Controls\Quads\Quad_Icons64x64_1;
|
||||||
|
use FML\Controls\Quads\Quad_UIConstruction_Buttons;
|
||||||
|
use FML\ManiaLink;
|
||||||
|
use ManiaControl\ManiaControl;
|
||||||
|
use ManiaControl\Manialinks\ManialinkManager;
|
||||||
|
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
||||||
|
use ManiaControl\Players\Player;
|
||||||
|
|
||||||
|
class SimpleStatsList implements ManialinkPageAnswerListener{
|
||||||
|
/**
|
||||||
|
* Constants
|
||||||
|
*/
|
||||||
|
const ACTION_OPEN_STATSLIST = 'SimpleStatsList.OpenStatsList';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Private Properties
|
||||||
|
*/
|
||||||
|
private $maniaControl = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a PlayerList Instance
|
||||||
|
*
|
||||||
|
* @param ManiaControl $maniaControl
|
||||||
|
*/
|
||||||
|
public function __construct(ManiaControl $maniaControl) {
|
||||||
|
$this->maniaControl = $maniaControl;
|
||||||
|
|
||||||
|
//$this->maniaControl->callbackManager->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_CLOSED, $this, 'closeWidget');
|
||||||
|
//$this->maniaControl->callbackManager->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_OPENED, $this, 'handleWidgetOpened');
|
||||||
|
//$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
|
||||||
|
|
||||||
|
// Action Open Playerlist
|
||||||
|
//$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_OPEN_STATSLIST, $this, 'command_playerList');
|
||||||
|
$itemQuad = new Quad_UIConstruction_Buttons();
|
||||||
|
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_Author);
|
||||||
|
$itemQuad->setAction(self::ACTION_OPEN_STATSLIST);
|
||||||
|
//$this->maniaControl->actionsMenu->addMenuItem($itemQuad, true, 14, 'Open Statistics');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show the PlayerList Widget to the Player
|
||||||
|
*
|
||||||
|
* @param Player $player
|
||||||
|
*/
|
||||||
|
public function showStatsList(Player $player) {
|
||||||
|
$width = $this->maniaControl->manialinkManager->styleManager->getListWidgetsWidth();
|
||||||
|
$height = $this->maniaControl->manialinkManager->styleManager->getListWidgetsHeight();
|
||||||
|
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowStyle();
|
||||||
|
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowSubStyle();
|
||||||
|
|
||||||
|
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
|
||||||
|
$script = $maniaLink->getScript();
|
||||||
|
|
||||||
|
// Main frame
|
||||||
|
$frame = new Frame();
|
||||||
|
$maniaLink->add($frame);
|
||||||
|
$frame->setSize($width, $height);
|
||||||
|
$frame->setPosition(0, 0, 10);
|
||||||
|
|
||||||
|
// Background
|
||||||
|
$backgroundQuad = new Quad();
|
||||||
|
$frame->add($backgroundQuad);
|
||||||
|
$backgroundQuad->setSize($width, $height);
|
||||||
|
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
|
||||||
|
|
||||||
|
// Close Quad (X)
|
||||||
|
$closeQuad = new Quad_Icons64x64_1();
|
||||||
|
$frame->add($closeQuad);
|
||||||
|
$closeQuad->setPosition($width * 0.483, $height * 0.467, 3);
|
||||||
|
$closeQuad->setSize(6, 6);
|
||||||
|
$closeQuad->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_QuitRace);
|
||||||
|
$closeQuad->setAction(ManialinkManager::ACTION_CLOSEWIDGET);
|
||||||
|
|
||||||
|
// Start offsets
|
||||||
|
$x = -$width / 2;
|
||||||
|
$y = $height / 2;
|
||||||
|
|
||||||
|
// Predefine Description Label
|
||||||
|
$descriptionLabel = new Label();
|
||||||
|
$frame->add($descriptionLabel);
|
||||||
|
$descriptionLabel->setAlign(Control::LEFT, Control::TOP);
|
||||||
|
$descriptionLabel->setPosition($x + 10, -$height / 2 + 5);
|
||||||
|
$descriptionLabel->setSize($width * 0.7, 4);
|
||||||
|
$descriptionLabel->setTextSize(2);
|
||||||
|
$descriptionLabel->setVisible(false);
|
||||||
|
|
||||||
|
// Headline
|
||||||
|
$headFrame = new Frame();
|
||||||
|
$frame->add($headFrame);
|
||||||
|
$headFrame->setY($y - 5);
|
||||||
|
|
||||||
|
$array = array("Id" => $x + 5, "Nickname" => $x + 18, "Login" => $x + 70, "Location" => $x + 101);
|
||||||
|
$this->maniaControl->manialinkManager->labelLine($headFrame, $array);
|
||||||
|
|
||||||
|
// get PlayerList
|
||||||
|
$players = $this->maniaControl->playerManager->getPlayers();
|
||||||
|
|
||||||
|
$i = 1;
|
||||||
|
$y -= 10;
|
||||||
|
foreach($players as $listPlayer) {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @var Player $listPlayer
|
||||||
|
*/
|
||||||
|
|
||||||
|
$path = $listPlayer->getProvince();
|
||||||
|
$playerFrame = new Frame();
|
||||||
|
$frame->add($playerFrame);
|
||||||
|
|
||||||
|
if($i % 2 != 0) {
|
||||||
|
$lineQuad = new Quad_BgsPlayerCard();
|
||||||
|
$playerFrame->add($lineQuad);
|
||||||
|
$lineQuad->setSize($width, 4);
|
||||||
|
$lineQuad->setSubStyle($lineQuad::SUBSTYLE_BgPlayerCardBig);
|
||||||
|
$lineQuad->setZ(0.001);
|
||||||
|
}
|
||||||
|
|
||||||
|
$array = array($i => $x + 5, $listPlayer->nickname => $x + 18, $listPlayer->login => $x + 70, $path => $x + 101);
|
||||||
|
$this->maniaControl->manialinkManager->labelLine($playerFrame, $array);
|
||||||
|
|
||||||
|
$playerFrame->setY($y);
|
||||||
|
|
||||||
|
|
||||||
|
$i++;
|
||||||
|
$y -= 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Render and display xml
|
||||||
|
$this->maniaControl->manialinkManager->displayWidget($maniaLink, $player, 'PlayerList');
|
||||||
|
}
|
||||||
|
}
|
@ -6,6 +6,7 @@ use ManiaControl\ManiaControl;
|
|||||||
use ManiaControl\Players\Player;
|
use ManiaControl\Players\Player;
|
||||||
|
|
||||||
require_once __DIR__ . '/StatisticCollector.php';
|
require_once __DIR__ . '/StatisticCollector.php';
|
||||||
|
require_once __DIR__ . '/SimpleStatsList.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Statistic Manager Class
|
* Statistic Manager Class
|
||||||
@ -27,6 +28,7 @@ class StatisticManager {
|
|||||||
* Public Properties
|
* Public Properties
|
||||||
*/
|
*/
|
||||||
public $statisticCollector = null;
|
public $statisticCollector = null;
|
||||||
|
public $simpleStatsList = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private Properties
|
* Private Properties
|
||||||
@ -44,6 +46,7 @@ class StatisticManager {
|
|||||||
$this->initTables();
|
$this->initTables();
|
||||||
|
|
||||||
$this->statisticCollector = new StatisticCollector($maniaControl);
|
$this->statisticCollector = new StatisticCollector($maniaControl);
|
||||||
|
$this->simpleStatsList = new SimpleStatsList($maniaControl);
|
||||||
|
|
||||||
// Store Stats MetaData
|
// Store Stats MetaData
|
||||||
$this->storeStatMetaData();
|
$this->storeStatMetaData();
|
||||||
@ -61,21 +64,18 @@ class StatisticManager {
|
|||||||
$mysqli = $this->maniaControl->database->mysqli;
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
$statId = $this->getStatId($statName);
|
$statId = $this->getStatId($statName);
|
||||||
|
|
||||||
if ($statId == null) {
|
if($statId == null) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($serverIndex == -1) {
|
if($serverIndex == -1) {
|
||||||
$query = "SELECT SUM(value) as value FROM `" . self::TABLE_STATISTICS . "` WHERE `statId` = " . $statId . " AND `playerId` = " . $playerId .
|
$query = "SELECT SUM(value) as value FROM `" . self::TABLE_STATISTICS . "` WHERE `statId` = " . $statId . " AND `playerId` = " . $playerId . ";";
|
||||||
";";
|
} else {
|
||||||
}
|
$query = "SELECT value FROM `" . self::TABLE_STATISTICS . "` WHERE `statId` = " . $statId . " AND `playerId` = " . $playerId . " AND `serverIndex` = '" . $serverIndex . "';";
|
||||||
else {
|
|
||||||
$query = "SELECT value FROM `" . self::TABLE_STATISTICS . "` WHERE `statId` = " . $statId . " AND `playerId` = " . $playerId .
|
|
||||||
" AND `serverIndex` = '" . $serverIndex . "';";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = $mysqli->query($query);
|
$result = $mysqli->query($query);
|
||||||
if (!$result) {
|
if(!$result) {
|
||||||
trigger_error($mysqli->error);
|
trigger_error($mysqli->error);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -94,12 +94,12 @@ class StatisticManager {
|
|||||||
|
|
||||||
$query = "SELECT * FROM `" . self::TABLE_STATMETADATA . "`;";
|
$query = "SELECT * FROM `" . self::TABLE_STATMETADATA . "`;";
|
||||||
$result = $mysqli->query($query);
|
$result = $mysqli->query($query);
|
||||||
if (!$result) {
|
if(!$result) {
|
||||||
trigger_error($mysqli->error);
|
trigger_error($mysqli->error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ($row = $result->fetch_object()) {
|
while($row = $result->fetch_object()) {
|
||||||
$this->stats[$row->name] = $row;
|
$this->stats[$row->name] = $row;
|
||||||
}
|
}
|
||||||
$result->close();
|
$result->close();
|
||||||
@ -112,9 +112,9 @@ class StatisticManager {
|
|||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
private function getStatId($statName) {
|
private function getStatId($statName) {
|
||||||
if (isset($this->stats[$statName])) {
|
if(isset($this->stats[$statName])) {
|
||||||
$stat = $this->stats[$statName];
|
$stat = $this->stats[$statName];
|
||||||
return (int) $stat->index;
|
return (int)$stat->index;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -129,7 +129,7 @@ class StatisticManager {
|
|||||||
public function getAllPlayerStats(Player $player, $serverIndex = -1) {
|
public function getAllPlayerStats(Player $player, $serverIndex = -1) {
|
||||||
// TODO improve performance
|
// TODO improve performance
|
||||||
$playerStats = array();
|
$playerStats = array();
|
||||||
foreach ($this->stats as $stat) {
|
foreach($this->stats as $stat) {
|
||||||
$value = $this->getStatisticData($stat->name, $player->index, $serverIndex);
|
$value = $this->getStatisticData($stat->name, $player->index, $serverIndex);
|
||||||
$playerStats[$stat->name] = array($stat, $value);
|
$playerStats[$stat->name] = array($stat, $value);
|
||||||
}
|
}
|
||||||
@ -148,12 +148,18 @@ class StatisticManager {
|
|||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function insertStat($statName, Player $player, $serverIndex = -1, $value, $statType = self::STAT_TYPE_INT) {
|
public function insertStat($statName, Player $player, $serverIndex = -1, $value, $statType = self::STAT_TYPE_INT) {
|
||||||
if (!$player) return false;
|
if(!$player) {
|
||||||
if ($player->isFakePlayer()) return true;
|
return false;
|
||||||
|
}
|
||||||
|
if($player->isFakePlayer()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
$statId = $this->getStatId($statName);
|
$statId = $this->getStatId($statName);
|
||||||
if (!$statId) return false;
|
if(!$statId) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if ($serverIndex == -1) {
|
if($serverIndex == -1) {
|
||||||
$serverIndex = $this->maniaControl->server->index;
|
$serverIndex = $this->maniaControl->server->index;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,13 +174,13 @@ class StatisticManager {
|
|||||||
) ON DUPLICATE KEY UPDATE
|
) ON DUPLICATE KEY UPDATE
|
||||||
`value` = `value` + VALUES(`value`);";
|
`value` = `value` + VALUES(`value`);";
|
||||||
$statement = $mysqli->prepare($query);
|
$statement = $mysqli->prepare($query);
|
||||||
if ($mysqli->error) {
|
if($mysqli->error) {
|
||||||
trigger_error($mysqli->error);
|
trigger_error($mysqli->error);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$statement->bind_param('iiii', $serverIndex, $player->index, $statId, $value);
|
$statement->bind_param('iiii', $serverIndex, $player->index, $statId, $value);
|
||||||
$statement->execute();
|
$statement->execute();
|
||||||
if ($statement->error) {
|
if($statement->error) {
|
||||||
trigger_error($statement->error);
|
trigger_error($statement->error);
|
||||||
$statement->close();
|
$statement->close();
|
||||||
return false;
|
return false;
|
||||||
@ -215,13 +221,13 @@ class StatisticManager {
|
|||||||
`type` = VALUES(`type`),
|
`type` = VALUES(`type`),
|
||||||
`description` = VALUES(`description`);";
|
`description` = VALUES(`description`);";
|
||||||
$statement = $mysqli->prepare($query);
|
$statement = $mysqli->prepare($query);
|
||||||
if ($mysqli->error) {
|
if($mysqli->error) {
|
||||||
trigger_error($mysqli->error);
|
trigger_error($mysqli->error);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$statement->bind_param('sis', $statName, $type, $statDescription);
|
$statement->bind_param('sis', $statName, $type, $statDescription);
|
||||||
$statement->execute();
|
$statement->execute();
|
||||||
if ($statement->error) {
|
if($statement->error) {
|
||||||
trigger_error($statement->error);
|
trigger_error($statement->error);
|
||||||
$statement->close();
|
$statement->close();
|
||||||
return false;
|
return false;
|
||||||
@ -246,12 +252,12 @@ class StatisticManager {
|
|||||||
UNIQUE KEY `name` (`name`)
|
UNIQUE KEY `name` (`name`)
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Statistics Meta Data' AUTO_INCREMENT=1;";
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Statistics Meta Data' AUTO_INCREMENT=1;";
|
||||||
$statement = $mysqli->prepare($query);
|
$statement = $mysqli->prepare($query);
|
||||||
if ($mysqli->error) {
|
if($mysqli->error) {
|
||||||
trigger_error($mysqli->error, E_USER_ERROR);
|
trigger_error($mysqli->error, E_USER_ERROR);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$statement->execute();
|
$statement->execute();
|
||||||
if ($statement->error) {
|
if($statement->error) {
|
||||||
trigger_error($statement->error, E_USER_ERROR);
|
trigger_error($statement->error, E_USER_ERROR);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -267,12 +273,12 @@ class StatisticManager {
|
|||||||
UNIQUE KEY `unique` (`statId`,`playerId`,`serverIndex`)
|
UNIQUE KEY `unique` (`statId`,`playerId`,`serverIndex`)
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Statistics' AUTO_INCREMENT=1;";
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Statistics' AUTO_INCREMENT=1;";
|
||||||
$statement = $mysqli->prepare($query);
|
$statement = $mysqli->prepare($query);
|
||||||
if ($mysqli->error) {
|
if($mysqli->error) {
|
||||||
trigger_error($mysqli->error, E_USER_ERROR);
|
trigger_error($mysqli->error, E_USER_ERROR);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$statement->execute();
|
$statement->execute();
|
||||||
if ($statement->error) {
|
if($statement->error) {
|
||||||
trigger_error($statement->error, E_USER_ERROR);
|
trigger_error($statement->error, E_USER_ERROR);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -139,6 +139,8 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
|
|||||||
$manialinkText = $emptyManialink->render()->saveXML();
|
$manialinkText = $emptyManialink->render()->saveXML();
|
||||||
$this->maniaControl->manialinkManager->sendManialink($manialinkText);
|
$this->maniaControl->manialinkManager->sendManialink($manialinkText);
|
||||||
$this->maniaControl->commandManager->unregisterCommandListener($this);
|
$this->maniaControl->commandManager->unregisterCommandListener($this);
|
||||||
|
$this->maniaControl->callbackManager->unregisterCallbackListener($this);
|
||||||
|
$this->maniaControl->manialinkManager->unregisterManialinkPageAnswerListener($this);
|
||||||
unset($this->maniaControl);
|
unset($this->maniaControl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user