added method to playermanager

This commit is contained in:
kremsy 2014-01-16 00:24:24 +01:00 committed by Steffen Schröder
parent 02a60ac875
commit d8d52251c9

View File

@ -143,14 +143,12 @@ class PlayerManager implements CallbackListener {
if($this->maniaControl->settingManager->getSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES) && !$player->isFakePlayer()) {
$string = array(0 => '$0f0Player', 1 => '$0f0Moderator', 2 => '$0f0Admin', 3 => '$0f0MasterAdmin', 4 => '$0f0MasterAdmin');
$chatMessage = '$s$0f0' . $string[$player->authLevel] . ' $fff' . $player->nickname . '$z$s$0f0 Nation:$fff ' . $player->getCountry() .
' $z$s$0f0joined!';
$chatMessage = '$s$0f0' . $string[$player->authLevel] . ' $fff' . $player->nickname . '$z$s$0f0 Nation:$fff ' . $player->getCountry() . ' $z$s$0f0joined!';
$this->maniaControl->chat->sendChat($chatMessage);
$this->maniaControl->chat->sendInformation('This server uses ManiaControl v' . ManiaControl::VERSION . '!', $player->login);
}
$logMessage = "Player joined: {$player->login} / " . Formatter::stripCodes($player->nickname) . " Nation: " . $player->getCountry() .
" IP: {$player->ipAddress}";
$logMessage = "Player joined: {$player->login} / " . Formatter::stripCodes($player->nickname) . " Nation: " . $player->getCountry() . " IP: {$player->ipAddress}";
$this->maniaControl->log($logMessage);
// Trigger own PlayerJoined callback
@ -210,6 +208,24 @@ class PlayerManager implements CallbackListener {
return $this->players;
}
/**
* Gets a Player by his index
*
* @param $index
* @return Player|null
*/
public function getPlayerByIndex($index) {
foreach($this->players as $player) {
/** @var Player $player */
if($player->index == $index) {
return $player;
} else {
return null;
}
}
}
/**
* Get a Player by Login
*
@ -243,7 +259,9 @@ class PlayerManager implements CallbackListener {
* @return Player $player
*/
private function removePlayer($login, $savePlayedTime = true) {
if (!isset($this->players[$login])) return null;
if(!isset($this->players[$login])) {
return null;
}
$player = $this->players[$login];
unset($this->players[$login]);
if($savePlayedTime) {