activated tooltip option OnClick

This commit is contained in:
Steffen Schröder 2014-01-05 14:14:08 +01:00
parent 7c2508a0af
commit eb37af0579
2 changed files with 143 additions and 141 deletions

View File

@ -205,7 +205,7 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
$backgroundQuad->setStyles($quadStyle, $quadSubstyle); $backgroundQuad->setStyles($quadStyle, $quadSubstyle);
$backgroundQuad->setSize(count($this->adminMenuItems) * $itemSize * 1.15 + 2, $itemSize * $itemMarginFactorY); $backgroundQuad->setSize(count($this->adminMenuItems) * $itemSize * 1.15 + 2, $itemSize * $itemMarginFactorY);
$script->addTooltip($itemQuad, $popoutFrame, Script::OPTION_TOOLTIP_STAYONCLICK); $script->addTooltip($itemQuad, $popoutFrame, Script::OPTION_TOOLTIP_ONCLICK);
// Add items // Add items
$x = -1; $x = -1;
@ -273,7 +273,7 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
$backgroundQuad->setStyles($quadStyle, $quadSubstyle); $backgroundQuad->setStyles($quadStyle, $quadSubstyle);
$backgroundQuad->setSize(count($this->playerMenuItems) * $itemSize * 1.15 + 2, $itemSize * $itemMarginFactorY); $backgroundQuad->setSize(count($this->playerMenuItems) * $itemSize * 1.15 + 2, $itemSize * $itemMarginFactorY);
$script->addTooltip($itemQuad, $popoutFrame, Script::OPTION_TOOLTIP_STAYONCLICK); $script->addTooltip($itemQuad, $popoutFrame, Script::OPTION_TOOLTIP_ONCLICK);
// Add items // Add items
$x = -1; $x = -1;

View File

