Skip to content
This repository has been archived by the owner on Feb 1, 2018. It is now read-only.

PHP 7.2 Update #290

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ sudo: true

language: php
php:
- 7.0
- 7.2.1

before_script:
- pecl install channel://pecl.php.net/pthreads-3.1.6
Expand Down
6 changes: 4 additions & 2 deletions src/pocketmine/PocketMine.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ function dummy(){
const CODENAME = "Wolf";
const TURANIC_API_VERSION = '2.0.0';

const MIN_PHP_VERSION = "7.2.0";

/*
* Startup code. Do not look at it, it may harm you.
* Most of them are hacks to fix date-related bugs, or basic functions used after this
Expand All @@ -101,8 +103,8 @@ function dummy(){
@define('pocketmine\PATH', \getcwd() . DIRECTORY_SEPARATOR);
}

if(version_compare("7.0.15", PHP_VERSION) > 0){
echo "[CRITICAL] You must use PHP >= 7.0.15" . PHP_EOL;
if(version_compare(MIN_PHP_VERSION, PHP_VERSION) > 0){
echo "[CRITICAL] You must use PHP >= " . MIN_PHP_VERSION . PHP_EOL;
echo "[CRITICAL] Please use the installer provided on the homepage." . PHP_EOL;
exit(1);
}
Expand Down
9 changes: 5 additions & 4 deletions src/pocketmine/Thread.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function registerClassLoader(){
*
* @return bool
*/
public function start(int $options = \PTHREADS_INHERIT_ALL){
public function start(?int $options = \PTHREADS_INHERIT_ALL){
ThreadManager::getInstance()->add($this);

if(!$this->isRunning() and !$this->isJoined() and !$this->isTerminated()){
Expand Down Expand Up @@ -93,9 +93,10 @@ public function quit(){
ThreadManager::getInstance()->remove($this);
}

/**
* @return string
*/
/**
* @return string
* @throws \ReflectionException
*/
public function getThreadName(){
return (new \ReflectionClass($this))->getShortName();
}
Expand Down
11 changes: 6 additions & 5 deletions src/pocketmine/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function registerClassLoader(){
*
* @return bool
*/
public function start(int $options = \PTHREADS_INHERIT_ALL){
public function start(?int $options = \PTHREADS_INHERIT_ALL){
ThreadManager::getInstance()->add($this);

if(!$this->isRunning() and !$this->isJoined() and !$this->isTerminated()){
Expand Down Expand Up @@ -98,10 +98,11 @@ public function quit(){
ThreadManager::getInstance()->remove($this);
}

/**
* @return string
*/
public function getThreadName(){
/**
* @return string
* @throws \ReflectionException
*/
public function getThreadName() : string{
return (new \ReflectionClass($this))->getShortName();
}
}
26 changes: 13 additions & 13 deletions src/pocketmine/entity/Human.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public function getXpLevel() : int{
*
* @param int $level
*/
public function setXpLevel(int $level){
public function setXpLevel(int $level) : void{
$this->attributeMap->getAttribute(Attribute::EXPERIENCE_LEVEL)->setValue($level);
}

Expand All @@ -316,7 +316,7 @@ public function setXpLevel(int $level){
* @param int $amount
* @param bool $playSound
*/
public function addXpLevels(int $amount, bool $playSound = true){
public function addXpLevels(int $amount, bool $playSound = true) : void{
$oldLevel = $this->getXpLevel();
$this->setXpLevel($oldLevel + $amount);

Expand All @@ -332,7 +332,7 @@ public function addXpLevels(int $amount, bool $playSound = true){
* Subtracts a number of XP levels from the player.
* @param int $amount
*/
public function subtractXpLevels(int $amount){
public function subtractXpLevels(int $amount) : void{
$this->setXpLevel($this->getXpLevel() - $amount);
}

Expand All @@ -349,7 +349,7 @@ public function getXpProgress() : float{
*
* @param float $progress
*/
public function setXpProgress(float $progress){
public function setXpProgress(float $progress) : void{
$this->attributeMap->getAttribute(Attribute::EXPERIENCE)->setValue($progress);
}

Expand Down Expand Up @@ -378,7 +378,7 @@ public function getCurrentTotalXp() : int{
*
* @param int $amount
*/
public function setCurrentTotalXp(int $amount){
public function setCurrentTotalXp(int $amount) : void{
$newLevel = ExperienceUtils::getLevelFromXp($amount);

$this->setXpLevel((int) $newLevel);
Expand All @@ -392,7 +392,7 @@ public function setCurrentTotalXp(int $amount){
* @param int $amount
* @param bool $playSound Whether to play level-up and XP gained sounds.
*/
public function addXp(int $amount, bool $playSound = true){
public function addXp(int $amount, bool $playSound = true) : void{
$this->totalXp += $amount;

$oldLevel = $this->getXpLevel();
Expand All @@ -411,7 +411,7 @@ public function addXp(int $amount, bool $playSound = true){
}
}

private function playLevelUpSound(int $newLevel){
private function playLevelUpSound(int $newLevel) : void{
$volume = 0x10000000 * (min(30, $newLevel) / 5); //No idea why such odd numbers, but this works...
$this->level->broadcastLevelSoundEvent($this, LevelSoundEventPacket::SOUND_LEVELUP, 1, (int) $volume);
}
Expand All @@ -420,7 +420,7 @@ private function playLevelUpSound(int $newLevel){
* Takes an amount of XP from the player, recalculating their XP level and progress.
* @param int $amount
*/
public function subtractXp(int $amount){
public function subtractXp(int $amount) : void{
$this->addXp(-$amount);
}

Expand All @@ -430,7 +430,7 @@ public function subtractXp(int $amount){
*
* @return int
*/
public function getLifetimeTotalXp(){
public function getLifetimeTotalXp() : int{
return $this->totalXp;
}

Expand All @@ -440,7 +440,7 @@ public function getLifetimeTotalXp(){
*
* @param int $amount
*/
public function setLifetimeTotalXp(int $amount){
public function setLifetimeTotalXp(int $amount) : void{
if($amount < 0){
throw new \InvalidArgumentException("XP must be greater than 0");
}
Expand All @@ -461,7 +461,7 @@ public function canPickupXp() : bool{
*
* @param int $value
*/
public function resetXpCooldown(int $value = 2){
public function resetXpCooldown(int $value = 2) : void{
$this->xpCooldown = $value;
}

Expand All @@ -472,14 +472,14 @@ public function getXpDropAmount() : int{
/**
* @return PlayerInventory
*/
public function getInventory(){
public function getInventory() : PlayerInventory{
return $this->inventory;
}

/**
* @return EnderChestInventory
*/
public function getEnderChestInventory(){
public function getEnderChestInventory() : EnderChestInventory{
return $this->enderChestInventory;
}

Expand Down
28 changes: 14 additions & 14 deletions src/pocketmine/network/mcpe/NetworkBinaryStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function getString() : string{
return $this->get($this->getUnsignedVarInt());
}

public function putString(string $v){
public function putString(string $v) : void{
$this->putUnsignedVarInt(strlen($v));
$this->put($v);
}
Expand All @@ -54,7 +54,7 @@ public function getUUID() : UUID{
return new UUID($part0, $part1, $part2, $part3);
}

public function putUUID(UUID $uuid){
public function putUUID(UUID $uuid) : void{
$this->putLInt($uuid->getPart(1));
$this->putLInt($uuid->getPart(0));
$this->putLInt($uuid->getPart(3));
Expand Down Expand Up @@ -101,7 +101,7 @@ public function getSlot() : Item{
}


public function putSlot(Item $item){
public function putSlot(Item $item) : void{
if($item->getId() === 0){
$this->putVarInt(0);

Expand Down Expand Up @@ -181,7 +181,7 @@ public function getEntityMetadata(bool $types = true) : array{
*
* @param array $metadata
*/
public function putEntityMetadata(array $metadata){
public function putEntityMetadata(array $metadata) : void{
$this->putUnsignedVarInt(count($metadata));
foreach($metadata as $key => $d){
$this->putUnsignedVarInt($key); //data key
Expand Down Expand Up @@ -260,7 +260,7 @@ public function getAttributeList() : array{
*
* @param Attribute[] ...$attributes
*/
public function putAttributeList(Attribute ...$attributes){
public function putAttributeList(Attribute ...$attributes) : void{
$this->putUnsignedVarInt(count($attributes));
foreach($attributes as $attribute){
$this->putLFloat($attribute->getMinValue());
Expand All @@ -284,7 +284,7 @@ public function getEntityUniqueId() : int{
*
* @param int $eid
*/
public function putEntityUniqueId(int $eid){
public function putEntityUniqueId(int $eid) : void{
$this->putVarLong($eid);
}

Expand All @@ -301,7 +301,7 @@ public function getEntityRuntimeId() : int{
*
* @param int $eid
*/
public function putEntityRuntimeId(int $eid){
public function putEntityRuntimeId(int $eid) : void{
$this->putUnsignedVarLong($eid);
}

Expand All @@ -325,7 +325,7 @@ public function getBlockPosition(&$x, &$y, &$z){
* @param int $y
* @param int $z
*/
public function putBlockPosition(int $x, int $y, int $z){
public function putBlockPosition(int $x, int $y, int $z) : void{
$this->putVarInt($x);
$this->putUnsignedVarInt($y);
$this->putVarInt($z);
Expand All @@ -351,7 +351,7 @@ public function getSignedBlockPosition(&$x, &$y, &$z){
* @param int $y
* @param int $z
*/
public function putSignedBlockPosition(int $x, int $y, int $z){
public function putSignedBlockPosition(int $x, int $y, int $z) : void{
$this->putVarInt($x);
$this->putVarInt($y);
$this->putVarInt($z);
Expand All @@ -378,7 +378,7 @@ public function getVector3() : Vector3{
*
* @param Vector3|null $vector
*/
public function putVector3Nullable($vector){
public function putVector3Nullable(?Vector3 $vector) : void{
if($vector){
$this->putVector3($vector);
}else{
Expand All @@ -394,7 +394,7 @@ public function putVector3Nullable($vector){
*
* @param Vector3 $vector
*/
public function putVector3(Vector3 $vector){
public function putVector3(Vector3 $vector) : void{
$this->putLFloat($vector->x);
$this->putLFloat($vector->y);
$this->putLFloat($vector->z);
Expand All @@ -404,7 +404,7 @@ public function getByteRotation() : float{
return (float) ($this->getByte() * (360 / 256));
}

public function putByteRotation(float $rotation){
public function putByteRotation(float $rotation) : void{
$this->putByte((int) ($rotation / (360 / 256)));
}

Expand Down Expand Up @@ -445,7 +445,7 @@ public function getGameRules() : array{
*
* @param array $rules
*/
public function putGameRules(array $rules){
public function putGameRules(array $rules) : void{
$this->putUnsignedVarInt(count($rules));
foreach($rules as $name => $rule){
$this->putString($name);
Expand Down Expand Up @@ -481,7 +481,7 @@ protected function getEntityLink() : EntityLink{
/**
* @param EntityLink $link
*/
protected function putEntityLink(EntityLink $link){
protected function putEntityLink(EntityLink $link) : void{
$this->putEntityUniqueId($link->fromEntityUniqueId);
$this->putEntityUniqueId($link->toEntityUniqueId);
$this->putByte($link->type);
Expand Down
2 changes: 1 addition & 1 deletion src/pocketmine/scheduler/AsyncWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function handleException(\Throwable $e){
/**
* @return string
*/
public function getThreadName(){
public function getThreadName() : string{
return "Asynchronous Worker #" . $this->id;
}

Expand Down
22 changes: 15 additions & 7 deletions src/pocketmine/utils/Terminal.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,21 @@ abstract class Terminal {
*/
public static function hasFormattingCodes(){
if(self::$formattingCodes === null){
$opts = getopt("", ["enable-ansi", "disable-ansi"]);
if(isset($opts["disable-ansi"])){
self::$formattingCodes = false;
}else{
self::$formattingCodes = ((Utils::getOS() !== "win" and getenv("TERM") != "" and (!function_exists("posix_ttyname") or !defined("STDOUT") or posix_ttyname(STDOUT) !== false)) or isset($opts["enable-ansi"]));
}
}
$opts = getopt("", ["enable-ansi", "disable-ansi"]);
if(isset($opts["disable-ansi"])){
self::$formattingCodes = false;
}else{
$stdout = fopen("php://stdout", "w");
self::$formattingCodes = (isset($opts["enable-ansi"]) or ( //user explicitly told us to enable ANSI
stream_isatty($stdout) and //STDOUT isn't being piped
(
getenv('TERM') !== false or //Console says it supports colours
(function_exists('sapi_windows_vt100_support') and sapi_windows_vt100_support($stdout)) //we're on windows and have vt100 support
)
));
fclose($stdout);
}
}

return self::$formattingCodes;
}
Expand Down
2 changes: 1 addition & 1 deletion src/raklib/server/RakLibServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public function cleanPath($path){
return str_replace(["\\", ".php", "phar://", str_replace(["\\", "phar://"], ["/", ""], $this->mainPath)], ["/", "", "", ""], $path);
}

public function run(){
public function run() : void{
try{
$this->loader->register(true);

Expand Down
Loading