donation minval setting
This commit is contained in:
parent
bddcea8d2d
commit
9d930ac85b
@ -40,6 +40,7 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
|
||||
const SETTING_DONATE_WIDGET_WIDTH = 'Donate-Widget-Size: Width';
|
||||
const SETTING_DONATE_WIDGET_HEIGHT = 'Donate-Widget-Size: Height';
|
||||
const SETTING_DONATION_VALUES = 'Donation Values';
|
||||
const SETTING_MIN_AMOUNT_SHOWN = 'Minimum Donation amount to get shown';
|
||||
|
||||
/**
|
||||
* 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_MC_ONINIT, $this, 'handleOnInit');
|
||||
$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
|
||||
$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_HEIGHT, 6);
|
||||
$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;
|
||||
}
|
||||
@ -139,7 +140,7 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
|
||||
* @param 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();
|
||||
}
|
||||
}
|
||||
@ -152,7 +153,9 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
|
||||
public function handleManialinkPageAnswer(array $callback) {
|
||||
$actionId = $callback[1][2];
|
||||
$boolSetting = (strpos($actionId, self::ACTION_DONATE_VALUE) === 0);
|
||||
if (!$boolSetting) return;
|
||||
if(!$boolSetting) {
|
||||
return;
|
||||
}
|
||||
$login = $callback[1][1];
|
||||
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||
$actionArray = explode(".", $callback[1][2]);
|
||||
@ -167,7 +170,7 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
|
||||
public function handlePlayerConnect(array $callback) {
|
||||
$player = $callback[1];
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
@ -247,7 +250,7 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
|
||||
|
||||
// Add items
|
||||
$x = -2;
|
||||
foreach (array_reverse($valueArray) as $value) {
|
||||
foreach(array_reverse($valueArray) as $value) {
|
||||
$label = new Label_Button();
|
||||
$popoutFrame->add($label);
|
||||
$label->setX($x);
|
||||
@ -276,21 +279,20 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
|
||||
public function command_Donate(array $chatCallback, Player $player) {
|
||||
$text = $chatCallback[1][2];
|
||||
$params = explode(' ', $text);
|
||||
if (count($params) < 2) {
|
||||
if(count($params) < 2) {
|
||||
$this->sendDonateUsageExample($player);
|
||||
return false;
|
||||
}
|
||||
$amount = (int) $params[1];
|
||||
if (!$amount || $amount <= 0) {
|
||||
$amount = (int)$params[1];
|
||||
if(!$amount || $amount <= 0) {
|
||||
$this->sendDonateUsageExample($player);
|
||||
return false;
|
||||
}
|
||||
if (count($params) >= 3) {
|
||||
if(count($params) >= 3) {
|
||||
$receiver = $params[2];
|
||||
$receiverPlayer = $this->maniaControl->playerManager->getPlayer($receiver);
|
||||
$receiverName = ($receiverPlayer ? $receiverPlayer['NickName'] : $receiver);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$receiver = '';
|
||||
$receiverName = $this->maniaControl->server->getName();
|
||||
}
|
||||
@ -305,15 +307,13 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
|
||||
* @param $value
|
||||
*/
|
||||
private function handleDonation(Player $player, $amount, $receiver = '', $receiverName = false) {
|
||||
if (!$receiverName) {
|
||||
if(!$receiverName) {
|
||||
$receiverName = $this->maniaControl->server->getName();
|
||||
}
|
||||
|
||||
$message = 'Donate ' . $amount . ' Planets to $<' . $receiverName . '$>?';
|
||||
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());
|
||||
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());
|
||||
$this->maniaControl->chat->sendError("Creating donation failed.", $player->login);
|
||||
return false;
|
||||
}
|
||||
@ -331,31 +331,29 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
|
||||
* @return bool
|
||||
*/
|
||||
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);
|
||||
return false;
|
||||
}
|
||||
$text = $chatCallback[1][2];
|
||||
$params = explode(' ', $text);
|
||||
if (count($params) < 2) {
|
||||
if(count($params) < 2) {
|
||||
$this->sendPayUsageExample($player);
|
||||
return false;
|
||||
}
|
||||
$amount = (int) $params[1];
|
||||
if (!$amount || $amount <= 0) {
|
||||
$amount = (int)$params[1];
|
||||
if(!$amount || $amount <= 0) {
|
||||
$this->sendPayUsageExample($player);
|
||||
return false;
|
||||
}
|
||||
if (count($params) >= 3) {
|
||||
if(count($params) >= 3) {
|
||||
$receiver = $params[2];
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$receiver = $player->login;
|
||||
}
|
||||
$message = 'Payout from $<' . $this->maniaControl->server->getName() . '$>.';
|
||||
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());
|
||||
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());
|
||||
$this->maniaControl->chat->sendError("Creating payout failed.", $player->login);
|
||||
return false;
|
||||
}
|
||||
@ -372,11 +370,11 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
|
||||
* @return bool
|
||||
*/
|
||||
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);
|
||||
return false;
|
||||
}
|
||||
if (!$this->maniaControl->client->query('GetServerPlanets')) {
|
||||
if(!$this->maniaControl->client->query('GetServerPlanets')) {
|
||||
trigger_error("Couldn't retrieve server planets. " . $this->maniaControl->getClientErrorText());
|
||||
return false;
|
||||
}
|
||||
@ -393,40 +391,42 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
|
||||
*/
|
||||
public function handleBillUpdated(array $callback) {
|
||||
$billId = $callback[1][0];
|
||||
if (!array_key_exists($billId, $this->openBills)) {
|
||||
if(!array_key_exists($billId, $this->openBills)) {
|
||||
return false;
|
||||
}
|
||||
$billData = $this->openBills[$billId];
|
||||
$login = $billData[1];
|
||||
$receiver = $billData[2];
|
||||
switch ($callback[1][1]) {
|
||||
switch($callback[1][1]) {
|
||||
case 4:
|
||||
{
|
||||
// Payed
|
||||
$donation = $billData[0];
|
||||
$amount = $billData[3];
|
||||
if ($donation) {
|
||||
if($donation) {
|
||||
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||
|
||||
// Donation
|
||||
if (strlen($receiver) > 0) {
|
||||
if(strlen($receiver) > 0) {
|
||||
// To player
|
||||
$message = "Successfully donated {$amount} to '{$receiver}'!";
|
||||
$this->maniaControl->chat->sendSuccess($message, $login);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// 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.';
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
|
||||
$message = 'Donation successful! Thanks.';
|
||||
}
|
||||
|
||||
|
||||
$this->maniaControl->chat->sendSuccess($message, $login);
|
||||
$this->maniaControl->statisticManager->insertStat(self::STAT_PLAYER_DONATIONS, $player, $this->maniaControl->server->index, $amount);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Payout
|
||||
$message = "Successfully payed out {$amount} to '{$receiver}'!";
|
||||
$this->maniaControl->chat->sendSuccess($message, $login);
|
||||
|
Loading…
Reference in New Issue
Block a user