@ -20,31 +20,34 @@ use ManiaControl\Plugins\Plugin;
/** /**
* Donation plugin * Donation plugin
* *
* @author steeffeen and Lukas * @author steeffeen & kremsy
*/ */
class DonationPlugin implements CallbackListener, CommandListener, Plugin { class DonationPlugin implements CallbackListener, CommandListener, Plugin {
/** /**
* Constants * Constants
*/ */
const ID = 3; const ID = 3;
const VERSION = 0.1; const VERSION = 0.1;
const SETTING_ANNOUNCE_SERVERDONATION = 'Enable Server-Donation Announcements'; const SETTING_ANNOUNCE_SERVERDONATION = 'Enable Server-Donation Announcements';
const STAT_PLAYER_DONATIONS = 'Donated Planets'; const STAT_PLAYER_DONATIONS = 'Donated Planets';
const ACTION_DONATE_VALUE = 'Donate.DonateValue'; const ACTION_DONATE_VALUE = 'Donate.DonateValue';
// DonateWidget Properties // DonateWidget Properties
const MLID_DONATE_WIDGET = 'DonationPlugin.DonateWidget'; const MLID_DONATE_WIDGET = 'DonationPlugin.DonateWidget';
const SETTING_DONATE_WIDGET_ACTIVATED = 'Donate-Widget Activated'; const SETTING_DONATE_WIDGET_ACTIVATED = 'Donate-Widget Activated';
const SETTING_DONATE_WIDGET_POSX = 'Donate-Widget-Position: X'; const SETTING_DONATE_WIDGET_POSX = 'Donate-Widget-Position: X';
const SETTING_DONATE_WIDGET_POSY = 'Donate-Widget-Position: Y'; const SETTING_DONATE_WIDGET_POSY = 'Donate-Widget-Position: Y';
const SETTING_DONATE_WIDGET_WIDTH = 'Donate-Widget-Size: Width'; const SETTING_DONATE_WIDGET_WIDTH = 'Donate-Widget-Size: Width';
const SETTING_DONATE_WIDGET_HEIGHT = 'Donate-Widget-Size: Height'; const SETTING_DONATE_WIDGET_HEIGHT = 'Donate-Widget-Size: Height';
const SETTING_DONATION_VALUES = 'Donation Values'; const SETTING_DONATION_VALUES = 'Donation Values';
/** /**
* Private properties * Private properties
*/ */
/** @var maniaControl $maniaControl */ /**
*
* @var maniaControl $maniaControl
*/
private $maniaControl = null; private $maniaControl = null;
private $openBills = array(); private $openBills = array();
@ -54,28 +57,29 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
*/ */
public function load(ManiaControl $maniaControl) { public function load(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
// Register for commands // Register for commands
$this->maniaControl->commandManager->registerCommandListener('donate', $this, 'command_Donate'); $this->maniaControl->commandManager->registerCommandListener('donate', $this, 'command_Donate');
$this->maniaControl->commandManager->registerCommandListener('pay', $this, 'command_Pay', true); $this->maniaControl->commandManager->registerCommandListener('pay', $this, 'command_Pay', true);
$this->maniaControl->commandManager->registerCommandListener('getplanets', $this, 'command_GetPlanets', true); $this->maniaControl->commandManager->registerCommandListener('getplanets', $this, 'command_GetPlanets', true);
// Register for callbacks // Register for callbacks
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_BILLUPDATED, $this, 'handleBillUpdated'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_BILLUPDATED, $this, 'handleBillUpdated');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'handleOnInit'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'handleOnInit');
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERJOINED, $this, 'handlePlayerConnect'); $this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERJOINED, $this, 'handlePlayerConnect');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this,
'handleManialinkPageAnswer');
// Define player stats // Define player stats
$this->maniaControl->statisticManager->defineStatMetaData(self::STAT_PLAYER_DONATIONS); $this->maniaControl->statisticManager->defineStatMetaData(self::STAT_PLAYER_DONATIONS);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_DONATE_WIDGET_ACTIVATED, true); $this->maniaControl->settingManager->initSetting($this, self::SETTING_DONATE_WIDGET_ACTIVATED, true);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_DONATE_WIDGET_POSX, 156.); $this->maniaControl->settingManager->initSetting($this, self::SETTING_DONATE_WIDGET_POSX, 156.);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_DONATE_WIDGET_POSY, -51.4); $this->maniaControl->settingManager->initSetting($this, self::SETTING_DONATE_WIDGET_POSY, -51.4);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_DONATE_WIDGET_WIDTH, 6); $this->maniaControl->settingManager->initSetting($this, self::SETTING_DONATE_WIDGET_WIDTH, 6);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_DONATE_WIDGET_HEIGHT, 6); $this->maniaControl->settingManager->initSetting($this, self::SETTING_DONATE_WIDGET_HEIGHT, 6);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_DONATION_VALUES, "20,50,100,500,1000,2000"); $this->maniaControl->settingManager->initSetting($this, self::SETTING_DONATION_VALUES, "20,50,100,500,1000,2000");
return true; return true;
} }
@ -135,7 +139,7 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
* @param array $callback * @param array $callback
*/ */
public function handleOnInit(array $callback) { public function handleOnInit(array $callback) {
if($this->maniaControl->settingManager->getSetting($this, self::SETTING_DONATE_WIDGET_ACTIVATED)) { if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_DONATE_WIDGET_ACTIVATED)) {
$this->displayDonateWidget(); $this->displayDonateWidget();
} }
} }
@ -146,20 +150,13 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
* @param array $callback * @param array $callback
*/ */
public function handleManialinkPageAnswer(array $callback) { public function handleManialinkPageAnswer(array $callback) {
$actionId = $callback[1][2]; $actionId = $callback[1][2];
$boolSetting = (strpos($actionId, self::ACTION_DONATE_VALUE) === 0); $boolSetting = (strpos($actionId, self::ACTION_DONATE_VALUE) === 0);
if(!$boolSetting) { if (!$boolSetting) return;
return;
}
$login = $callback[1][1]; $login = $callback[1][1];
$player = $this->maniaControl->playerManager->getPlayer($login); $player = $this->maniaControl->playerManager->getPlayer($login);
$actionArray = explode(".", $callback[1][2]); $actionArray = explode(".", $callback[1][2]);
$this->handleDonation($player, intval($actionArray[2])); $this->handleDonation($player, intval($actionArray[2]));
} }
/** /**
@ -170,7 +167,7 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
public function handlePlayerConnect(array $callback) { public function handlePlayerConnect(array $callback) {
$player = $callback[1]; $player = $callback[1];
// Display Map Widget // Display Map Widget
if($this->maniaControl->settingManager->getSetting($this, self::SETTING_DONATE_WIDGET_ACTIVATED)) { if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_DONATE_WIDGET_ACTIVATED)) {
$this->displayDonateWidget($player->login); $this->displayDonateWidget($player->login);
} }
} }
@ -181,68 +178,66 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
* @param bool $login * @param bool $login
*/ */
public function displayDonateWidget($login = false) { public function displayDonateWidget($login = false) {
$posX = $this->maniaControl->settingManager->getSetting($this, self::SETTING_DONATE_WIDGET_POSX); $posX = $this->maniaControl->settingManager->getSetting($this, self::SETTING_DONATE_WIDGET_POSX);
$posY = $this->maniaControl->settingManager->getSetting($this, self::SETTING_DONATE_WIDGET_POSY); $posY = $this->maniaControl->settingManager->getSetting($this, self::SETTING_DONATE_WIDGET_POSY);
$width = $this->maniaControl->settingManager->getSetting($this, self::SETTING_DONATE_WIDGET_WIDTH); $width = $this->maniaControl->settingManager->getSetting($this, self::SETTING_DONATE_WIDGET_WIDTH);
$height = $this->maniaControl->settingManager->getSetting($this, self::SETTING_DONATE_WIDGET_HEIGHT); $height = $this->maniaControl->settingManager->getSetting($this, self::SETTING_DONATE_WIDGET_HEIGHT);
$values = $this->maniaControl->settingManager->getSetting($this, self::SETTING_DONATION_VALUES); $values = $this->maniaControl->settingManager->getSetting($this, self::SETTING_DONATION_VALUES);
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle(); $quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle();
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle(); $quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle();
$itemMarginFactorX = 1.3; $itemMarginFactorX = 1.3;
$itemMarginFactorY = 1.2; $itemMarginFactorY = 1.2;
$itemSize = $width; $itemSize = $width;
$maniaLink = new ManiaLink(self::MLID_DONATE_WIDGET); $maniaLink = new ManiaLink(self::MLID_DONATE_WIDGET);
$script = new Script(); $script = new Script();
$maniaLink->setScript($script); $maniaLink->setScript($script);
//Donate Menu Icon Frame // Donate Menu Icon Frame
$frame = new Frame(); $frame = new Frame();
$maniaLink->add($frame); $maniaLink->add($frame);
$frame->setPosition($posX, $posY); $frame->setPosition($posX, $posY);
$backgroundQuad = new Quad(); $backgroundQuad = new Quad();
$frame->add($backgroundQuad); $frame->add($backgroundQuad);
$backgroundQuad->setSize($width * $itemMarginFactorX, $height * $itemMarginFactorY); $backgroundQuad->setSize($width * $itemMarginFactorX, $height * $itemMarginFactorY);
$backgroundQuad->setStyles($quadStyle, $quadSubstyle); $backgroundQuad->setStyles($quadStyle, $quadSubstyle);
$iconFrame = new Frame(); $iconFrame = new Frame();
$frame->add($iconFrame); $frame->add($iconFrame);
$iconFrame->setSize($itemSize, $itemSize); $iconFrame->setSize($itemSize, $itemSize);
$itemQuad = new Quad_Icons128x128_1(); $itemQuad = new Quad_Icons128x128_1();
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_Coppers); $itemQuad->setSubStyle($itemQuad::SUBSTYLE_Coppers);
$itemQuad->setSize($itemSize, $itemSize); $itemQuad->setSize($itemSize, $itemSize);
$iconFrame->add($itemQuad); $iconFrame->add($itemQuad);
$valueArray = explode(",", $values); $valueArray = explode(",", $values);
//Values Menu // Values Menu
$popoutFrame = new Frame(); $popoutFrame = new Frame();
$maniaLink->add($popoutFrame); $maniaLink->add($popoutFrame);
$popoutFrame->setPosition($posX - $itemSize * 0.5, $posY); $popoutFrame->setPosition($posX - $itemSize * 0.5, $posY);
$popoutFrame->setHAlign(Control::RIGHT); $popoutFrame->setHAlign(Control::RIGHT);
$popoutFrame->setSize(4 * $itemSize * $itemMarginFactorX, $itemSize * $itemMarginFactorY); $popoutFrame->setSize(4 * $itemSize * $itemMarginFactorX, $itemSize * $itemMarginFactorY);
$quad = new Quad(); $quad = new Quad();
$popoutFrame->add($quad); $popoutFrame->add($quad);
$quad->setHAlign(Control::RIGHT); $quad->setHAlign(Control::RIGHT);
$quad->setStyles($quadStyle, $quadSubstyle); $quad->setStyles($quadStyle, $quadSubstyle);
$quad->setSize(strlen($values) * 2 + count($valueArray) * 1, $itemSize * $itemMarginFactorY); $quad->setSize(strlen($values) * 2 + count($valueArray) * 1, $itemSize * $itemMarginFactorY);
$popoutFrame->add($quad); $popoutFrame->add($quad);
$script->addTooltip($itemQuad, $popoutFrame, Script::OPTION_TOOLTIP_STAYONCLICK); $script->addTooltip($itemQuad, $popoutFrame, Script::OPTION_TOOLTIP_ONCLICK);
//Description Label // Description Label
$descriptionFrame = new Frame(); $descriptionFrame = new Frame();
$maniaLink->add($descriptionFrame); $maniaLink->add($descriptionFrame);
$descriptionFrame->setPosition($posX - 50, $posY - 5); $descriptionFrame->setPosition($posX - 50, $posY - 5);
$descriptionFrame->setHAlign(Control::RIGHT); $descriptionFrame->setHAlign(Control::RIGHT);
$descriptionLabel = new Label(); $descriptionLabel = new Label();
$descriptionFrame->add($descriptionLabel); $descriptionFrame->add($descriptionLabel);
$descriptionLabel->setAlign(Control::LEFT, Control::TOP); $descriptionLabel->setAlign(Control::LEFT, Control::TOP);
@ -250,24 +245,23 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
$descriptionLabel->setTextSize(2); $descriptionLabel->setTextSize(2);
$descriptionLabel->setVisible(true); $descriptionLabel->setVisible(true);
$descriptionLabel->setTextColor("0F0"); $descriptionLabel->setTextColor("0F0");
// Add items // Add items
$x = -2; $x = -2;
foreach(array_reverse($valueArray) as $value) { foreach (array_reverse($valueArray) as $value) {
$label = new Label_Button(); $label = new Label_Button();
$popoutFrame->add($label); $popoutFrame->add($label);
$label->setX($x); $label->setX($x);
$label->setHAlign(Control::RIGHT); $label->setHAlign(Control::RIGHT);
$label->setText('$s$FFF'.$value . '$09FP'); $label->setText('$s$FFF' . $value . '$09FP');
$label->setTextSize(1.2); $label->setTextSize(1.2);
$label->setAction(self::ACTION_DONATE_VALUE . "." . $value); $label->setAction(self::ACTION_DONATE_VALUE . "." . $value);
$label->setStyle(Label_Text::STYLE_TextCardSmall); $label->setStyle(Label_Text::STYLE_TextCardSmall);
$script->addTooltip($label, $descriptionLabel, array(Script::OPTION_TOOLTIP_TEXT => "Donate " . $value . " Planets")); $script->addTooltip($label, $descriptionLabel, array(Script::OPTION_TOOLTIP_TEXT => "Donate " . $value . " Planets"));
$x -= strlen($value) * 2 + 1.7; $x -= strlen($value) * 2 + 1.7;
} }
// Send manialink // Send manialink
$manialinkText = $maniaLink->render()->saveXML(); $manialinkText = $maniaLink->render()->saveXML();
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $login); $this->maniaControl->manialinkManager->sendManialink($manialinkText, $login);
@ -276,32 +270,32 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
/** /**
* Handle /donate command * Handle /donate command
* *
* @param array $chatCallback * @param array $chatCallback
* @param Player $player * @param Player $player
* @return bool * @return bool
*/ */
public function command_Donate(array $chatCallback, Player $player) { public function command_Donate(array $chatCallback, Player $player) {
$text = $chatCallback[1][2]; $text = $chatCallback[1][2];
$params = explode(' ', $text); $params = explode(' ', $text);
if(count($params) < 2) { if (count($params) < 2) {
$this->sendDonateUsageExample($player); $this->sendDonateUsageExample($player);
return false; return false;
} }
$amount = (int)$params[1]; $amount = (int) $params[1];
if(!$amount || $amount <= 0) { if (!$amount || $amount <= 0) {
$this->sendDonateUsageExample($player); $this->sendDonateUsageExample($player);
return false; return false;
} }
if(count($params) >= 3) { if (count($params) >= 3) {
$receiver = $params[2]; $receiver = $params[2];
$receiverPlayer = $this->maniaControl->playerManager->getPlayer($receiver); $receiverPlayer = $this->maniaControl->playerManager->getPlayer($receiver);
$receiverName = ($receiverPlayer ? $receiverPlayer['NickName'] : $receiver); $receiverName = ($receiverPlayer ? $receiverPlayer['NickName'] : $receiver);
}
} else { else {
$receiver = ''; $receiver = '';
$receiverName = $this->maniaControl->server->getName(); $receiverName = $this->maniaControl->server->getName();
} }
return $this->handleDonation($player, $amount, $receiver, $receiverName); return $this->handleDonation($player, $amount, $receiver, $receiverName);
} }
@ -309,60 +303,64 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
* Handles a Player Donate * Handles a Player Donate
* *
* @param Player $player * @param Player $player
* @param $value * @param $value
*/ */
private function handleDonation(Player $player, $amount, $receiver = '', $receiverName = false) { private function handleDonation(Player $player, $amount, $receiver = '', $receiverName = false) {
if(!$receiverName) { if (!$receiverName) {
$receiverName = $this->maniaControl->server->getName(); $receiverName = $this->maniaControl->server->getName();
} }
$message = 'Donate ' . $amount . ' Planets to $<' . $receiverName . '$>?'; $message = 'Donate ' . $amount . ' Planets to $<' . $receiverName . '$>?';
if(!$this->maniaControl->client->query('SendBill', $player->login, $amount, $message, $receiver)) { if (!$this->maniaControl->client->query('SendBill', $player->login, $amount, $message, $receiver)) {
trigger_error("Couldn't create donation of {$amount} planets from '{$player->login}' for '{$receiver}'. " . $this->maniaControl->getClientErrorText()); trigger_error(
"Couldn't create donation of {$amount} planets from '{$player->login}' for '{$receiver}'. " .
$this->maniaControl->getClientErrorText());
$this->maniaControl->chat->sendError("Creating donation failed.", $player->login); $this->maniaControl->chat->sendError("Creating donation failed.", $player->login);
return false; return false;
} }
$bill = $this->maniaControl->client->getResponse(); $bill = $this->maniaControl->client->getResponse();
$this->openBills[$bill] = array(true, $player->login, $receiver, $amount, time()); $this->openBills[$bill] = array(true, $player->login, $receiver, $amount, time());
return true; return true;
} }
/** /**
* Handle //pay command * Handle //pay command
* *
* @param array $chatCallback * @param array $chatCallback
* @param Player $player * @param Player $player
* @return bool * @return bool
*/ */
public function command_Pay(array $chatCallback, Player $player) { public function command_Pay(array $chatCallback, Player $player) {
if(!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_SUPERADMIN)) { if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_SUPERADMIN)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player); $this->maniaControl->authenticationManager->sendNotAllowed($player);
return false; return false;
} }
$text = $chatCallback[1][2]; $text = $chatCallback[1][2];
$params = explode(' ', $text); $params = explode(' ', $text);
if(count($params) < 2) { if (count($params) < 2) {
$this->sendPayUsageExample($player); $this->sendPayUsageExample($player);
return false; return false;
} }
$amount = (int)$params[1]; $amount = (int) $params[1];
if(!$amount || $amount <= 0) { if (!$amount || $amount <= 0) {
$this->sendPayUsageExample($player); $this->sendPayUsageExample($player);
return false; return false;
} }
if(count($params) >= 3) { if (count($params) >= 3) {
$receiver = $params[2]; $receiver = $params[2];
} else { }
else {
$receiver = $player->login; $receiver = $player->login;
} }
$message = 'Payout from $<' . $this->maniaControl->server->getName() . '$>.'; $message = 'Payout from $<' . $this->maniaControl->server->getName() . '$>.';
if(!$this->maniaControl->client->query('Pay', $receiver, $amount, $message)) { if (!$this->maniaControl->client->query('Pay', $receiver, $amount, $message)) {
trigger_error("Couldn't create payout of {$amount} planets by '{$player->login}' for '{$receiver}'. " . $this->maniaControl->getClientErrorText()); trigger_error(
"Couldn't create payout of {$amount} planets by '{$player->login}' for '{$receiver}'. " . $this->maniaControl->getClientErrorText());
$this->maniaControl->chat->sendError("Creating payout failed.", $player->login); $this->maniaControl->chat->sendError("Creating payout failed.", $player->login);
return false; return false;
} }
$bill = $this->maniaControl->client->getResponse(); $bill = $this->maniaControl->client->getResponse();
$this->openBills[$bill] = array(false, $player->login, $receiver, $amount, time()); $this->openBills[$bill] = array(false, $player->login, $receiver, $amount, time());
return true; return true;
} }
@ -370,16 +368,16 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
/** /**
* Handle //getplanets command * Handle //getplanets command
* *
* @param array $chatCallback * @param array $chatCallback
* @param Player $player * @param Player $player
* @return bool * @return bool
*/ */
public function command_GetPlanets(array $chatCallback, Player $player) { public function command_GetPlanets(array $chatCallback, Player $player) {
if(!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)) { if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player); $this->maniaControl->authenticationManager->sendNotAllowed($player);
return false; return false;
} }
if(!$this->maniaControl->client->query('GetServerPlanets')) { if (!$this->maniaControl->client->query('GetServerPlanets')) {
trigger_error("Couldn't retrieve server planets. " . $this->maniaControl->getClientErrorText()); trigger_error("Couldn't retrieve server planets. " . $this->maniaControl->getClientErrorText());
return false; return false;
} }
@ -396,59 +394,63 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
*/ */
public function handleBillUpdated(array $callback) { public function handleBillUpdated(array $callback) {
$billId = $callback[1][0]; $billId = $callback[1][0];
if(!array_key_exists($billId, $this->openBills)) { if (!array_key_exists($billId, $this->openBills)) {
return false; return false;
} }
$billData = $this->openBills[$billId]; $billData = $this->openBills[$billId];
$login = $billData[1]; $login = $billData[1];
$receiver = $billData[2]; $receiver = $billData[2];
switch($callback[1][1]) { switch ($callback[1][1]) {
case 4: case 4:
{ {
// Payed // Payed
$donation = $billData[0]; $donation = $billData[0];
$amount = $billData[3]; $amount = $billData[3];
if($donation) { if ($donation) {
$player = $this->maniaControl->playerManager->getPlayer($login); $player = $this->maniaControl->playerManager->getPlayer($login);
// Donation // Donation
if(strlen($receiver) > 0) { if (strlen($receiver) > 0) {
// To player // To player
$message = "Successfully donated {$amount} to '{$receiver}'!"; $message = "Successfully donated {$amount} to '{$receiver}'!";
$this->maniaControl->chat->sendSuccess($message, $login); $this->maniaControl->chat->sendSuccess($message, $login);
} else { }
// To server else {
if($this->maniaControl->settingManager->getSetting($this, self::SETTING_ANNOUNCE_SERVERDONATION, true)) { // To server
$message = '$<' . $player->nickname . '$> donated ' . $amount . ' Planets! Thanks.'; if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_ANNOUNCE_SERVERDONATION, true)) {
} else { $message = '$<' . $player->nickname . '$> donated ' . $amount . ' Planets! Thanks.';
$message = 'Donation successful! Thanks.'; }
else {
$message = 'Donation successful! Thanks.';
}
$this->maniaControl->chat->sendSuccess($message, $login);
$this->maniaControl->statisticManager->insertStat(self::STAT_PLAYER_DONATIONS, $player,
$this->maniaControl->server->getServerId(), $amount);
} }
$this->maniaControl->chat->sendSuccess($message, $login);
$this->maniaControl->statisticManager->insertStat(self::STAT_PLAYER_DONATIONS, $player, $this->maniaControl->server->getServerId(), $amount);
} }
} else { else {
// Payout // Payout
$message = "Successfully payed out {$amount} to '{$receiver}'!"; $message = "Successfully payed out {$amount} to '{$receiver}'!";
$this->maniaControl->chat->sendSuccess($message, $login); $this->maniaControl->chat->sendSuccess($message, $login);
}
unset($this->openBills[$billId]);
break;
} }
unset($this->openBills[$billId]);
break;
}
case 5: case 5:
{ {
// Refused // Refused
$message = 'Transaction cancelled.'; $message = 'Transaction cancelled.';
$this->maniaControl->chat->sendError($message, $login); $this->maniaControl->chat->sendError($message, $login);
unset($this->openBills[$billId]); unset($this->openBills[$billId]);
break; break;
} }
case 6: case 6:
{ {
// Error // Error
$this->maniaControl->chat->sendError($callback[1][2], $login); $this->maniaControl->chat->sendError($callback[1][2], $login);
unset($this->openBills[$billId]); unset($this->openBills[$billId]);
break; break;
} }
} }
return true; return true;
} }