donation minval setting

This commit is contained in:
kremsy 2014-01-08 20:20:18 +01:00
parent bddcea8d2d
commit 9d930ac85b

View File

@ -40,6 +40,7 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
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';
const SETTING_MIN_AMOUNT_SHOWN = 'Minimum Donation amount to get shown';
/** /**
* Private properties * Private properties
@ -67,8 +68,7 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
$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, $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
'handleManialinkPageAnswer');
// Define player stats // Define player stats
$this->maniaControl->statisticManager->defineStatMetaData(self::STAT_PLAYER_DONATIONS); $this->maniaControl->statisticManager->defineStatMetaData(self::STAT_PLAYER_DONATIONS);
@ -79,6 +79,7 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
$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");
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MIN_AMOUNT_SHOWN, 100);
return true; return true;
} }
@ -152,7 +153,9 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
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) return; if(!$boolSetting) {
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]);
@ -289,8 +292,7 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
$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();
} }
@ -311,9 +313,7 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
$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( trigger_error("Couldn't create donation of {$amount} planets from '{$player->login}' for '{$receiver}'. " . $this->maniaControl->getClientErrorText());
"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;
} }
@ -348,14 +348,12 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
} }
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( trigger_error("Couldn't create payout of {$amount} planets by '{$player->login}' for '{$receiver}'. " . $this->maniaControl->getClientErrorText());
"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;
} }
@ -413,20 +411,22 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
// 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 {
else {
// To server // To server
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_ANNOUNCE_SERVERDONATION, true)) { if($this->maniaControl->settingManager->getSetting($this, self::SETTING_ANNOUNCE_SERVERDONATION, true) && $amount >= $this->maniaControl->settingManager->getSetting($this, self::SETTING_MIN_AMOUNT_SHOWN, true)
) {
$login = null;
$message = '$<' . $player->nickname . '$> donated ' . $amount . ' Planets! Thanks.'; $message = '$<' . $player->nickname . '$> donated ' . $amount . ' Planets! Thanks.';
} } else {
else {
$message = 'Donation successful! Thanks.'; $message = 'Donation successful! Thanks.';
} }
$this->maniaControl->chat->sendSuccess($message, $login); $this->maniaControl->chat->sendSuccess($message, $login);
$this->maniaControl->statisticManager->insertStat(self::STAT_PLAYER_DONATIONS, $player, $this->maniaControl->server->index, $amount); $this->maniaControl->statisticManager->insertStat(self::STAT_PLAYER_DONATIONS, $player, $this->maniaControl->server->index, $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);