Fixed task not being freed from player on close

This commit is contained in:
Shoghi Cervantes 2014-08-19 11:31:23 +02:00
parent 0246648a2c
commit 5c150f696c

View File

@ -811,7 +811,8 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$this->updateMetadata(); $this->updateMetadata();
}*/ }*/
$this->setSpawn($pos); $this->setSpawn($pos);
$this->server->getScheduler()->scheduleDelayedTask(new CallbackTask(array($this, "checkSleep")), 60); $this->tasks[] = $this->server->getScheduler()->scheduleDelayedTask(new CallbackTask(array($this, "checkSleep")), 60);
return true; return true;
} }
@ -2106,6 +2107,12 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
* @param string $reason Reason showed in console * @param string $reason Reason showed in console
*/ */
public function close($message = "", $reason = "generic reason"){ public function close($message = "", $reason = "generic reason"){
foreach($this->tasks as $task){
$task->cancel();
}
$this->tasks = [];
if($this->connected === true){ if($this->connected === true){
parent::close(); parent::close();
if($this->username != ""){ if($this->username != ""){
@ -2120,10 +2127,6 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$this->server->removePlayer($this); $this->server->removePlayer($this);
$this->getLevel()->freeAllChunks($this); $this->getLevel()->freeAllChunks($this);
$this->loggedIn = false; $this->loggedIn = false;
foreach($this->tasks as $task){
$task->cancel();
}
$this->tasks = [];
if(isset($ev) and $this->username != "" and $this->spawned !== false and $ev->getQuitMessage() != ""){ if(isset($ev) and $this->username != "" and $this->spawned !== false and $ev->getQuitMessage() != ""){
$this->server->broadcastMessage($ev->getQuitMessage()); $this->server->broadcastMessage($ev->getQuitMessage());