From c01e0354bde721f6f7944f9320608fbb3c4adcca Mon Sep 17 00:00:00 2001 From: JackNoordhuis Date: Wed, 12 Apr 2017 00:40:41 +1000 Subject: [PATCH 01/14] Address #816 Removes redundant compression argument from NBT::readCompressed() and NBT:: readNetworkCompressed() --- src/pocketmine/level/format/io/region/Anvil.php | 2 +- src/pocketmine/level/format/io/region/McRegion.php | 2 +- src/pocketmine/level/format/io/region/PMAnvil.php | 2 +- src/pocketmine/nbt/NBT.php | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/pocketmine/level/format/io/region/Anvil.php b/src/pocketmine/level/format/io/region/Anvil.php index 9b48a2830..084126b5f 100644 --- a/src/pocketmine/level/format/io/region/Anvil.php +++ b/src/pocketmine/level/format/io/region/Anvil.php @@ -101,7 +101,7 @@ class Anvil extends McRegion{ public function nbtDeserialize(string $data){ $nbt = new NBT(NBT::BIG_ENDIAN); try{ - $nbt->readCompressed($data, ZLIB_ENCODING_DEFLATE); + $nbt->readCompressed($data); $chunk = $nbt->getData(); diff --git a/src/pocketmine/level/format/io/region/McRegion.php b/src/pocketmine/level/format/io/region/McRegion.php index 07563c8ab..bf342a705 100644 --- a/src/pocketmine/level/format/io/region/McRegion.php +++ b/src/pocketmine/level/format/io/region/McRegion.php @@ -126,7 +126,7 @@ class McRegion extends BaseLevelProvider{ public function nbtDeserialize(string $data){ $nbt = new NBT(NBT::BIG_ENDIAN); try{ - $nbt->readCompressed($data, ZLIB_ENCODING_DEFLATE); + $nbt->readCompressed($data); $chunk = $nbt->getData(); diff --git a/src/pocketmine/level/format/io/region/PMAnvil.php b/src/pocketmine/level/format/io/region/PMAnvil.php index cb28cb17f..9ec30c203 100644 --- a/src/pocketmine/level/format/io/region/PMAnvil.php +++ b/src/pocketmine/level/format/io/region/PMAnvil.php @@ -104,7 +104,7 @@ class PMAnvil extends Anvil{ public function nbtDeserialize(string $data){ $nbt = new NBT(NBT::BIG_ENDIAN); try{ - $nbt->readCompressed($data, ZLIB_ENCODING_DEFLATE); + $nbt->readCompressed($data); $chunk = $nbt->getData(); diff --git a/src/pocketmine/nbt/NBT.php b/src/pocketmine/nbt/NBT.php index 5fa2fdd3f..f929f58e3 100644 --- a/src/pocketmine/nbt/NBT.php +++ b/src/pocketmine/nbt/NBT.php @@ -423,11 +423,11 @@ class NBT{ $this->buffer = ""; } - public function readCompressed($buffer, $compression = ZLIB_ENCODING_GZIP){ + public function readCompressed($buffer){ $this->read(zlib_decode($buffer)); } - public function readNetworkCompressed($buffer, $compression = ZLIB_ENCODING_GZIP){ + public function readNetworkCompressed($buffer){ $this->read(zlib_decode($buffer), false, true); } From 1c7773c5f1d3d2e44da73f490133b38f5d43a9c4 Mon Sep 17 00:00:00 2001 From: Sandertv Date: Thu, 13 Apr 2017 14:58:53 +0200 Subject: [PATCH 02/14] Visibility keyword before final or abstract keyword. (#814) --- src/pocketmine/Player.php | 2 +- src/pocketmine/command/Command.php | 2 +- src/pocketmine/entity/Entity.php | 2 +- src/pocketmine/entity/Living.php | 2 +- src/pocketmine/item/Item.php | 4 ++-- src/pocketmine/level/generator/Generator.php | 14 ++++++------- .../level/generator/biome/Biome.php | 2 +- .../level/generator/populator/Populator.php | 2 +- src/pocketmine/metadata/MetadataStore.php | 2 +- src/pocketmine/metadata/MetadataValue.php | 4 ++-- src/pocketmine/nbt/tag/Tag.php | 2 +- src/pocketmine/plugin/PluginBase.php | 20 +++++++++---------- src/pocketmine/scheduler/AsyncTask.php | 2 +- src/pocketmine/scheduler/PluginTask.php | 2 +- src/pocketmine/scheduler/Task.php | 8 ++++---- src/pocketmine/tile/Spawnable.php | 2 +- src/pocketmine/tile/Tile.php | 2 +- 17 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index b8c5ee62b..ac2a05e82 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -3069,7 +3069,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade * @param string $reason Reason showed in console * @param bool $notify */ - public final function close($message = "", $reason = "generic reason", $notify = true){ + final public function close($message = "", $reason = "generic reason", $notify = true){ if($this->connected and !$this->closed){ if($notify and strlen((string) $reason) > 0){ diff --git a/src/pocketmine/command/Command.php b/src/pocketmine/command/Command.php index 07347c557..189a3b03b 100644 --- a/src/pocketmine/command/Command.php +++ b/src/pocketmine/command/Command.php @@ -132,7 +132,7 @@ abstract class Command{ * * @return mixed */ - public abstract function execute(CommandSender $sender, $commandLabel, array $args); + abstract public function execute(CommandSender $sender, $commandLabel, array $args); /** * @return string diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 9f31ee37d..4537c7d2b 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -1092,7 +1092,7 @@ abstract class Entity extends Location implements Metadatable{ //return !($this instanceof Player); } - public final function scheduleUpdate(){ + final public function scheduleUpdate(){ $this->level->updateEntities[$this->id] = $this; } diff --git a/src/pocketmine/entity/Living.php b/src/pocketmine/entity/Living.php index 26b0fcc5a..8cf9644af 100644 --- a/src/pocketmine/entity/Living.php +++ b/src/pocketmine/entity/Living.php @@ -86,7 +86,7 @@ abstract class Living extends Entity implements Damageable{ $this->namedtag->Health = new ShortTag("Health", $this->getHealth()); } - public abstract function getName(); + abstract public function getName(); public function hasLineOfSight(Entity $entity){ //TODO: head height diff --git a/src/pocketmine/item/Item.php b/src/pocketmine/item/Item.php index 98e4a8207..7b49f0f6e 100644 --- a/src/pocketmine/item/Item.php +++ b/src/pocketmine/item/Item.php @@ -916,7 +916,7 @@ class Item implements ItemIds, \JsonSerializable{ * * @return bool */ - public final function equals(Item $item, bool $checkDamage = true, bool $checkCompound = true) : bool{ + final public function equals(Item $item, bool $checkDamage = true, bool $checkCompound = true) : bool{ if($this->id === $item->getId() and ($checkDamage === false or $this->getDamage() === $item->getDamage())){ if($checkCompound){ if($item->getCompoundTag() === $this->getCompoundTag()){ @@ -942,7 +942,7 @@ class Item implements ItemIds, \JsonSerializable{ * * @return bool */ - public final function deepEquals(Item $item, bool $checkDamage = true, bool $checkCompound = true) : bool{ + final public function deepEquals(Item $item, bool $checkDamage = true, bool $checkCompound = true) : bool{ return $this->equals($item, $checkDamage, $checkCompound); } diff --git a/src/pocketmine/level/generator/Generator.php b/src/pocketmine/level/generator/Generator.php index 401890484..c29c5d5cb 100644 --- a/src/pocketmine/level/generator/Generator.php +++ b/src/pocketmine/level/generator/Generator.php @@ -233,17 +233,17 @@ abstract class Generator{ return $noiseArray; } - public abstract function __construct(array $settings = []); + abstract public function __construct(array $settings = []); - public abstract function init(ChunkManager $level, Random $random); + abstract public function init(ChunkManager $level, Random $random); - public abstract function generateChunk($chunkX, $chunkZ); + abstract public function generateChunk($chunkX, $chunkZ); - public abstract function populateChunk($chunkX, $chunkZ); + abstract public function populateChunk($chunkX, $chunkZ); - public abstract function getSettings(); + abstract public function getSettings(); - public abstract function getName(); + abstract public function getName(); - public abstract function getSpawn(); + abstract public function getSpawn(); } diff --git a/src/pocketmine/level/generator/biome/Biome.php b/src/pocketmine/level/generator/biome/Biome.php index 17ee242e0..599de0334 100644 --- a/src/pocketmine/level/generator/biome/Biome.php +++ b/src/pocketmine/level/generator/biome/Biome.php @@ -137,7 +137,7 @@ abstract class Biome{ return $this->id; } - public abstract function getName(); + abstract public function getName(); public function getMinElevation(){ return $this->minElevation; diff --git a/src/pocketmine/level/generator/populator/Populator.php b/src/pocketmine/level/generator/populator/Populator.php index 7eab9fde8..e089a0098 100644 --- a/src/pocketmine/level/generator/populator/Populator.php +++ b/src/pocketmine/level/generator/populator/Populator.php @@ -28,5 +28,5 @@ use pocketmine\level\ChunkManager; use pocketmine\utils\Random; abstract class Populator{ - public abstract function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random); + abstract public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random); } \ No newline at end of file diff --git a/src/pocketmine/metadata/MetadataStore.php b/src/pocketmine/metadata/MetadataStore.php index 586b648af..9cb66dacd 100644 --- a/src/pocketmine/metadata/MetadataStore.php +++ b/src/pocketmine/metadata/MetadataStore.php @@ -136,5 +136,5 @@ abstract class MetadataStore{ * * @throws \InvalidArgumentException */ - public abstract function disambiguate(Metadatable $subject, $metadataKey); + abstract public function disambiguate(Metadatable $subject, $metadataKey); } \ No newline at end of file diff --git a/src/pocketmine/metadata/MetadataValue.php b/src/pocketmine/metadata/MetadataValue.php index 4b927eaaf..4834003fc 100644 --- a/src/pocketmine/metadata/MetadataValue.php +++ b/src/pocketmine/metadata/MetadataValue.php @@ -43,11 +43,11 @@ abstract class MetadataValue{ * * @return mixed */ - public abstract function value(); + abstract public function value(); /** * Invalidates this metadata item, forcing it to recompute when next * accessed. */ - public abstract function invalidate(); + abstract public function invalidate(); } \ No newline at end of file diff --git a/src/pocketmine/nbt/tag/Tag.php b/src/pocketmine/nbt/tag/Tag.php index 9359a5b2f..fa2d395c5 100644 --- a/src/pocketmine/nbt/tag/Tag.php +++ b/src/pocketmine/nbt/tag/Tag.php @@ -34,7 +34,7 @@ abstract class Tag extends \stdClass{ return $this->value; } - public abstract function getType(); + abstract public function getType(); public function setValue($value){ $this->value = $value; diff --git a/src/pocketmine/plugin/PluginBase.php b/src/pocketmine/plugin/PluginBase.php index 1a21698a0..d998ea5bb 100644 --- a/src/pocketmine/plugin/PluginBase.php +++ b/src/pocketmine/plugin/PluginBase.php @@ -72,14 +72,14 @@ abstract class PluginBase implements Plugin{ /** * @return bool */ - public final function isEnabled(){ + final public function isEnabled(){ return $this->isEnabled === true; } /** * @param bool $boolean */ - public final function setEnabled($boolean = true){ + final public function setEnabled($boolean = true){ if($this->isEnabled !== $boolean){ $this->isEnabled = $boolean; if($this->isEnabled === true){ @@ -93,19 +93,19 @@ abstract class PluginBase implements Plugin{ /** * @return bool */ - public final function isDisabled(){ + final public function isDisabled(){ return $this->isEnabled === false; } - public final function getDataFolder(){ + final public function getDataFolder(){ return $this->dataFolder; } - public final function getDescription(){ + final public function getDescription(){ return $this->description; } - public final function init(PluginLoader $loader, Server $server, PluginDescription $description, $dataFolder, $file){ + final public function init(PluginLoader $loader, Server $server, PluginDescription $description, $dataFolder, $file){ if($this->initialized === false){ $this->initialized = true; $this->loader = $loader; @@ -128,7 +128,7 @@ abstract class PluginBase implements Plugin{ /** * @return bool */ - public final function isInitialized(){ + final public function isInitialized(){ return $this->initialized; } @@ -267,21 +267,21 @@ abstract class PluginBase implements Plugin{ /** * @return Server */ - public final function getServer(){ + final public function getServer(){ return $this->server; } /** * @return string */ - public final function getName(){ + final public function getName(){ return $this->description->getName(); } /** * @return string */ - public final function getFullName(){ + final public function getFullName(){ return $this->description->getFullName(); } diff --git a/src/pocketmine/scheduler/AsyncTask.php b/src/pocketmine/scheduler/AsyncTask.php index 455d2e1f4..68491511c 100644 --- a/src/pocketmine/scheduler/AsyncTask.php +++ b/src/pocketmine/scheduler/AsyncTask.php @@ -161,7 +161,7 @@ abstract class AsyncTask extends Collectable{ * * @return void */ - public abstract function onRun(); + abstract public function onRun(); /** * Actions to execute when completed (on main thread) diff --git a/src/pocketmine/scheduler/PluginTask.php b/src/pocketmine/scheduler/PluginTask.php index cacb732e3..645720dbf 100644 --- a/src/pocketmine/scheduler/PluginTask.php +++ b/src/pocketmine/scheduler/PluginTask.php @@ -41,7 +41,7 @@ abstract class PluginTask extends Task{ /** * @return Plugin */ - public final function getOwner(){ + final public function getOwner(){ return $this->owner; } diff --git a/src/pocketmine/scheduler/Task.php b/src/pocketmine/scheduler/Task.php index cbf82a74a..fc0681914 100644 --- a/src/pocketmine/scheduler/Task.php +++ b/src/pocketmine/scheduler/Task.php @@ -32,14 +32,14 @@ abstract class Task{ /** * @return TaskHandler */ - public final function getHandler(){ + final public function getHandler(){ return $this->taskHandler; } /** * @return int */ - public final function getTaskId(){ + final public function getTaskId(){ if($this->taskHandler !== null){ return $this->taskHandler->getTaskId(); } @@ -50,7 +50,7 @@ abstract class Task{ /** * @param TaskHandler $taskHandler */ - public final function setHandler($taskHandler){ + final public function setHandler($taskHandler){ if($this->taskHandler === null or $taskHandler === null){ $this->taskHandler = $taskHandler; } @@ -63,7 +63,7 @@ abstract class Task{ * * @return void */ - public abstract function onRun($currentTick); + abstract public function onRun($currentTick); /** * Actions to execute if the Task is cancelled diff --git a/src/pocketmine/tile/Spawnable.php b/src/pocketmine/tile/Spawnable.php index 07f0ffaa4..555cd75db 100644 --- a/src/pocketmine/tile/Spawnable.php +++ b/src/pocketmine/tile/Spawnable.php @@ -75,7 +75,7 @@ abstract class Spawnable extends Tile{ /** * @return CompoundTag */ - public abstract function getSpawnCompound(); + abstract public function getSpawnCompound(); /** * Called when a player updates a block entity's NBT data diff --git a/src/pocketmine/tile/Tile.php b/src/pocketmine/tile/Tile.php index 51c3ca9d8..daddd775a 100644 --- a/src/pocketmine/tile/Tile.php +++ b/src/pocketmine/tile/Tile.php @@ -159,7 +159,7 @@ abstract class Tile extends Position{ return false; } - public final function scheduleUpdate(){ + final public function scheduleUpdate(){ $this->level->updateTiles[$this->id] = $this; } From 930945db188e36705b4e7186a7174e4d9c3049b0 Mon Sep 17 00:00:00 2001 From: SOFe Date: Tue, 18 Apr 2017 23:33:37 +0800 Subject: [PATCH 03/14] Create PULL_REQUEST_TEMPLATE.md (#845) Adapted from the PHP RFC template --- .github/PULL_REQUEST_TEMPLATE.md | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .github/PULL_REQUEST_TEMPLATE.md diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 000000000..280e4f8bd --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,35 @@ +# Introduction + +## Relevant issues + + + +# Changes +## API changes + + +## Behavioural changes + + +# Follow-up + + + +# Tests + From 207056fb9de4d27ff4303fd37ee755461f641b9c Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 3 Apr 2017 12:37:12 +0100 Subject: [PATCH 04/14] Fixed adventure mode being useless --- src/pocketmine/level/Level.php | 74 +++++++++++++++++----------------- 1 file changed, 38 insertions(+), 36 deletions(-) diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 44e27894b..37b272d49 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -1570,6 +1570,25 @@ class Level implements ChunkManager, Metadatable{ $ev->setCancelled(); } } + + if($player->isAdventure(true) and !$ev->isCancelled()){ + $tag = $item->getNamedTagEntry("CanDestroy"); + $canBreak = false; + if($tag instanceof ListTag){ + foreach($tag as $v){ + if($v instanceof StringTag){ + $entry = Item::fromString($v->getValue()); + if($entry->getId() > 0 and $entry->getBlock() !== null and $entry->getBlock()->getId() === $target->getId()){ + $canBreak = true; + break; + } + } + } + } + + $ev->setCancelled(!$canBreak); + } + $this->server->getPluginManager()->callEvent($ev); if($ev->isCancelled()){ return false; @@ -1615,24 +1634,6 @@ class Level implements ChunkManager, Metadatable{ } } - $tag = $item->getNamedTagEntry("CanDestroy"); - if($tag instanceof ListTag){ - $canBreak = false; - foreach($tag as $v){ - if($v instanceof StringTag){ - $entry = Item::fromString($v->getValue()); - if($entry->getId() > 0 and $entry->getBlock() !== null and $entry->getBlock()->getId() === $target->getId()){ - $canBreak = true; - break; - } - } - } - - if(!$canBreak){ - return false; - } - } - if($createParticles){ $this->addParticle(new DestroyBlockParticle($target->add(0.5, 0.5, 0.5), $target)); } @@ -1707,6 +1708,25 @@ class Level implements ChunkManager, Metadatable{ $ev->setCancelled(); } } + + if($player->isAdventure(true) and !$ev->isCancelled()){ + $canPlace = false; + $tag = $item->getNamedTagEntry("CanPlaceOn"); + if($tag instanceof ListTag){ + foreach($tag as $v){ + if($v instanceof StringTag){ + $entry = Item::fromString($v->getValue()); + if($entry->getId() > 0 and $entry->getBlock() !== null and $entry->getBlock()->getId() === $target->getId()){ + $canPlace = true; + break; + } + } + } + } + + $ev->setCancelled(!$canPlace); + } + $this->server->getPluginManager()->callEvent($ev); if(!$ev->isCancelled()){ $target->onUpdate(self::BLOCK_UPDATE_TOUCH); @@ -1769,24 +1789,6 @@ class Level implements ChunkManager, Metadatable{ } } - $tag = $item->getNamedTagEntry("CanPlaceOn"); - if($tag instanceof ListTag){ - $canPlace = false; - foreach($tag as $v){ - if($v instanceof StringTag){ - $entry = Item::fromString($v->getValue()); - if($entry->getId() > 0 and $entry->getBlock() !== null and $entry->getBlock()->getId() === $target->getId()){ - $canPlace = true; - break; - } - } - } - - if(!$canPlace){ - return false; - } - } - if($player !== null){ $ev = new BlockPlaceEvent($player, $hand, $block, $target, $item); From 86de0bddd912466b21badf57b80999a24754e7f2 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 18 Apr 2017 20:01:51 +0100 Subject: [PATCH 05/14] World should only be completely immutable if we're in spectator mode Fixes being unable to break any blocks at all in adventure mode --- src/pocketmine/Player.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 7898f764e..d9f30ecbd 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1319,7 +1319,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade public function sendSettings(){ $pk = new AdventureSettingsPacket(); $pk->flags = 0; - $pk->worldImmutable = $this->isAdventure(); + $pk->worldImmutable = $this->isSpectator(); $pk->autoJump = $this->autoJump; $pk->allowFlight = $this->allowFlight; $pk->noClip = $this->isSpectator(); From d3f4b185f3ac61f6cdca674439bf549f55ea30b3 Mon Sep 17 00:00:00 2001 From: SOFe Date: Wed, 19 Apr 2017 11:49:46 +0800 Subject: [PATCH 06/14] Fixed typo in PULL_REQUEST_TEMPLATE.md --- .github/PULL_REQUEST_TEMPLATE.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 280e4f8bd..9ac78d047 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -14,10 +14,10 @@ ## Behavioural changes - # Backwards compatibility - + # Follow-up From b867cf4c9153513ee70aab3c378367b52b665915 Mon Sep 17 00:00:00 2001 From: SOFe Date: Wed, 19 Apr 2017 11:50:49 +0800 Subject: [PATCH 07/14] Fix a potential newline issue in PULL_REQUEST_TEMPLATE.md --- .github/PULL_REQUEST_TEMPLATE.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 9ac78d047..d3b3e6d8e 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,5 +1,6 @@ # Introduction + ## Relevant issues -## Relevant issues +### Relevant issues -# Changes -## API changes +## Changes +### API changes -## Behavioural changes +### Behavioural changes -# Backwards compatibility +## Backwards compatibility -# Follow-up +## Follow-up -# Tests +## Tests From 547a09c8d4bb7c034e66377a9252b367e8122234 Mon Sep 17 00:00:00 2001 From: Muqsit Rayyan Date: Thu, 20 Apr 2017 22:39:09 +0300 Subject: [PATCH 10/14] Fix "Creating default object from empty value" (#858) while setting lore to items. --- src/pocketmine/item/Item.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/item/Item.php b/src/pocketmine/item/Item.php index 7cc94878c..b116db7a6 100644 --- a/src/pocketmine/item/Item.php +++ b/src/pocketmine/item/Item.php @@ -685,7 +685,7 @@ class Item implements ItemIds, \JsonSerializable{ } public function setLore(array $lines){ - $tag = $this->getNamedTag(); + $tag = $this->getNamedTag() ?? new CompoundTag("", []); if(!isset($tag->display)){ $tag->display = new CompoundTag("display", []); } From a356e363402af7f042bd76d15da7e72be2d37bf7 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 21 Apr 2017 13:22:09 +0100 Subject: [PATCH 11/14] Autogenerated data for 1.0.7.0 Did they actually _change_ anything or just trying to keep it on par with the game version? >_< --- src/pocketmine/network/mcpe/protocol/ProtocolInfo.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pocketmine/network/mcpe/protocol/ProtocolInfo.php b/src/pocketmine/network/mcpe/protocol/ProtocolInfo.php index 82cfc851a..e789512ff 100644 --- a/src/pocketmine/network/mcpe/protocol/ProtocolInfo.php +++ b/src/pocketmine/network/mcpe/protocol/ProtocolInfo.php @@ -31,9 +31,9 @@ interface ProtocolInfo{ /** * Actual Minecraft: PE protocol version */ - const CURRENT_PROTOCOL = 106; - const MINECRAFT_VERSION = 'v1.0.6.52'; - const MINECRAFT_VERSION_NETWORK = '1.0.6.52'; + const CURRENT_PROTOCOL = 107; + const MINECRAFT_VERSION = 'v1.0.7.0'; + const MINECRAFT_VERSION_NETWORK = '1.0.7.0'; const LOGIN_PACKET = 0x01; const PLAY_STATUS_PACKET = 0x02; From e7406ba0969b55d583568ab82607ccdeb96a19ac Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 21 Apr 2017 14:42:19 +0100 Subject: [PATCH 12/14] Fixed squid health attribute errors --- src/pocketmine/entity/Entity.php | 3 +-- src/pocketmine/entity/Living.php | 2 +- src/pocketmine/entity/Squid.php | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index e7e924e76..9f9ff3a65 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -339,6 +339,7 @@ abstract class Entity extends Location implements Metadatable{ $this->invulnerable = $this->namedtag["Invulnerable"] > 0 ? true : false; $this->attributeMap = new AttributeMap(); + $this->addAttributes(); $this->chunk->addEntity($this); $this->level->addEntity($this); @@ -642,8 +643,6 @@ abstract class Entity extends Location implements Metadatable{ $this->scheduleUpdate(); - $this->addAttributes(); - if(isset($this->namedtag->ActiveEffects)){ foreach($this->namedtag->ActiveEffects->getValue() as $e){ $amplifier = $e["Amplifier"] & 0xff; //0-255 only diff --git a/src/pocketmine/entity/Living.php b/src/pocketmine/entity/Living.php index fbdac34e5..7a0a93e91 100644 --- a/src/pocketmine/entity/Living.php +++ b/src/pocketmine/entity/Living.php @@ -68,7 +68,7 @@ abstract class Living extends Entity implements Damageable{ public function setHealth($amount){ $wasAlive = $this->isAlive(); parent::setHealth($amount); - $this->attributeMap->getAttribute(Attribute::HEALTH)->setValue($this->getHealth()); + $this->attributeMap->getAttribute(Attribute::HEALTH)->setValue($this->getHealth(), true); if($this->isAlive() and !$wasAlive){ $pk = new EntityEventPacket(); $pk->eid = $this->getId(); diff --git a/src/pocketmine/entity/Squid.php b/src/pocketmine/entity/Squid.php index becc8cfc2..50a398360 100644 --- a/src/pocketmine/entity/Squid.php +++ b/src/pocketmine/entity/Squid.php @@ -43,8 +43,8 @@ class Squid extends WaterAnimal implements Ageable{ private $switchDirectionTicker = 0; public function initEntity(){ + $this->setMaxHealth(10); parent::initEntity(); - $this->setMaxHealth(5); } public function getName(){ From 00a226921c6a982491c029d7dcc16d4beaae855a Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 21 Apr 2017 18:51:26 +0100 Subject: [PATCH 13/14] Fixed server crash when taking damage after being killed when having Health Boost effect --- src/pocketmine/Player.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index d9f30ecbd..4763c0113 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -2672,9 +2672,9 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $this->deadTicks = 0; $this->noDamageTicks = 60; + $this->removeAllEffects(); $this->setHealth($this->getMaxHealth()); - $this->removeAllEffects(); $this->sendData($this); $this->sendSettings(); From 22049423383c0f671056ae3b1a1738b4edeec1cb Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 3 Apr 2017 13:12:33 +0100 Subject: [PATCH 14/14] Fixed the half-done hunger implementation, fixed lots of bugs related to hunger - Fixed starvation doesn't deal any damage at all (Human->getFood() returns a float, not an int, === 0 won't work so great) - Added exhaustion for sprinting, walking, jumping and sprint-jumping as per MCPE (these use MCPE values, and yes MCPE does walking exhaustion!) - Fixed attributes don't get reset after player death - Added food and hunger regeneration in peaceful difficulty - Added API methods Living->jump() (motion isn't updated yet, so this won't actually do much if plugins try to use it) and Living->getJumpVelocity() TODO: implement exhaustion for swimming --- src/pocketmine/Player.php | 35 +++++++++---- src/pocketmine/entity/Attribute.php | 4 ++ src/pocketmine/entity/AttributeMap.php | 3 ++ src/pocketmine/entity/Human.php | 49 ++++++++++++------- src/pocketmine/entity/Living.php | 23 +++++++++ .../event/player/PlayerExhaustEvent.php | 18 +++++-- 6 files changed, 101 insertions(+), 31 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 4763c0113..ad6f7b3ed 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1566,6 +1566,15 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $this->teleport($ev->getTo()); }else{ $this->level->addEntityMovement($this->x >> 4, $this->z >> 4, $this->getId(), $this->x, $this->y + $this->getEyeHeight(), $this->z, $this->yaw, $this->pitch, $this->yaw); + + $distance = $from->distance($to); + + //TODO: check swimming (adds 0.015 exhaustion in MCPE) + if($this->isSprinting()){ + $this->exhaust(0.1 * $distance, PlayerExhaustEvent::CAUSE_SPRINTING); + }else{ + $this->exhaust(0.01 * $distance, PlayerExhaustEvent::CAUSE_WALKING); + } } } } @@ -2675,6 +2684,10 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $this->removeAllEffects(); $this->setHealth($this->getMaxHealth()); + foreach($this->attributeMap->getAll() as $attr){ + $attr->resetToDefault(); + } + $this->sendData($this); $this->sendSettings(); @@ -2685,6 +2698,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $this->scheduleUpdate(); break; case PlayerActionPacket::ACTION_JUMP: + $this->jump(); return true; case PlayerActionPacket::ACTION_START_SPRINT: $ev = new PlayerToggleSprintEvent($this, true); @@ -3684,6 +3698,17 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade return; } + parent::kill(); + + $pk = new RespawnPacket(); + $pos = $this->getSpawn(); + $pk->x = $pos->x; + $pk->y = $pos->y; + $pk->z = $pos->z; + $this->dataPacket($pk); + } + + protected function callDeathEvent(){ $message = "death.attack.generic"; $params = [ @@ -3793,10 +3818,9 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade break; default: + break; } - Entity::kill(); - $this->server->getPluginManager()->callEvent($ev = new PlayerDeathEvent($this, $this->getDrops(), new TranslationContainer($message, $params))); if(!$ev->getKeepInventory()){ @@ -3814,13 +3838,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade if($ev->getDeathMessage() != ""){ $this->server->broadcast($ev->getDeathMessage(), Server::BROADCAST_CHANNEL_USERS); } - - $pk = new RespawnPacket(); - $pos = $this->getSpawn(); - $pk->x = $pos->x; - $pk->y = $pos->y; - $pk->z = $pos->z; - $this->dataPacket($pk); } public function attack($damage, EntityDamageEvent $source){ diff --git a/src/pocketmine/entity/Attribute.php b/src/pocketmine/entity/Attribute.php index be5a6cfae..c48534c63 100644 --- a/src/pocketmine/entity/Attribute.php +++ b/src/pocketmine/entity/Attribute.php @@ -165,6 +165,10 @@ class Attribute{ return $this; } + public function resetToDefault(){ + $this->setValue($this->getDefaultValue()); + } + public function getValue(){ return $this->currentValue; } diff --git a/src/pocketmine/entity/AttributeMap.php b/src/pocketmine/entity/AttributeMap.php index cdf821c52..b74492f08 100644 --- a/src/pocketmine/entity/AttributeMap.php +++ b/src/pocketmine/entity/AttributeMap.php @@ -38,6 +38,9 @@ class AttributeMap implements \ArrayAccess{ return $this->attributes[$id] ?? null; } + /** + * @return Attribute[] + */ public function getAll(): array{ return $this->attributes; } diff --git a/src/pocketmine/entity/Human.php b/src/pocketmine/entity/Human.php index 732dd23f8..5d8db656c 100644 --- a/src/pocketmine/entity/Human.php +++ b/src/pocketmine/entity/Human.php @@ -99,6 +99,15 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ $this->skinId = $skinId; } + public function jump(){ + parent::jump(); + if($this->isSprinting()){ + $this->exhaust(0.8, PlayerExhaustEvent::CAUSE_SPRINT_JUMPING); + }else{ + $this->exhaust(0.2, PlayerExhaustEvent::CAUSE_JUMPING); + } + } + public function getFood() : float{ return $this->attributeMap->getAttribute(Attribute::HUNGER)->getValue(); } @@ -355,31 +364,35 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ if($this->isAlive()){ $food = $this->getFood(); $health = $this->getHealth(); - if($food >= 18){ - $this->foodTickTimer++; - if($this->foodTickTimer >= 80 and $health < $this->getMaxHealth()){ - $this->heal(1, new EntityRegainHealthEvent($this, 1, EntityRegainHealthEvent::CAUSE_SATURATION)); - $this->exhaust(3.0, PlayerExhaustEvent::CAUSE_HEALTH_REGEN); - $this->foodTickTimer = 0; + $difficulty = $this->server->getDifficulty(); + $this->foodTickTimer++; + if($this->foodTickTimer >= 80){ + $this->foodTickTimer = 0; + } + + if($difficulty === 0 and $this->foodTickTimer % 10 === 0){ //Peaceful + if($food < 20){ + $this->addFood(1.0); } - }elseif($food === 0){ - $this->foodTickTimer++; - if($this->foodTickTimer >= 80){ - $diff = $this->server->getDifficulty(); - $can = false; - if($diff === 1){ - $can = $health > 10; - }elseif($diff === 2){ - $can = $health > 1; - }elseif($diff === 3){ - $can = true; + if($this->foodTickTimer % 20 === 0 and $health < $this->getMaxHealth()){ + $this->heal(1, new EntityRegainHealthEvent($this, 1, EntityRegainHealthEvent::CAUSE_SATURATION)); + } + } + + if($this->foodTickTimer === 0){ + if($food >= 18){ + if($health < $this->getMaxHealth()){ + $this->heal(1, new EntityRegainHealthEvent($this, 1, EntityRegainHealthEvent::CAUSE_SATURATION)); + $this->exhaust(3.0, PlayerExhaustEvent::CAUSE_HEALTH_REGEN); } - if($can){ + }elseif($food <= 0){ + if(($difficulty === 1 and $health > 10) or ($difficulty === 2 and $health > 1) or $difficulty === 3){ $this->attack(1, new EntityDamageEvent($this, EntityDamageEvent::CAUSE_STARVATION, 1)); } } } + if($food <= 6){ if($this->isSprinting()){ $this->setSprinting(false); diff --git a/src/pocketmine/entity/Living.php b/src/pocketmine/entity/Living.php index 7a0a93e91..985b4fe3a 100644 --- a/src/pocketmine/entity/Living.php +++ b/src/pocketmine/entity/Living.php @@ -43,6 +43,8 @@ abstract class Living extends Entity implements Damageable{ protected $invisible = false; + protected $jumpVelocity = 0.42; + protected function initEntity(){ parent::initEntity(); @@ -115,6 +117,23 @@ abstract class Living extends Entity implements Damageable{ $this->attackTime = 0; } + /** + * Returns the initial upwards velocity of a jumping entity in blocks/tick, including additional velocity due to effects. + * @return float + */ + public function getJumpVelocity() : float{ + return $this->jumpVelocity + ($this->hasEffect(Effect::JUMP) ? (($this->getEffect(Effect::JUMP)->getAmplifier() + 1) / 10) : 0); + } + + /** + * Called when the entity jumps from the ground. This method adds upwards velocity to the entity. + */ + public function jump(){ + if($this->onGround){ + $this->motionY = $this->getJumpVelocity(); //Y motion should already be 0 if we're jumping from the ground. + } + } + public function attack($damage, EntityDamageEvent $source){ if($this->attackTime > 0 or $this->noDamageTicks > 0){ $lastCause = $this->getLastDamageCause(); @@ -183,6 +202,10 @@ abstract class Living extends Entity implements Damageable{ return; } parent::kill(); + $this->callDeathEvent(); + } + + protected function callDeathEvent(){ $this->server->getPluginManager()->callEvent($ev = new EntityDeathEvent($this, $this->getDrops())); foreach($ev->getDrops() as $item){ $this->getLevel()->dropItem($this, $item); diff --git a/src/pocketmine/event/player/PlayerExhaustEvent.php b/src/pocketmine/event/player/PlayerExhaustEvent.php index 623b5fdf4..747988fb5 100644 --- a/src/pocketmine/event/player/PlayerExhaustEvent.php +++ b/src/pocketmine/event/player/PlayerExhaustEvent.php @@ -34,19 +34,21 @@ class PlayerExhaustEvent extends PlayerEvent implements Cancellable{ const CAUSE_HEALTH_REGEN = 4; const CAUSE_POTION = 5; const CAUSE_WALKING = 6; - const CAUSE_SNEAKING = 7; + const CAUSE_SPRINTING = 7; const CAUSE_SWIMMING = 8; - const CAUSE_JUMPING = 10; + const CAUSE_JUMPING = 9; + const CAUSE_SPRINT_JUMPING = 10; const CAUSE_CUSTOM = 11; - const CAUSE_FLAG_SPRINT = 0x10000; - /** @var float */ private $amount; + /** @var int */ + private $cause; public function __construct(Human $human, float $amount, int $cause){ $this->player = $human; $this->amount = $amount; + $this->cause = $cause; } /** @@ -63,4 +65,12 @@ class PlayerExhaustEvent extends PlayerEvent implements Cancellable{ public function setAmount(float $amount){ $this->amount = $amount; } + + /** + * Returns an int cause of the exhaustion - one of the constants at the top of this class. + * @return int + */ + public function getCause() : int{ + return $this->cause; + } }