Merge branch 'master' into mcpe-1.1

This commit is contained in:
Dylan K. Taylor
2017-05-30 09:45:20 +01:00
9 changed files with 144 additions and 22 deletions

View File

@ -37,6 +37,7 @@ use pocketmine\entity\Entity;
use pocketmine\event\HandlerList;
use pocketmine\event\level\LevelInitEvent;
use pocketmine\event\level\LevelLoadEvent;
use pocketmine\event\player\PlayerDataSaveEvent;
use pocketmine\event\server\QueryRegenerateEvent;
use pocketmine\event\server\ServerCommandEvent;
use pocketmine\event\Timings;
@ -758,8 +759,6 @@ class Server{
$nbt->Motion->setTagType(NBT::TAG_Double);
$nbt->Rotation->setTagType(NBT::TAG_Float);
$this->saveOfflinePlayerData($name, $nbt);
return $nbt;
}
@ -769,11 +768,16 @@ class Server{
* @param CompoundTag $nbtTag
* @param bool $async
*/
public function saveOfflinePlayerData($name, CompoundTag $nbtTag, $async = false){
if($this->shouldSavePlayerData()){
public function saveOfflinePlayerData(string $name, CompoundTag $nbtTag, bool $async = false){
$ev = new PlayerDataSaveEvent($nbtTag, $name);
$ev->setCancelled(!$this->shouldSavePlayerData());
$this->pluginManager->callEvent($ev);
if(!$ev->isCancelled()){
$nbt = new NBT(NBT::BIG_ENDIAN);
try{
$nbt->setData($nbtTag);
$nbt->setData($ev->getSaveData());
if($async){
$this->getScheduler()->scheduleAsyncTask(new FileWriteTask($this->getDataPath() . "players/" . strtolower($name) . ".dat", $nbt->writeCompressed()));
@ -1716,6 +1720,36 @@ class Server{
return count($recipients);
}
/**
* @param string $title
* @param string $subtitle
* @param int $fadeIn Duration in ticks for fade-in. If -1 is given, client-sided defaults will be used.
* @param int $stay Duration in ticks to stay on screen for
* @param int $fadeOut Duration in ticks for fade-out.
* @param Player[]|null $recipients
*
* @return int
*/
public function broadcastTitle(string $title, string $subtitle = "", int $fadeIn = -1, int $stay = -1, int $fadeOut = -1, $recipients = null){
if(!is_array($recipients)){
/** @var Player[] $recipients */
$recipients = [];
foreach($this->pluginManager->getPermissionSubscriptions(self::BROADCAST_CHANNEL_USERS) as $permissible){
if($permissible instanceof Player and $permissible->hasPermission(self::BROADCAST_CHANNEL_USERS)){
$recipients[spl_object_hash($permissible)] = $permissible; // do not send messages directly, or some might be repeated
}
}
}
/** @var Player[] $recipients */
foreach($recipients as $recipient){
$recipient->addTitle($title, $subtitle, $fadeIn, $stay, $fadeOut);
}
return count($recipients);
}
/**
* @param string $message
* @param string $permissions