2014-05-03 21:57:38 +02:00
< ? php
namespace MCTeam ;
use FML\Controls\Frame ;
use FML\Controls\Label ;
use FML\Controls\Labels\Label_Text ;
use FML\Controls\Quad ;
2014-07-04 18:29:30 +02:00
use FML\Controls\Quads\Quad_BgRaceScore2 ;
2014-05-03 21:57:38 +02:00
use FML\Controls\Quads\Quad_BgsPlayerCard ;
use FML\ManiaLink ;
use FML\Script\Features\Paging ;
2017-05-07 20:22:59 +02:00
use ManiaControl\Admin\ActionsMenu ;
2014-05-03 21:57:38 +02:00
use ManiaControl\Admin\AuthenticationManager ;
use ManiaControl\Bills\BillManager ;
use ManiaControl\Callbacks\CallbackListener ;
use ManiaControl\Callbacks\CallbackManager ;
use ManiaControl\Commands\CommandListener ;
use ManiaControl\ManiaControl ;
2017-05-08 19:58:48 +02:00
use ManiaControl\Manialinks\LabelLine ;
2014-05-03 21:57:38 +02:00
use ManiaControl\Manialinks\ManialinkManager ;
2017-05-11 22:35:16 +02:00
use ManiaControl\Manialinks\SidebarMenuEntryRenderable ;
2017-05-11 20:02:28 +02:00
use ManiaControl\Manialinks\SidebarMenuManager ;
2014-05-03 21:57:38 +02:00
use ManiaControl\Players\Player ;
use ManiaControl\Players\PlayerManager ;
use ManiaControl\Plugins\Plugin ;
/**
* ManiaControl Donation Plugin
*
2014-05-03 23:49:58 +02:00
* @ author ManiaControl Team < mail @ maniacontrol . com >
2017-02-04 11:49:23 +01:00
* @ copyright 2014 - 2017 ManiaControl Team
2014-05-03 23:49:58 +02:00
* @ license http :// www . gnu . org / licenses / GNU General Public License , Version 3
2014-05-03 21:57:38 +02:00
*/
2017-05-11 22:35:16 +02:00
class DonationPlugin implements CallbackListener , CommandListener , Plugin , SidebarMenuEntryRenderable {
2014-05-03 23:49:58 +02:00
/*
2014-05-03 21:57:38 +02:00
* Constants
*/
2014-06-17 23:35:56 +02:00
const ID = 3 ;
const VERSION = 0.1 ;
const AUTHOR = 'MCTeam' ;
const NAME = 'Donation Plugin' ;
const SETTING_ANNOUNCE_SERVER_DONATION = 'Enable Server-Donation Announcements' ;
const STAT_PLAYER_DONATIONS = 'Donated Planets' ;
const ACTION_DONATE_VALUE = 'Donate.DonateValue' ;
2017-05-11 20:02:28 +02:00
const DONATIONPLUGIN_MENU_ID = 'DonationPlugin.MenuId' ;
2014-05-03 21:57:38 +02:00
// DonateWidget Properties
const MLID_DONATE_WIDGET = 'DonationPlugin.DonateWidget' ;
const SETTING_DONATE_WIDGET_ACTIVATED = 'Donate-Widget Activated' ;
const SETTING_DONATION_VALUES = 'Donation Values' ;
const SETTING_MIN_AMOUNT_SHOWN = 'Minimum Donation amount to get shown' ;
2014-05-03 23:49:58 +02:00
/*
2014-08-02 22:31:46 +02:00
* Private properties
2014-05-03 21:57:38 +02:00
*/
2014-05-07 22:59:09 +02:00
/** @var ManiaControl $maniaControl */
2014-05-03 21:57:38 +02:00
private $maniaControl = null ;
/**
2014-05-03 23:49:58 +02:00
* @ see \ManiaControl\Plugins\Plugin :: prepare ()
2014-05-03 21:57:38 +02:00
*/
public static function prepare ( ManiaControl $maniaControl ) {
}
2014-05-03 23:49:58 +02:00
/**
* @ see \ManiaControl\Plugins\Plugin :: getId ()
*/
public static function getId () {
return self :: ID ;
}
/**
* @ see \ManiaControl\Plugins\Plugin :: getName ()
*/
public static function getName () {
return self :: NAME ;
}
/**
* @ see \ManiaControl\Plugins\Plugin :: getVersion ()
*/
public static function getVersion () {
return self :: VERSION ;
}
/**
* @ see \ManiaControl\Plugins\Plugin :: getAuthor ()
*/
public static function getAuthor () {
return self :: AUTHOR ;
}
/**
* @ see \ManiaControl\Plugins\Plugin :: getDescription ()
*/
public static function getDescription () {
2014-05-07 22:59:09 +02:00
return 'Plugin offering Commands like /donate, /pay and /planets and a Donation Widget.' ;
2014-05-03 23:49:58 +02:00
}
2014-05-03 21:57:38 +02:00
/**
* @ see \ManiaControl\Plugins\Plugin :: load ()
*/
public function load ( ManiaControl $maniaControl ) {
$this -> maniaControl = $maniaControl ;
// Register for commands
2014-08-13 11:14:29 +02:00
$this -> maniaControl -> getCommandManager () -> registerCommandListener ( 'donate' , $this , 'command_Donate' , false , 'Donate some planets to the server.' );
$this -> maniaControl -> getCommandManager () -> registerCommandListener ( 'pay' , $this , 'command_Pay' , true , 'Pays planets from the server to a player.' );
$this -> maniaControl -> getCommandManager () -> registerCommandListener ( array ( 'getplanets' , 'planets' ), $this , 'command_GetPlanets' , true , 'Checks the planets-balance of the server.' );
$this -> maniaControl -> getCommandManager () -> registerCommandListener ( 'topdons' , $this , 'command_TopDons' , false , 'Provides an overview of who donated the most planets.' );
2014-05-03 21:57:38 +02:00
// Register for callbacks
2014-08-13 11:14:29 +02:00
$this -> maniaControl -> getCallbackManager () -> registerCallbackListener ( PlayerManager :: CB_PLAYERCONNECT , $this , 'handlePlayerConnect' );
$this -> maniaControl -> getCallbackManager () -> registerCallbackListener ( CallbackManager :: CB_MP_PLAYERMANIALINKPAGEANSWER , $this , 'handleManialinkPageAnswer' );
2014-05-03 21:57:38 +02:00
// Define player stats
2014-08-13 11:14:29 +02:00
$this -> maniaControl -> getStatisticManager () -> defineStatMetaData ( self :: STAT_PLAYER_DONATIONS );
2017-05-11 22:35:16 +02:00
$this -> maniaControl -> getManialinkManager () -> getSidebarMenuManager () -> addMenuEntry ( $this , SidebarMenuManager :: ORDER_PLAYER_MENU , self :: DONATIONPLUGIN_MENU_ID );
2017-05-07 20:22:59 +02:00
2014-08-13 11:14:29 +02:00
$this -> maniaControl -> getSettingManager () -> initSetting ( $this , self :: SETTING_DONATE_WIDGET_ACTIVATED , true );
$this -> maniaControl -> getSettingManager () -> initSetting ( $this , self :: SETTING_DONATION_VALUES , " 20,50,100,500,1000,2000 " );
$this -> maniaControl -> getSettingManager () -> initSetting ( $this , self :: SETTING_MIN_AMOUNT_SHOWN , 100 );
2014-05-03 21:57:38 +02:00
// Register Stat in Simple StatsList
2014-08-13 11:14:29 +02:00
$this -> maniaControl -> getStatisticManager () -> getSimpleStatsList () -> registerStat ( self :: STAT_PLAYER_DONATIONS , 90 , " DP " , 15 );
2014-05-03 21:57:38 +02:00
$this -> displayWidget ();
return true ;
}
/**
2014-05-07 22:59:09 +02:00
* Display the widget
2014-05-03 21:57:38 +02:00
*/
public function displayWidget () {
2017-03-28 16:44:41 +02:00
if ( $this -> maniaControl -> getSettingManager () -> getSettingValue ( $this , self :: SETTING_DONATE_WIDGET_ACTIVATED )) {
2014-05-03 21:57:38 +02:00
$this -> displayDonateWidget ();
}
}
/**
2014-05-09 17:31:29 +02:00
* Display the Donation Widget
2014-05-03 21:57:38 +02:00
*
2014-05-07 22:59:09 +02:00
* @ param string $login
2014-05-03 21:57:38 +02:00
*/
2014-05-09 17:31:29 +02:00
public function displayDonateWidget ( $login = null ) {
2017-05-11 20:02:28 +02:00
$pos = $this -> maniaControl -> getManialinkManager () -> getSidebarMenuManager () -> getEntryPosition ( self :: DONATIONPLUGIN_MENU_ID );
$itemSize = $this -> maniaControl -> getSettingManager () -> getSettingValue ( SidebarMenuManager :: class , SidebarMenuManager :: SETTING_MENU_ITEMSIZE );
2014-08-13 11:14:29 +02:00
$values = $this -> maniaControl -> getSettingManager () -> getSettingValue ( $this , self :: SETTING_DONATION_VALUES );
$quadStyle = $this -> maniaControl -> getManialinkManager () -> getStyleManager () -> getDefaultQuadStyle ();
$quadSubstyle = $this -> maniaControl -> getManialinkManager () -> getStyleManager () -> getDefaultQuadSubstyle ();
2014-05-03 21:57:38 +02:00
$itemMarginFactorX = 1.3 ;
$itemMarginFactorY = 1.2 ;
$maniaLink = new ManiaLink ( self :: MLID_DONATE_WIDGET );
// Donate Menu Icon Frame
$frame = new Frame ();
2017-03-25 19:15:50 +01:00
$maniaLink -> addChild ( $frame );
2017-05-11 20:02:28 +02:00
$frame -> setPosition ( $pos [ 'x' ], $pos [ 'y' ]);
2017-04-11 12:04:37 +02:00
$frame -> setZ ( ManialinkManager :: MAIN_MANIALINK_Z_VALUE );
2014-05-03 21:57:38 +02:00
$backgroundQuad = new Quad ();
2017-03-25 19:15:50 +01:00
$frame -> addChild ( $backgroundQuad );
2017-05-11 20:02:28 +02:00
$backgroundQuad -> setSize ( $itemSize * $itemMarginFactorX , $itemSize * $itemMarginFactorY );
2014-05-03 21:57:38 +02:00
$backgroundQuad -> setStyles ( $quadStyle , $quadSubstyle );
$iconFrame = new Frame ();
2017-03-25 19:15:50 +01:00
$frame -> addChild ( $iconFrame );
2014-05-03 21:57:38 +02:00
$iconFrame -> setSize ( $itemSize , $itemSize );
2014-07-04 18:29:30 +02:00
$itemQuad = new Quad_BgRaceScore2 ();
$itemQuad -> setSubStyle ( $itemQuad :: SUBSTYLE_Points );
2014-05-03 21:57:38 +02:00
$itemQuad -> setSize ( $itemSize , $itemSize );
2017-03-25 19:15:50 +01:00
$iconFrame -> addChild ( $itemQuad );
2014-05-03 21:57:38 +02:00
2014-06-22 19:02:18 +02:00
$valueArray = explode ( ',' , $values );
2014-05-03 21:57:38 +02:00
// Values Menu
$popoutFrame = new Frame ();
2017-04-11 12:04:37 +02:00
$frame -> addChild ( $popoutFrame );
2017-05-07 20:22:59 +02:00
$popoutFrame -> setPosition ( - $itemSize * 0.5 , 0 );
2017-03-25 19:15:50 +01:00
$popoutFrame -> setHorizontalAlign ( $popoutFrame :: RIGHT );
2014-05-03 21:57:38 +02:00
$popoutFrame -> setVisible ( false );
2014-05-03 23:49:58 +02:00
$itemQuad -> addToggleFeature ( $popoutFrame );
2014-05-03 21:57:38 +02:00
// Description Label
$descriptionFrame = new Frame ();
2017-04-11 12:04:37 +02:00
$frame -> addChild ( $descriptionFrame );
2017-03-25 19:15:50 +01:00
$descriptionFrame -> setHorizontalAlign ( $descriptionFrame :: RIGHT );
2014-05-03 21:57:38 +02:00
$descriptionLabel = new Label ();
2017-03-25 19:15:50 +01:00
$descriptionFrame -> addChild ( $descriptionLabel );
2017-03-29 21:08:58 +02:00
$descriptionLabel -> setAlign ( $descriptionLabel :: RIGHT , $descriptionLabel :: TOP );
2014-05-03 21:57:38 +02:00
$descriptionLabel -> setSize ( 40 , 4 );
2017-03-29 21:08:58 +02:00
$descriptionLabel -> setTextSize ( 1 );
2014-05-03 21:57:38 +02:00
$descriptionLabel -> setVisible ( true );
// Add items
2017-05-07 20:22:59 +02:00
$posX = - 2 ;
2014-05-03 23:49:58 +02:00
foreach ( array_reverse ( $valueArray ) as $value ) {
2014-06-22 19:02:18 +02:00
$label = new Label_Text ();
2017-03-25 19:15:50 +01:00
$popoutFrame -> addChild ( $label );
2014-06-14 15:48:27 +02:00
$label -> setX ( $posX );
2017-03-25 19:15:50 +01:00
$label -> setHorizontalAlign ( $label :: RIGHT );
2014-05-03 21:57:38 +02:00
$label -> setText ( '$s$FFF' . $value . '$09FP' );
$label -> setTextSize ( 1.2 );
$label -> setAction ( self :: ACTION_DONATE_VALUE . " . " . $value );
2014-06-22 19:02:18 +02:00
$label -> setStyle ( $label :: STYLE_TextCardSmall );
2014-05-03 23:49:58 +02:00
$description = " Donate { $value } Planets " ;
$label -> addTooltipLabelFeature ( $descriptionLabel , $description );
2014-05-03 21:57:38 +02:00
2017-04-03 22:06:06 +02:00
$posX -= strlen ( $value ) * 1.6 + 2.5 ;
2014-05-03 21:57:38 +02:00
}
2017-05-11 20:02:28 +02:00
$descriptionFrame -> setPosition ( $posX - $itemSize + $itemMarginFactorX , 0 );
2017-03-29 21:08:58 +02:00
2017-03-28 16:44:41 +02:00
//Popout background
$quad = new Quad ();
$popoutFrame -> addChild ( $quad );
$quad -> setHorizontalAlign ( $quad :: RIGHT );
$quad -> setStyles ( $quadStyle , $quadSubstyle );
$quad -> setSize (( 2 - $posX ), $itemSize * $itemMarginFactorY );
2014-05-03 21:57:38 +02:00
// Send manialink
2014-08-13 11:14:29 +02:00
$this -> maniaControl -> getManialinkManager () -> sendManialink ( $maniaLink , $login );
2014-05-03 21:57:38 +02:00
}
/**
2014-05-03 23:49:58 +02:00
* @ see \ManiaControl\Plugins\Plugin :: unload ()
*/
public function unload () {
2014-08-13 11:14:29 +02:00
$this -> maniaControl -> getManialinkManager () -> hideManialink ( self :: MLID_DONATE_WIDGET );
2017-05-11 22:35:16 +02:00
$this -> maniaControl -> getManialinkManager () -> getSidebarMenuManager () -> deleteMenuEntry ( $this , self :: DONATIONPLUGIN_MENU_ID , true );
2014-05-03 23:49:58 +02:00
}
/**
* Handle ManialinkPageAnswer Callback
2014-05-03 21:57:38 +02:00
*
2014-05-03 23:49:58 +02:00
* @ param array $callback
2014-05-03 21:57:38 +02:00
*/
2014-05-03 23:49:58 +02:00
public function handleManialinkPageAnswer ( array $callback ) {
$actionId = $callback [ 1 ][ 2 ];
$boolSetting = ( strpos ( $actionId , self :: ACTION_DONATE_VALUE ) === 0 );
if ( ! $boolSetting ) {
return ;
2014-05-03 21:57:38 +02:00
}
2014-05-03 23:49:58 +02:00
$login = $callback [ 1 ][ 1 ];
2014-08-13 11:14:29 +02:00
$player = $this -> maniaControl -> getPlayerManager () -> getPlayer ( $login );
2014-05-03 23:49:58 +02:00
$actionArray = explode ( " . " , $callback [ 1 ][ 2 ]);
$this -> handleDonation ( $player , intval ( $actionArray [ 2 ]));
2014-05-03 21:57:38 +02:00
}
/**
2014-05-09 17:31:29 +02:00
* Handle a Player Donation
2014-05-03 21:57:38 +02:00
*
* @ param Player $player
2014-05-09 17:31:29 +02:00
* @ param int $amount
* @ param string $receiver
* @ param string $receiverName
2014-05-03 21:57:38 +02:00
*/
2014-05-09 17:31:29 +02:00
private function handleDonation ( Player $player , $amount , $receiver = '' , $receiverName = null ) {
2014-07-20 00:12:28 +02:00
if ( $amount > 1000000 ) {
// Prevent too huge donation amounts that would cause xmlrpc parsing errors
$message = " You can only donate 1.000.000 Planets at a time! " ;
2014-08-13 11:14:29 +02:00
$this -> maniaControl -> getChat () -> sendError ( $message , $player );
2014-07-20 00:12:28 +02:00
return ;
}
2015-06-04 00:23:29 +02:00
//FIXME if you write "/donate 50 hallo" than comes Message: Donate to Hallo
2014-05-03 21:57:38 +02:00
if ( ! $receiverName ) {
2014-08-13 11:14:29 +02:00
$serverName = $this -> maniaControl -> getClient () -> getServerName ();
2014-05-03 21:57:38 +02:00
$message = 'Donate ' . $amount . ' Planets to $<' . $serverName . '$>?' ;
} else {
$message = 'Donate ' . $amount . ' Planets to $<' . $receiverName . '$>?' ;
}
//Send and Handle the Bill
2014-08-13 11:14:29 +02:00
$this -> maniaControl -> getBillManager () -> sendBill ( function ( $data , $status ) use ( & $player , $amount , $receiver ) {
2015-01-17 18:01:46 +01:00
switch ( $status ) {
case BillManager :: DONATED_TO_SERVER :
if ( $this -> maniaControl -> getSettingManager () -> getSettingValue ( $this , DonationPlugin :: SETTING_ANNOUNCE_SERVER_DONATION , true )
&& $amount >= $this -> maniaControl -> getSettingManager () -> getSettingValue ( $this , DonationPlugin :: SETTING_MIN_AMOUNT_SHOWN , true )
) {
$login = null ;
$message = $player -> getEscapedNickname () . ' donated ' . $amount . ' Planets! Thanks.' ;
} else {
$login = $player -> login ;
$message = 'Donation successful! Thanks.' ;
}
$this -> maniaControl -> getChat () -> sendSuccess ( $message , $login );
$this -> maniaControl -> getStatisticManager () -> insertStat ( DonationPlugin :: STAT_PLAYER_DONATIONS , $player , $this -> maniaControl -> getServer () -> index , $amount );
break ;
case BillManager :: DONATED_TO_RECEIVER :
$message = " Successfully donated { $amount } to ' { $receiver } '! " ;
$this -> maniaControl -> getChat () -> sendSuccess ( $message , $player );
break ;
case BillManager :: PLAYER_REFUSED_DONATION :
$message = 'Transaction cancelled.' ;
$this -> maniaControl -> getChat () -> sendError ( $message , $player );
break ;
case BillManager :: ERROR_WHILE_TRANSACTION :
$message = $data ;
$this -> maniaControl -> getChat () -> sendError ( $message , $player );
break ;
}
}, $player , $amount , $message );
2014-05-03 21:57:38 +02:00
}
2014-05-03 23:49:58 +02:00
/**
* Handle PlayerConnect callback
*
* @ param Player $player
*/
public function handlePlayerConnect ( Player $player ) {
// Display Map Widget
2017-03-28 16:44:41 +02:00
if ( $this -> maniaControl -> getSettingManager () -> getSettingValue ( $this , self :: SETTING_DONATE_WIDGET_ACTIVATED )) {
2014-05-03 23:49:58 +02:00
$this -> displayDonateWidget ( $player -> login );
}
}
/**
* Handle / donate command
*
* @ param array $chatCallback
* @ param Player $player
*/
public function command_Donate ( array $chatCallback , Player $player ) {
$text = $chatCallback [ 1 ][ 2 ];
$params = explode ( ' ' , $text );
if ( count ( $params ) < 2 ) {
$this -> sendDonateUsageExample ( $player );
2014-05-07 22:59:09 +02:00
return ;
2014-05-03 23:49:58 +02:00
}
2015-01-17 18:01:46 +01:00
$amount = ( int ) $params [ 1 ];
2014-05-03 23:49:58 +02:00
if ( ! $amount || $amount <= 0 ) {
$this -> sendDonateUsageExample ( $player );
2014-05-07 22:59:09 +02:00
return ;
2014-05-03 23:49:58 +02:00
}
if ( count ( $params ) >= 3 ) {
$receiver = $params [ 2 ];
2014-08-13 11:14:29 +02:00
$receiverPlayer = $this -> maniaControl -> getPlayerManager () -> getPlayer ( $receiver );
2014-05-03 23:49:58 +02:00
$receiverName = ( $receiverPlayer ? $receiverPlayer -> nickname : $receiver );
} else {
$receiver = '' ;
2014-08-13 11:14:29 +02:00
$receiverName = $this -> maniaControl -> getClient () -> getServerName ();
2014-05-03 23:49:58 +02:00
}
2014-05-07 22:59:09 +02:00
$this -> handleDonation ( $player , $amount , $receiver , $receiverName );
2014-05-03 23:49:58 +02:00
}
/**
* Send an usage example for / donate to the player
*
* @ param Player $player
*/
private function sendDonateUsageExample ( Player $player ) {
$message = " Usage Example: '/donate 100' " ;
2014-08-13 11:14:29 +02:00
$this -> maniaControl -> getChat () -> sendChat ( $message , $player );
2014-05-03 23:49:58 +02:00
}
2014-05-03 21:57:38 +02:00
/**
* Handle //pay command
*
* @ param array $chatCallback
* @ param Player $player
*/
public function command_Pay ( array $chatCallback , Player $player ) {
2017-03-28 16:44:41 +02:00
if ( ! $this -> maniaControl -> getAuthenticationManager () -> checkRight ( $player , AuthenticationManager :: AUTH_LEVEL_SUPERADMIN )) {
2014-08-13 11:14:29 +02:00
$this -> maniaControl -> getAuthenticationManager () -> sendNotAllowed ( $player );
2014-05-07 22:59:09 +02:00
return ;
2014-05-03 21:57:38 +02:00
}
$text = $chatCallback [ 1 ][ 2 ];
$params = explode ( ' ' , $text );
if ( count ( $params ) < 2 ) {
$this -> sendPayUsageExample ( $player );
2014-05-07 22:59:09 +02:00
return ;
2014-05-03 21:57:38 +02:00
}
2015-01-17 18:01:46 +01:00
$amount = ( int ) $params [ 1 ];
2014-05-03 21:57:38 +02:00
if ( ! $amount || $amount <= 0 ) {
$this -> sendPayUsageExample ( $player );
2014-05-07 22:59:09 +02:00
return ;
2014-05-03 21:57:38 +02:00
}
if ( count ( $params ) >= 3 ) {
$receiver = $params [ 2 ];
} else {
$receiver = $player -> login ;
}
2014-08-13 11:14:29 +02:00
$message = 'Payout from $<' . $this -> maniaControl -> getClient () -> getServerName () . '$>.' ;
$this -> maniaControl -> getBillManager () -> sendPlanets ( function ( $data , $status ) use ( & $player , $amount , $receiver ) {
2015-01-17 18:01:46 +01:00
switch ( $status ) {
case BillManager :: PAYED_FROM_SERVER :
$message = " Successfully payed out { $amount } to ' { $receiver } '! " ;
$this -> maniaControl -> getChat () -> sendSuccess ( $message , $player );
break ;
case BillManager :: PLAYER_REFUSED_DONATION :
$message = 'Transaction cancelled.' ;
$this -> maniaControl -> getChat () -> sendError ( $message , $player );
break ;
case BillManager :: ERROR_WHILE_TRANSACTION :
$message = $data ;
$this -> maniaControl -> getChat () -> sendError ( $message , $player );
break ;
}
}, $receiver , $amount , $message );
2014-05-03 21:57:38 +02:00
}
2014-05-03 23:49:58 +02:00
/**
* Send an usage example for / pay to the player
*
* @ param Player $player
*/
private function sendPayUsageExample ( Player $player ) {
2014-05-24 21:53:07 +02:00
$message = " Usage Example: '//pay 100 login' " ;
2014-08-13 11:14:29 +02:00
$this -> maniaControl -> getChat () -> sendChat ( $message , $player );
2014-05-03 23:49:58 +02:00
}
2014-05-03 21:57:38 +02:00
/**
* Handle //getplanets command
*
* @ param array $chatCallback
* @ param Player $player
*/
public function command_GetPlanets ( array $chatCallback , Player $player ) {
2017-03-28 16:44:41 +02:00
if ( ! $this -> maniaControl -> getAuthenticationManager () -> checkRight ( $player , AuthenticationManager :: AUTH_LEVEL_ADMIN )) {
2014-08-13 11:14:29 +02:00
$this -> maniaControl -> getAuthenticationManager () -> sendNotAllowed ( $player );
2014-05-07 22:59:09 +02:00
return ;
2014-05-03 21:57:38 +02:00
}
2014-08-13 11:14:29 +02:00
$planets = $this -> maniaControl -> getClient () -> getServerPlanets ();
2014-05-03 21:57:38 +02:00
$message = " This Server has { $planets } Planets! " ;
2014-08-13 11:14:29 +02:00
$this -> maniaControl -> getChat () -> sendInformation ( $message , $player );
2014-05-03 21:57:38 +02:00
}
/**
* Handles the / topdons command
*
* @ param array $chatCallback
* @ param Player $player
*/
public function command_TopDons ( array $chatCallback , Player $player ) {
$this -> showTopDonsList ( $player );
}
/**
2014-05-13 18:26:38 +02:00
* Provide an Overview ManiaLink with Donators
2014-05-03 21:57:38 +02:00
*
* @ param Player $player
*/
private function showTopDonsList ( Player $player ) {
2014-08-13 11:14:29 +02:00
$stats = $this -> maniaControl -> getStatisticManager () -> getStatsRanking ( self :: STAT_PLAYER_DONATIONS );
2014-05-03 21:57:38 +02:00
2014-08-13 11:14:29 +02:00
$width = $this -> maniaControl -> getManialinkManager () -> getStyleManager () -> getListWidgetsWidth ();
$height = $this -> maniaControl -> getManialinkManager () -> getStyleManager () -> getListWidgetsHeight ();
2014-05-03 21:57:38 +02:00
// create manialink
$maniaLink = new ManiaLink ( ManialinkManager :: MAIN_MLID );
2014-05-03 23:49:58 +02:00
$script = $maniaLink -> getScript ();
$paging = new Paging ();
2014-05-03 21:57:38 +02:00
$script -> addFeature ( $paging );
// Main frame
2014-08-13 11:14:29 +02:00
$frame = $this -> maniaControl -> getManialinkManager () -> getStyleManager () -> getDefaultListFrame ( $script , $paging );
2017-03-25 19:15:50 +01:00
$maniaLink -> addChild ( $frame );
2014-05-03 21:57:38 +02:00
// Start offsets
2014-06-14 15:48:27 +02:00
$posX = - $width / 2 ;
$posY = $height / 2 ;
2014-05-03 21:57:38 +02:00
//Predefine description Label
2014-08-13 11:14:29 +02:00
$descriptionLabel = $this -> maniaControl -> getManialinkManager () -> getStyleManager () -> getDefaultDescriptionLabel ();
2017-03-25 19:15:50 +01:00
$frame -> addChild ( $descriptionLabel );
2014-05-03 21:57:38 +02:00
// Headline
$headFrame = new Frame ();
2017-03-25 19:15:50 +01:00
$frame -> addChild ( $headFrame );
2014-06-14 15:48:27 +02:00
$headFrame -> setY ( $posY - 5 );
2017-05-08 19:58:48 +02:00
$labelLine = new LabelLine ( $headFrame );
$labelLine -> setPrefix ( '$o' );
2017-05-11 20:02:28 +02:00
$labelLine -> addLabelEntryText ( 'Id' , $posX + 5 );
2017-05-08 19:58:48 +02:00
$labelLine -> addLabelEntryText ( 'Nickname' , $posX + 18 );
2017-05-11 20:02:28 +02:00
$labelLine -> addLabelEntryText ( 'Login' , $posX + 70 );
2017-05-08 19:58:48 +02:00
$labelLine -> addLabelEntryText ( 'Donated planets' , $posX + 110 );
$labelLine -> render ();
2014-05-03 21:57:38 +02:00
2014-06-14 15:48:27 +02:00
$index = 1 ;
$posY = $posY - 10 ;
2014-05-15 17:45:08 +02:00
$pageFrame = null ;
2014-05-03 23:49:58 +02:00
foreach ( $stats as $playerIndex => $donations ) {
2014-06-14 15:48:27 +02:00
if ( $index % 15 === 1 ) {
2014-05-03 21:57:38 +02:00
$pageFrame = new Frame ();
2017-03-25 19:15:50 +01:00
$frame -> addChild ( $pageFrame );
2014-06-14 15:48:27 +02:00
$posY = $height / 2 - 10 ;
2017-05-08 19:58:48 +02:00
$paging -> addPageControl ( $pageFrame );
2014-05-03 21:57:38 +02:00
}
$playerFrame = new Frame ();
2017-03-25 19:15:50 +01:00
$pageFrame -> addChild ( $playerFrame );
2014-06-14 15:48:27 +02:00
$playerFrame -> setY ( $posY );
2014-05-03 21:57:38 +02:00
2014-06-14 15:48:27 +02:00
if ( $index % 2 !== 0 ) {
2014-05-03 21:57:38 +02:00
$lineQuad = new Quad_BgsPlayerCard ();
2017-03-25 19:15:50 +01:00
$playerFrame -> addChild ( $lineQuad );
2014-05-03 21:57:38 +02:00
$lineQuad -> setSize ( $width , 4 );
$lineQuad -> setSubStyle ( $lineQuad :: SUBSTYLE_BgPlayerCardBig );
2017-05-08 19:58:48 +02:00
$lineQuad -> setZ ( - 0.001 );
2014-05-03 21:57:38 +02:00
}
2014-08-13 11:14:29 +02:00
$donatingPlayer = $this -> maniaControl -> getPlayerManager () -> getPlayerByIndex ( $playerIndex );
2015-06-04 00:23:29 +02:00
2017-05-08 19:58:48 +02:00
$labelLine = new LabelLine ( $playerFrame );
$labelLine -> addLabelEntryText ( $index , $posX + 5 , 13 );
2017-05-11 20:02:28 +02:00
$labelLine -> addLabelEntryText ( $donatingPlayer -> nickname , $posX + 18 , 52 );
$labelLine -> addLabelEntryText ( $donatingPlayer -> login , $posX + 70 , 40 );
$labelLine -> addLabelEntryText ( $donations , $posX + 110 , $width / 2 - ( $posX + 110 ));
2017-05-08 19:58:48 +02:00
$labelLine -> render ();
2014-05-03 21:57:38 +02:00
2014-06-14 15:48:27 +02:00
$posY -= 4 ;
$index ++ ;
2014-05-03 21:57:38 +02:00
2014-06-14 15:48:27 +02:00
if ( $index > 100 ) {
2014-05-03 21:57:38 +02:00
break ;
}
}
// Render and display xml
2014-08-13 11:14:29 +02:00
$this -> maniaControl -> getManialinkManager () -> displayWidget ( $maniaLink , $player , 'TopDons' );
2014-05-03 21:57:38 +02:00
}
2017-05-11 22:35:16 +02:00
public function renderMenuIcon () {
$this -> displayDonateWidget ();
}
2014-05-03 21:57:38 +02:00
}