2013-11-12 16:52:23 +01:00
< ? php
namespace ManiaControl\Maps ;
2014-01-05 00:43:46 +01:00
use FML\Controls\Quad ;
2014-01-04 18:18:46 +01:00
use FML\Controls\Quads\Quad_Icons64x64_1 ;
2014-01-05 01:29:49 +01:00
use FML\Controls\Quads\Quad_UIConstruction_Buttons ;
2014-05-01 00:31:38 +02:00
use ManiaControl\Callbacks\CallbackManager ;
2014-01-05 00:43:46 +01:00
use ManiaControl\Callbacks\CallbackListener ;
2013-11-12 16:52:23 +01:00
use ManiaControl\Commands\CommandListener ;
2014-01-04 18:49:33 +01:00
use ManiaControl\ManiaControl ;
2014-01-05 00:43:46 +01:00
use ManiaControl\Manialinks\IconManager ;
2014-01-04 18:18:46 +01:00
use ManiaControl\Manialinks\ManialinkPageAnswerListener ;
2013-11-12 16:52:23 +01:00
use ManiaControl\Players\Player ;
2014-04-19 23:14:37 +02:00
use Maniaplanet\DedicatedServer\Xmlrpc\ChangeInProgressException ;
2014-04-27 01:47:51 +02:00
use Maniaplanet\DedicatedServer\Xmlrpc\FaultException ;
2013-11-12 16:52:23 +01:00
/**
2014-04-12 12:14:37 +02:00
* Class offering Commands to manage Maps
2013-11-12 16:52:23 +01:00
*
2014-04-19 23:14:37 +02:00
* @ author steeffeen & kremsy
2014-04-12 12:14:37 +02:00
* @ copyright ManiaControl Copyright © 2014 ManiaControl Team
2014-04-19 23:14:37 +02:00
* @ license http :// www . gnu . org / licenses / GNU General Public License , Version 3
2013-11-12 16:52:23 +01:00
*/
2014-01-05 13:32:59 +01:00
class MapCommands implements CommandListener , ManialinkPageAnswerListener , CallbackListener {
2014-04-12 12:14:37 +02:00
/*
2014-01-04 18:18:46 +01:00
* Constants
*/
2014-01-08 20:11:48 +01:00
const ACTION_OPEN_MAPLIST = 'MapCommands.OpenMapList' ;
const ACTION_OPEN_XLIST = 'MapCommands.OpenMXList' ;
const ACTION_RESTART_MAP = 'MapCommands.RestartMap' ;
const ACTION_SKIP_MAP = 'MapCommands.NextMap' ;
2014-05-01 00:31:38 +02:00
const ACTION_SHOW_AUTHOR = 'MapList.ShowAuthorList.' ;
2014-01-08 20:11:48 +01:00
2014-04-12 12:14:37 +02:00
/*
2014-01-06 18:50:26 +01:00
* Private Properties
2013-11-12 16:52:23 +01:00
*/
private $maniaControl = null ;
/**
* Create MapCommands instance
*
2014-01-04 18:49:33 +01:00
* @ param \ManiaControl\ManiaControl $maniaControl
2013-11-12 16:52:23 +01:00
*/
public function __construct ( ManiaControl $maniaControl ) {
$this -> maniaControl = $maniaControl ;
2014-01-05 13:32:59 +01:00
$this -> initActionsMenuButtons ();
2014-01-08 20:11:48 +01:00
2013-12-15 11:29:49 +01:00
// Register for admin chat commands
2014-04-19 00:16:19 +02:00
$this -> maniaControl -> commandManager -> registerCommandListener ( array ( 'nextmap' , 'next' , 'skip' ), $this , 'command_NextMap' , true );
$this -> maniaControl -> commandManager -> registerCommandListener ( array ( 'restartmap' , 'resmap' , 'res' ), $this , 'command_RestartMap' , true );
2014-04-27 00:55:39 +02:00
$this -> maniaControl -> commandManager -> registerCommandListener ( array ( 'replaymap' , 'replay' ), $this , 'command_ReplayMap' , true );
2014-04-19 00:16:19 +02:00
$this -> maniaControl -> commandManager -> registerCommandListener ( array ( 'addmap' , 'add' ), $this , 'command_AddMap' , true );
2014-01-10 12:32:11 +01:00
$this -> maniaControl -> commandManager -> registerCommandListener ( array ( 'removemap' , 'removethis' , 'erasemap' , 'erasethis' ), $this , 'command_RemoveMap' , true );
2014-01-11 17:06:32 +01:00
$this -> maniaControl -> commandManager -> registerCommandListener ( array ( 'shufflemaps' , 'shuffle' ), $this , 'command_ShuffleMaps' , true );
2014-04-27 01:47:51 +02:00
$this -> maniaControl -> commandManager -> registerCommandListener ( array ( 'writemaplist' , 'wml' ), $this , 'command_WriteMapList' , true );
$this -> maniaControl -> commandManager -> registerCommandListener ( array ( 'readmaplist' , 'rml' ), $this , 'command_ReadMapList' , true );
2014-01-08 20:11:48 +01:00
2013-12-15 11:29:49 +01:00
// Register for player chat commands
2014-01-14 20:35:31 +01:00
$this -> maniaControl -> commandManager -> registerCommandListener ( 'nextmap' , $this , 'command_showNextMap' );
2014-01-06 18:50:26 +01:00
$this -> maniaControl -> commandManager -> registerCommandListener ( array ( 'maps' , 'list' ), $this , 'command_List' );
$this -> maniaControl -> commandManager -> registerCommandListener ( array ( 'xmaps' , 'xlist' ), $this , 'command_xList' );
2014-01-08 20:11:48 +01:00
2014-01-05 13:32:59 +01:00
// Menu Buttons
2014-01-04 18:49:33 +01:00
$this -> maniaControl -> manialinkManager -> registerManialinkPageAnswerListener ( self :: ACTION_OPEN_XLIST , $this , 'command_xList' );
2014-01-05 00:43:46 +01:00
$this -> maniaControl -> manialinkManager -> registerManialinkPageAnswerListener ( self :: ACTION_OPEN_MAPLIST , $this , 'command_List' );
$this -> maniaControl -> manialinkManager -> registerManialinkPageAnswerListener ( self :: ACTION_RESTART_MAP , $this , 'command_RestartMap' );
$this -> maniaControl -> manialinkManager -> registerManialinkPageAnswerListener ( self :: ACTION_SKIP_MAP , $this , 'command_NextMap' );
2014-05-01 00:31:38 +02:00
$this -> maniaControl -> callbackManager -> registerCallbackListener ( CallbackManager :: CB_MP_PLAYERMANIALINKPAGEANSWER , $this , 'handleManialinkPageAnswer' );
2014-01-05 00:43:46 +01:00
}
/**
2014-01-05 13:32:59 +01:00
* Add all Actions Menu Buttons
2014-01-05 00:43:46 +01:00
*/
2014-01-05 13:32:59 +01:00
private function initActionsMenuButtons () {
// Menu Open xList
2014-01-05 00:43:46 +01:00
$itemQuad = new Quad ();
$itemQuad -> setImage ( $this -> maniaControl -> manialinkManager -> iconManager -> getIcon ( IconManager :: MX_ICON ));
2014-01-05 13:32:59 +01:00
$itemQuad -> setImageFocus ( $this -> maniaControl -> manialinkManager -> iconManager -> getIcon ( IconManager :: MX_ICON_MOVER ));
2014-01-04 18:49:33 +01:00
$itemQuad -> setAction ( self :: ACTION_OPEN_XLIST );
2014-01-05 13:32:59 +01:00
$this -> maniaControl -> actionsMenu -> addPlayerMenuItem ( $itemQuad , 5 , 'Open MX List' );
2014-01-08 20:11:48 +01:00
2014-01-05 13:32:59 +01:00
// Menu Open List
2014-01-04 18:18:46 +01:00
$itemQuad = new Quad_Icons64x64_1 ();
2014-01-05 01:29:49 +01:00
$itemQuad -> setSubStyle ( $itemQuad :: SUBSTYLE_ToolRoot );
2014-01-04 18:18:46 +01:00
$itemQuad -> setAction ( self :: ACTION_OPEN_MAPLIST );
2014-01-05 13:32:59 +01:00
$this -> maniaControl -> actionsMenu -> addPlayerMenuItem ( $itemQuad , 10 , 'Open MapList' );
2014-01-08 20:11:48 +01:00
2014-01-05 13:32:59 +01:00
// Menu RestartMap
2014-01-05 01:29:49 +01:00
$itemQuad = new Quad_UIConstruction_Buttons ();
$itemQuad -> setSubStyle ( $itemQuad :: SUBSTYLE_Reload );
2014-01-04 18:49:33 +01:00
$itemQuad -> setAction ( self :: ACTION_RESTART_MAP );
2014-01-31 20:12:01 +01:00
$this -> maniaControl -> actionsMenu -> addAdminMenuItem ( $itemQuad , 10 , 'Restart Map' );
2014-01-08 20:11:48 +01:00
2014-01-05 13:32:59 +01:00
// Menu NextMap
2014-01-04 18:49:33 +01:00
$itemQuad = new Quad_Icons64x64_1 ();
$itemQuad -> setSubStyle ( $itemQuad :: SUBSTYLE_ArrowFastNext );
$itemQuad -> setAction ( self :: ACTION_SKIP_MAP );
2014-01-31 20:12:01 +01:00
$this -> maniaControl -> actionsMenu -> addAdminMenuItem ( $itemQuad , 20 , 'Skip Map' );
2014-01-05 00:43:46 +01:00
}
2014-01-05 13:32:59 +01:00
2014-01-14 20:35:31 +01:00
/**
* Shows which map is the next
*
* @ param array $chat
* @ param Player $player
*/
public function command_ShowNextMap ( array $chat , Player $player ) {
$nextQueued = $this -> maniaControl -> mapManager -> mapQueue -> getNextQueuedMap ();
2014-03-31 21:41:05 +02:00
if ( $nextQueued ) {
2014-01-14 20:35:31 +01:00
/** @var Player $requester */
$requester = $nextQueued [ 0 ];
/** @var Map $map */
$map = $nextQueued [ 1 ];
$this -> maniaControl -> chat -> sendInformation ( " Next map is $ < " . $map -> name . " $ > from $ < " . $map -> authorNick . " $ > requested by $ < " . $requester -> nickname . " $ >. " , $player -> login );
} else {
2014-03-01 11:11:50 +01:00
$mapIndex = $this -> maniaControl -> client -> getNextMapIndex ();
$maps = $this -> maniaControl -> mapManager -> getMaps ();
$map = $maps [ $mapIndex ];
2014-01-14 20:35:31 +01:00
$this -> maniaControl -> chat -> sendInformation ( " Next map is $ < " . $map -> name . " $ > from $ < " . $map -> authorNick . " $ >. " , $player -> login );
}
}
2013-11-12 16:52:23 +01:00
/**
* Handle removemap command
*
2014-01-08 20:11:48 +01:00
* @ param array $chat
2014-01-04 18:49:33 +01:00
* @ param \ManiaControl\Players\Player $player
2013-11-12 16:52:23 +01:00
*/
public function command_RemoveMap ( array $chat , Player $player ) {
2014-01-28 16:54:23 +01:00
if ( ! $this -> maniaControl -> authenticationManager -> checkPermission ( $player , MapManager :: SETTING_PERMISSION_REMOVE_MAP )) {
2013-11-13 01:43:12 +01:00
$this -> maniaControl -> authenticationManager -> sendNotAllowed ( $player );
2013-12-15 09:00:30 +01:00
return ;
2013-11-12 16:52:23 +01:00
}
2013-11-27 02:42:39 +01:00
// Get map
$map = $this -> maniaControl -> mapManager -> getCurrentMap ();
2014-01-28 16:54:23 +01:00
if ( ! $map ) {
2013-11-12 16:52:23 +01:00
$this -> maniaControl -> chat -> sendError ( " Couldn't remove map. " , $player -> login );
2013-12-15 09:00:30 +01:00
return ;
2013-11-12 16:52:23 +01:00
}
2014-01-14 15:45:36 +01:00
2014-01-10 12:32:11 +01:00
//RemoveMap
$this -> maniaControl -> mapManager -> removeMap ( $player , $map -> uid );
2013-11-12 16:52:23 +01:00
}
/**
2014-03-31 21:04:15 +02:00
* Handle shufflemaps command
2013-11-12 16:52:23 +01:00
*
2014-01-08 20:11:48 +01:00
* @ param array $chatCallback
2014-01-04 18:49:33 +01:00
* @ param \ManiaControl\Players\Player $player
2014-01-11 16:34:05 +01:00
*/
public function command_ShuffleMaps ( array $chatCallback , Player $player ) {
2014-01-28 16:54:23 +01:00
if ( ! $this -> maniaControl -> authenticationManager -> checkPermission ( $player , MapManager :: SETTING_PERMISSION_SHUFFLE_MAPS )) {
2014-01-11 16:34:05 +01:00
$this -> maniaControl -> authenticationManager -> sendNotAllowed ( $player );
return ;
}
2014-01-11 16:36:34 +01:00
// Shuffles the maps
2014-01-14 15:45:36 +01:00
$this -> maniaControl -> mapManager -> shuffleMapList ( $player );
2014-01-11 16:34:05 +01:00
}
/**
* Handle addmap command
*
* @ param array $chatCallback
* @ param \ManiaControl\Players\Player $player
2013-11-12 16:52:23 +01:00
*/
2013-11-27 02:42:39 +01:00
public function command_AddMap ( array $chatCallback , Player $player ) {
2014-01-31 16:55:01 +01:00
if ( ! $this -> maniaControl -> authenticationManager -> checkPermission ( $player , MapManager :: SETTING_PERMISSION_ADD_MAP )) {
2013-11-13 01:43:12 +01:00
$this -> maniaControl -> authenticationManager -> sendNotAllowed ( $player );
2013-12-15 09:00:30 +01:00
return ;
2013-11-12 16:52:23 +01:00
}
2013-11-27 02:42:39 +01:00
$params = explode ( ' ' , $chatCallback [ 1 ][ 2 ], 2 );
2014-01-28 16:54:23 +01:00
if ( count ( $params ) < 2 ) {
2013-11-19 20:29:37 +01:00
$this -> maniaControl -> chat -> sendUsageInfo ( 'Usage example: //addmap 1234' , $player -> login );
2013-12-15 09:00:30 +01:00
return ;
2013-11-12 16:52:23 +01:00
}
2014-01-08 20:11:48 +01:00
2014-01-05 13:32:59 +01:00
// add Map from Mania Exchange
2014-01-04 18:49:33 +01:00
$this -> maniaControl -> mapManager -> addMapFromMx ( $params [ 1 ], $player -> login );
2013-11-12 16:52:23 +01:00
}
/**
2014-01-06 18:50:26 +01:00
* Handle / nextmap Command
2013-11-12 16:52:23 +01:00
*
2014-01-08 20:11:48 +01:00
* @ param array $chat
2014-01-04 18:49:33 +01:00
* @ param \ManiaControl\Players\Player $player
2013-11-12 16:52:23 +01:00
*/
public function command_NextMap ( array $chat , Player $player ) {
2014-01-31 16:55:01 +01:00
if ( ! $this -> maniaControl -> authenticationManager -> checkPermission ( $player , MapManager :: SETTING_PERMISSION_SKIP_MAP )) {
2013-11-13 01:43:12 +01:00
$this -> maniaControl -> authenticationManager -> sendNotAllowed ( $player );
2013-12-15 09:00:30 +01:00
return ;
2013-11-12 16:52:23 +01:00
}
2014-04-19 23:38:08 +02:00
try {
$this -> maniaControl -> client -> nextMap ();
} catch ( ChangeInProgressException $e ) {
}
2014-01-14 16:30:02 +01:00
$message = '$<' . $player -> nickname . '$> skipped the current Map!' ;
$this -> maniaControl -> chat -> sendSuccess ( $message );
$this -> maniaControl -> log ( $message , true );
2013-11-12 16:52:23 +01:00
}
/**
2013-12-15 09:00:30 +01:00
* Handle restartmap command
2013-11-12 16:52:23 +01:00
*
2014-01-08 20:11:48 +01:00
* @ param array $chat
2014-01-04 18:49:33 +01:00
* @ param \ManiaControl\Players\Player $player
2013-11-12 16:52:23 +01:00
*/
public function command_RestartMap ( array $chat , Player $player ) {
2014-01-31 16:55:01 +01:00
if ( ! $this -> maniaControl -> authenticationManager -> checkPermission ( $player , MapManager :: SETTING_PERMISSION_RESTART_MAP )) {
2013-11-13 01:43:12 +01:00
$this -> maniaControl -> authenticationManager -> sendNotAllowed ( $player );
2013-12-15 09:00:30 +01:00
return ;
2013-11-12 16:52:23 +01:00
}
2014-01-14 16:30:02 +01:00
$message = '$<' . $player -> nickname . '$> restarted the current Map!' ;
$this -> maniaControl -> chat -> sendSuccess ( $message );
$this -> maniaControl -> log ( $message , true );
2014-03-01 11:11:50 +01:00
2014-03-13 18:25:29 +01:00
try {
$this -> maniaControl -> client -> restartMap ();
2014-04-19 23:14:37 +02:00
} catch ( ChangeInProgressException $e ) {
2014-03-13 18:25:29 +01:00
}
2013-11-12 16:52:23 +01:00
}
2013-12-14 22:00:59 +01:00
2014-04-27 00:55:39 +02:00
////$this->maniaControl->mapManager->mapQueue->addFirstMapToMapQueue($this->currentVote->voter, $this->maniaControl->mapManager->getCurrentMap());
/**
* Handle replaymap command
*
* @ param array $chat
* @ param \ManiaControl\Players\Player $player
*/
public function command_ReplayMap ( array $chat , Player $player ) {
if ( ! $this -> maniaControl -> authenticationManager -> checkPermission ( $player , MapManager :: SETTING_PERMISSION_RESTART_MAP )) {
$this -> maniaControl -> authenticationManager -> sendNotAllowed ( $player );
return ;
}
$message = '$<' . $player -> nickname . '$> replays the current Map!' ;
$this -> maniaControl -> chat -> sendSuccess ( $message );
$this -> maniaControl -> log ( $message , true );
$this -> maniaControl -> mapManager -> mapQueue -> addFirstMapToMapQueue ( $player , $this -> maniaControl -> mapManager -> getCurrentMap ());
}
2014-04-27 01:47:51 +02:00
/**
* Handle writemaplist command
*
* @ param array $chat
* @ param \ManiaControl\Players\Player $player
*/
public function command_WriteMapList ( array $chat , Player $player ) {
if ( ! $this -> maniaControl -> authenticationManager -> checkRight ( $player , 3 )) {
$this -> maniaControl -> authenticationManager -> sendNotAllowed ( $player );
return ;
}
$chatCommand = explode ( ' ' , $chat [ 1 ][ 2 ]);
if ( isset ( $chatCommand [ 1 ])) {
if ( strstr ( $chatCommand [ 1 ], '.txt' )) {
$maplist = $chatCommand [ 1 ];
} else {
$maplist = $chatCommand . '.txt' ;
}
} else {
$maplist = 'maplist.txt' ;
}
$maplist = 'MatchSettings/' . $maplist ;
2014-04-27 01:48:54 +02:00
try {
$this -> maniaControl -> client -> saveMatchSettings ( $maplist );
2014-04-27 01:47:51 +02:00
2014-04-27 01:48:54 +02:00
$message = 'Maplist $<$fff' . $maplist . '$> written.' ;
$this -> maniaControl -> chat -> sendSuccess ( $message , $player );
$this -> maniaControl -> log ( $message , true );
} catch ( FaultException $e ) {
$this -> maniaControl -> chat -> sendError ( 'Cannot write maplist $<$fff' . $maplist . '$>!' , $player );
}
2014-04-27 01:47:51 +02:00
}
/**
* Handle readmaplist command
*
* @ param array $chat
* @ param \ManiaControl\Players\Player $player
*/
public function command_ReadMapList ( array $chat , Player $player ) {
if ( ! $this -> maniaControl -> authenticationManager -> checkRight ( $player , 3 )) {
$this -> maniaControl -> authenticationManager -> sendNotAllowed ( $player );
return ;
}
$chatCommand = explode ( ' ' , $chat [ 1 ][ 2 ]);
if ( isset ( $chatCommand [ 1 ])) {
if ( strstr ( $chatCommand [ 1 ], '.txt' )) {
$maplist = $chatCommand [ 1 ];
} else {
$maplist = $chatCommand [ 1 ] . '.txt' ;
}
} else {
$maplist = 'maplist.txt' ;
}
$maplist = 'MatchSettings/' . $maplist ;
try {
$this -> maniaControl -> client -> loadMatchSettings ( $maplist );
$message = 'Maplist $<$fff' . $maplist . '$> loaded.' ;
$this -> maniaControl -> mapManager -> restructureMapList ();
$this -> maniaControl -> chat -> sendSuccess ( $message , $player );
$this -> maniaControl -> log ( $message , true );
} catch ( FaultException $e ) {
$this -> maniaControl -> chat -> sendError ( 'Cannot load maplist $<$fff' . $maplist . '$>!' , $player );
}
}
2014-05-01 00:31:38 +02:00
public function handleManialinkPageAnswer ( array $callback ) {
$actionId = $callback [ 1 ][ 2 ];
$login = $callback [ 1 ][ 1 ];
$player = $this -> maniaControl -> playerManager -> getPlayer ( $login );
if ( strstr ( $actionId , self :: ACTION_SHOW_AUTHOR )) {
$login = str_replace ( self :: ACTION_SHOW_AUTHOR , '' , $actionId );
$this -> maniaControl -> mapManager -> mapList -> playerCloseWidget ( $player );
$this -> showMapListAuthor ( $login , $player );
}
}
2013-12-15 09:00:30 +01:00
/**
2014-01-06 18:50:26 +01:00
* Handle / maps command
2013-12-15 09:00:30 +01:00
*
2014-01-08 20:11:48 +01:00
* @ param array $chatCallback
2014-01-04 18:49:33 +01:00
* @ param Player $player
2013-12-15 09:00:30 +01:00
*/
public function command_List ( array $chatCallback , Player $player ) {
2014-04-29 15:20:20 +02:00
$chatCommands = explode ( ' ' , $chatCallback [ 1 ][ 2 ]);
$this -> maniaControl -> mapManager -> mapList -> playerCloseWidget ( $player );
if ( isset ( $chatCommands [ 1 ])) {
if ( $chatCommands [ 1 ] == ' ' || $chatCommands [ 1 ] == 'all' ) {
$this -> maniaControl -> mapManager -> mapList -> showMapList ( $player );
} elseif ( $chatCommands [ 1 ] == 'best' ) {
$this -> showMapListKarma ( true , $player );
} elseif ( $chatCommands [ 1 ] == 'worst' ) {
$this -> showMapListKarma ( false , $player );
} elseif ( $chatCommands [ 1 ] == 'newest' ) {
$this -> showMapListDate ( true , $player );
} elseif ( $chatCommands [ 1 ] == 'oldest' ) {
$this -> showMapListDate ( false , $player );
2014-04-30 19:18:37 +02:00
} elseif ( $chatCommands [ 1 ] == 'author' ) {
if ( isset ( $chatCommands [ 2 ])) {
$this -> showMaplistAuthor ( $chatCommands [ 2 ], $player );
} else {
$this -> maniaControl -> chat -> sendError ( 'There are no maps to show!' , $player -> login );
}
2014-04-29 15:20:20 +02:00
}
} else {
$this -> maniaControl -> mapManager -> mapList -> showMapList ( $player );
}
}
2014-04-30 19:18:37 +02:00
private function showMapListAuthor ( $author , $player ) {
$maps = $this -> maniaControl -> mapManager -> getMaps ();
$mapList = array ();
/** @var Map $map */
foreach ( $maps as $map ) {
if ( $map -> authorLogin == $author ) {
$mapList [] = $map ;
}
}
if ( count ( $mapList ) == 0 ) {
$this -> maniaControl -> chat -> sendError ( 'There are no maps to show!' , $player -> login );
return ;
}
$this -> maniaControl -> mapManager -> mapList -> showMapList ( $player , $mapList );
}
2014-04-29 15:20:20 +02:00
private function showMapListKarma ( $best , $player ) {
/** @var \MCTeam\KarmaPlugin $karmaPlugin */
$karmaPlugin = $this -> maniaControl -> pluginManager -> getPlugin ( MapList :: DEFAULT_KARMA_PLUGIN );
if ( $karmaPlugin ) {
$maps = $this -> maniaControl -> mapManager -> getMaps ();
$mapList = array ();
foreach ( $maps as $map ) {
if ( $map instanceof Map ) {
2014-04-30 14:45:56 +02:00
if ( $this -> maniaControl -> settingManager -> getSetting ( $karmaPlugin , $karmaPlugin :: SETTING_NEWKARMA ) === true ) {
$karma = $karmaPlugin -> getMapKarma ( $map );
$map -> karma = round ( $karma * 100. );
} else {
$votes = $karmaPlugin -> getMapVotes ( $map );
$min = 0 ;
$plus = 0 ;
foreach ( $votes as $vote ) {
if ( isset ( $vote -> vote )) {
if ( $vote -> vote != 0.5 ) {
if ( $vote -> vote < 0.5 ) {
$min = $min + $vote -> count ;
} else {
$plus = $plus + $vote -> count ;
}
2014-04-29 15:20:20 +02:00
}
}
}
2014-04-30 14:45:56 +02:00
$map -> karma = $plus - $min ;
2014-04-29 15:20:20 +02:00
}
$mapList [] = $map ;
}
}
usort ( $mapList , array ( $this , 'sortByKarma' ));
if ( $best ) {
$mapList = array_reverse ( $mapList );
}
$this -> maniaControl -> mapManager -> mapList -> showMapList ( $player , $mapList );
} else {
$this -> maniaControl -> chat -> sendError ( 'KarmaPlugin is not enabled!' , $player -> login );
}
}
private function sortByKarma ( $a , $b ) {
return $a -> karma - $b -> karma ;
}
private function showMapListDate ( $newest , $player ) {
$maps = $this -> maniaControl -> mapManager -> getMaps ();
usort ( $maps , function ( $a , $b ) {
return $a -> index - $b -> index ;
});
if ( $newest ) {
$maps = array_reverse ( $maps );
}
$this -> maniaControl -> mapManager -> mapList -> showMapList ( $player , $maps );
2013-12-14 22:00:59 +01:00
}
2013-12-15 11:29:49 +01:00
/**
* Handle ManiaExchange list command
2014-01-04 18:49:33 +01:00
*
2014-01-08 20:11:48 +01:00
* @ param array $chatCallback
2013-12-15 11:29:49 +01:00
* @ param Player $player
*/
public function command_xList ( array $chatCallback , Player $player ) {
2014-02-07 14:05:10 +01:00
$this -> maniaControl -> mapManager -> mxList -> showList ( $chatCallback , $player );
2013-12-15 11:29:49 +01:00
}
2013-11-12 16:52:23 +01:00
}