mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-14 09:49:50 +00:00
Merge branch 'master' into mcpe-1.1
This commit is contained in:
commit
63358a8065
@ -3639,7 +3639,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
$this->server->getPluginManager()->unsubscribeFromPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE, $this);
|
||||
|
||||
if($this->joined){
|
||||
//TODO: add events for player data saving
|
||||
$this->save();
|
||||
|
||||
$this->server->getPluginManager()->callEvent($ev = new PlayerQuitEvent($this, $message));
|
||||
@ -3740,7 +3739,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
}
|
||||
|
||||
$this->namedtag["playerGameType"] = $this->gamemode;
|
||||
$this->namedtag["lastPlayed"] = new LongTag("lastPlayed", floor(microtime(true) * 1000));
|
||||
$this->namedtag["lastPlayed"] = floor(microtime(true) * 1000);
|
||||
|
||||
if($this->username != "" and $this->namedtag instanceof CompoundTag){
|
||||
$this->server->saveOfflinePlayerData($this->username, $this->namedtag, $async);
|
||||
|
@ -84,6 +84,12 @@ namespace pocketmine {
|
||||
* Enjoy it as much as I did writing it. I don't want to do it again.
|
||||
*/
|
||||
|
||||
if(!extension_loaded("phar")){
|
||||
echo "[CRITICAL] Unable to find the Phar extension." . PHP_EOL;
|
||||
echo "[CRITICAL] Please use the installer provided on the homepage." . PHP_EOL;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if(\Phar::running(true) !== ""){
|
||||
@define('pocketmine\PATH', \Phar::running(true) . "/");
|
||||
}else{
|
||||
|
@ -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
|
||||
|
@ -1016,6 +1016,10 @@ abstract class Entity extends Location implements Metadatable{
|
||||
}
|
||||
|
||||
protected function checkObstruction($x, $y, $z){
|
||||
if(count($this->level->getCollisionCubes($this, $this->getBoundingBox(), false)) === 0){
|
||||
return false;
|
||||
}
|
||||
|
||||
$i = Math::floorFloat($x);
|
||||
$j = Math::floorFloat($y);
|
||||
$k = Math::floorFloat($z);
|
||||
|
78
src/pocketmine/event/player/PlayerDataSaveEvent.php
Normal file
78
src/pocketmine/event/player/PlayerDataSaveEvent.php
Normal file
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\event\player;
|
||||
|
||||
use pocketmine\event\Cancellable;
|
||||
use pocketmine\event\Event;
|
||||
use pocketmine\IPlayer;
|
||||
use pocketmine\nbt\tag\CompoundTag;
|
||||
use pocketmine\Server;
|
||||
|
||||
/**
|
||||
* Called when a player's data is about to be saved to disk.
|
||||
*/
|
||||
class PlayerDataSaveEvent extends Event implements Cancellable{
|
||||
public static $handlerList = null;
|
||||
|
||||
/** @var CompoundTag */
|
||||
protected $data;
|
||||
/** @var string */
|
||||
protected $playerName;
|
||||
|
||||
public function __construct(CompoundTag $nbt, string $playerName){
|
||||
$this->data = $nbt;
|
||||
$this->playerName = $playerName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the data to be written to disk as a CompoundTag
|
||||
* @return CompoundTag
|
||||
*/
|
||||
public function getSaveData() : CompoundTag{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CompoundTag $data
|
||||
*/
|
||||
public function setSaveData(CompoundTag $data){
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the username of the player whose data is being saved. This is not necessarily an online player.
|
||||
* @return string
|
||||
*/
|
||||
public function getPlayerName() : string{
|
||||
return $this->playerName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the player whose data is being saved. This may be a Player or an OfflinePlayer.
|
||||
* @return IPlayer (Player or OfflinePlayer)
|
||||
*/
|
||||
public function getPlayer() : IPlayer{
|
||||
return Server::getInstance()->getOfflinePlayer($this->playerName);
|
||||
}
|
||||
}
|
@ -21,6 +21,7 @@
|
||||
|
||||
namespace pocketmine\event\player;
|
||||
|
||||
use pocketmine\event\TranslationContainer;
|
||||
use pocketmine\Player;
|
||||
|
||||
/**
|
||||
@ -29,30 +30,29 @@ use pocketmine\Player;
|
||||
class PlayerQuitEvent extends PlayerEvent{
|
||||
public static $handlerList = null;
|
||||
|
||||
/** @var string */
|
||||
/** @var TranslationContainer|string */
|
||||
protected $quitMessage;
|
||||
protected $autoSave = true;
|
||||
|
||||
public function __construct(Player $player, $quitMessage, $autoSave = true){
|
||||
/**
|
||||
* @param Player $player
|
||||
* @param TranslationContainer|string $quitMessage
|
||||
*/
|
||||
public function __construct(Player $player, $quitMessage){
|
||||
$this->player = $player;
|
||||
$this->quitMessage = $quitMessage;
|
||||
$this->autoSave = $autoSave;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TranslationContainer|string $quitMessage
|
||||
*/
|
||||
public function setQuitMessage($quitMessage){
|
||||
$this->quitMessage = $quitMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TranslationContainer|string
|
||||
*/
|
||||
public function getQuitMessage(){
|
||||
return $this->quitMessage;
|
||||
}
|
||||
|
||||
public function getAutoSave(){
|
||||
return $this->autoSave;
|
||||
}
|
||||
|
||||
public function setAutoSave($value = true){
|
||||
$this->autoSave = (bool) $value;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -83,6 +83,7 @@ class ResourcePackManager{
|
||||
$info = new \SplFileInfo($packPath);
|
||||
switch($info->getExtension()){
|
||||
case "zip":
|
||||
case "mcpack":
|
||||
$newPack = new ZippedResourcePack($packPath);
|
||||
break;
|
||||
default:
|
||||
|
@ -20,7 +20,7 @@ if(Test-Path "PocketMine-MP.phar"){
|
||||
}
|
||||
|
||||
function StartServer{
|
||||
$command = $binary + " " + $file + " --enable-ansi"
|
||||
$command = "powershell " + $binary + " " + $file + " --enable-ansi"
|
||||
iex $command
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ done
|
||||
|
||||
echo Running PHP lint scans...
|
||||
|
||||
OUTPUT=`find ./src/pocketmine -name "*.php" -print0 | xargs -0 -n1 -P4 php -l`
|
||||
OUTPUT=`find ./src/pocketmine -name "*.php" -print0 | xargs -0 -n1 -P4 "$PHP_BINARY" -l`
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo $OUTPUT | grep -v "No syntax errors"
|
||||
|
Loading…
x
Reference in New Issue
Block a user