Added AsyncTask::onCompletion()

This commit is contained in:
Shoghi Cervantes 2014-06-25 13:01:39 +02:00
parent f9d9d2b0e5
commit 80aebf2932
4 changed files with 19 additions and 8 deletions

View File

@ -1142,7 +1142,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
foreach($this->server->getOnlinePlayers() as $p){
if($p !== $this and strtolower($p->getName()) === strtolower($this->getName())){
if($p->kick("logged in from another location") === false){
$this->close($this->getName() . " has left the game", "already logged in");
$this->close($this->getName() . " has left the game", "Already logged in");
return;
}else{
@ -1190,11 +1190,6 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
parent::__construct($this->getLevel()->getChunkAt($nbt["Pos"][0], $nbt["Pos"][2], true), $nbt);
$this->loggedIn = true;
if(($this->gamemode & 0x01) === 0x01){
$this->inventory->setHeldItemSlot(0);
$this->inventory->setItemInHand(Item::get(Item::STONE, 0, 1));
}
$this->server->getPluginManager()->callEvent($ev = new PlayerLoginEvent($this, "Plugin reason"));
if($ev->isCancelled()){
$this->close($ev->getKickMessage(), "Plugin reason");
@ -1202,6 +1197,11 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
return;
}
if(($this->gamemode & 0x01) === 0x01){
$this->inventory->setHeldItemSlot(0);
$this->inventory->setItemInHand(Item::get(Item::STONE, 0, 1));
}
$pk = new LoginStatusPacket;
$pk->status = 0;
$this->directDataPacket($pk);

View File

@ -1635,7 +1635,7 @@ class Server{
$this->pluginManager->disablePlugins();
foreach($this->players as $player){
$player->close($this->getProperty("settings.shutdown-message", "Server closed"), "server closed");
$player->close($player->getName() . " has left the game", $this->getProperty("settings.shutdown-message", "Server closed"));
}
foreach($this->getLevels() as $level){

View File

@ -20,6 +20,7 @@
*/
namespace pocketmine\scheduler;
use pocketmine\Server;
/**
* Class used to run async tasks in other threads.
@ -91,4 +92,13 @@ abstract class AsyncTask extends \Threaded{
*/
public abstract function onRun();
/**
* Actions to execute when completed (on main thread)
*
* @param Server $server
*
* @return void
*/
public abstract function onCompletion(Server $server);
}

View File

@ -25,6 +25,7 @@
namespace pocketmine\scheduler;
use pocketmine\plugin\Plugin;
use pocketmine\Server;
use pocketmine\utils\ReversePriorityQueue;
class ServerScheduler{
@ -216,7 +217,7 @@ class ServerScheduler{
$this->asyncPool->collect(function (AsyncTask $task){
if($task->isCompleted() or ($task->isFinished() and !$task->hasResult())){
--$this->asyncTasks;
$task->onCompletion(Server::getInstance());
return true;
}