From 175dd0efa6f3073c48645abfdeeb0ee3600ad6ac Mon Sep 17 00:00:00 2001 From: SOFe Date: Fri, 21 Oct 2016 22:38:49 +0800 Subject: [PATCH 1/3] PhpStorm inspections Fixed some minor bugs and dropped some obsolete code pocketmine\level\generator namespace is ignored in this commit --- src/pocketmine/Player.php | 6 ++++++ src/pocketmine/Server.php | 1 - src/pocketmine/command/defaults/ParticleCommand.php | 7 ++++++- src/pocketmine/entity/Entity.php | 1 + src/pocketmine/entity/Human.php | 3 ++- src/pocketmine/event/Event.php | 2 -- src/pocketmine/inventory/Inventory.php | 4 ++-- src/pocketmine/inventory/Recipe.php | 2 ++ src/pocketmine/item/Item.php | 5 +++++ src/pocketmine/lang/BaseLang.php | 5 +++-- src/pocketmine/level/Level.php | 12 ++++++------ src/pocketmine/level/Location.php | 4 +++- .../level/format/generic/BaseFullChunk.php | 1 + src/pocketmine/nbt/NBT.php | 5 ++--- src/pocketmine/nbt/tag/ListTag.php | 2 ++ src/pocketmine/permission/Permission.php | 4 ++-- src/pocketmine/permission/PermissionAttachment.php | 3 --- src/pocketmine/plugin/PluginBase.php | 2 +- src/pocketmine/scheduler/ServerScheduler.php | 12 ------------ src/pocketmine/tile/Container.php | 1 - src/pocketmine/utils/Utils.php | 2 ++ 21 files changed, 46 insertions(+), 38 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 21aaa1392..f27566478 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -2647,6 +2647,10 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade break; } + /** + * @var int $i + * @var Item $item + */ foreach($packet->input as $i => $item){ if($item->getDamage() === -1 or $item->getDamage() === 0xffff){ $item->setDamage(null); @@ -3140,6 +3144,8 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade /** * Handles player data saving + * + * @param bool $async */ public function save($async = false){ if($this->closed){ diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index 3cc206526..acdd8e538 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -185,7 +185,6 @@ class Server{ /** @var CommandReader */ private $console = null; - private $consoleThreaded; /** @var SimpleCommandMap */ private $commandMap = null; diff --git a/src/pocketmine/command/defaults/ParticleCommand.php b/src/pocketmine/command/defaults/ParticleCommand.php index 58bea12f0..6f29e6138 100644 --- a/src/pocketmine/command/defaults/ParticleCommand.php +++ b/src/pocketmine/command/defaults/ParticleCommand.php @@ -123,8 +123,13 @@ class ParticleCommand extends VanillaCommand{ } /** - * @param $name + * @param string $name * + * @param Vector3 $pos + * @param int $xd + * @param float $yd + * @param float $zd + * @param int|null $data * @return Particle */ private function getParticle($name, Vector3 $pos, $xd, $yd, $zd, $data){ diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 6e6ce9ab9..91ac5104c 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -1610,6 +1610,7 @@ abstract class Entity extends Location implements Metadatable{ * @param int $id * @param int $type * @param mixed $value + * @param bool $send * * @return bool */ diff --git a/src/pocketmine/entity/Human.php b/src/pocketmine/entity/Human.php index f136b97df..870a7146e 100644 --- a/src/pocketmine/entity/Human.php +++ b/src/pocketmine/entity/Human.php @@ -236,7 +236,8 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ } public function recalculateXpProgress() : float{ - $this->setXpProgress($this->getRemainderXp() / self::getTotalXpForLevel($this->getXpLevel())); + $this->setXpProgress($progress = $this->getRemainderXp() / self::getTotalXpForLevel($this->getXpLevel())); + return $progress; } public static function getTotalXpForLevel(int $level) : int{ diff --git a/src/pocketmine/event/Event.php b/src/pocketmine/event/Event.php index 246a1dab6..ed1c47842 100644 --- a/src/pocketmine/event/Event.php +++ b/src/pocketmine/event/Event.php @@ -63,8 +63,6 @@ abstract class Event{ /** * @param bool $value * - * @return bool - * * @throws \BadMethodCallException */ public function setCancelled($value = true){ diff --git a/src/pocketmine/inventory/Inventory.php b/src/pocketmine/inventory/Inventory.php index cadf65fa8..f5f964d4e 100644 --- a/src/pocketmine/inventory/Inventory.php +++ b/src/pocketmine/inventory/Inventory.php @@ -68,7 +68,7 @@ interface Inventory{ * * Returns the Items that did not fit. * - * @param Item ...$item + * @param Item ...$slots * * @return Item[] */ @@ -87,7 +87,7 @@ interface Inventory{ * Removes the given Item from the inventory. * It will return the Items that couldn't be removed. * - * @param Item ...$item + * @param Item ...$slots * * @return Item[] */ diff --git a/src/pocketmine/inventory/Recipe.php b/src/pocketmine/inventory/Recipe.php index bcac5ba75..e1aa17374 100644 --- a/src/pocketmine/inventory/Recipe.php +++ b/src/pocketmine/inventory/Recipe.php @@ -36,4 +36,6 @@ interface Recipe{ * @return UUID */ public function getId(); + + public function setId(UUID $id); } \ No newline at end of file diff --git a/src/pocketmine/item/Item.php b/src/pocketmine/item/Item.php index eab5a0ae2..c2d18d569 100644 --- a/src/pocketmine/item/Item.php +++ b/src/pocketmine/item/Item.php @@ -35,6 +35,7 @@ use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\ListTag; use pocketmine\nbt\tag\ShortTag; use pocketmine\nbt\tag\StringTag; +use pocketmine\nbt\tag\Tag; use pocketmine\Player; use pocketmine\Server; use pocketmine\utils\Config; @@ -594,6 +595,10 @@ class Item implements ItemIds, \JsonSerializable{ return $this; } + /** + * @param $name + * @return Tag|null + */ public function getNamedTagEntry($name){ $tag = $this->getNamedTag(); if($tag !== null){ diff --git a/src/pocketmine/lang/BaseLang.php b/src/pocketmine/lang/BaseLang.php index 5d4a78bce..7dec752f2 100644 --- a/src/pocketmine/lang/BaseLang.php +++ b/src/pocketmine/lang/BaseLang.php @@ -89,9 +89,10 @@ class BaseLang{ } /** - * @param string $str - * @param string[] $params + * @param string $str + * @param string[] $params * + * @param string|null $onlyPrefix * @return string */ public function translateString($str, array $params = [], $onlyPrefix = null){ diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 22565e869..f93abb43f 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -287,6 +287,11 @@ class Level implements ChunkManager, Metadatable{ } } + /** + * @param string|int $hash + * @param int|null $x + * @param int|null $z + */ public static function getXZ($hash, &$x, &$z){ if(PHP_INT_SIZE === 8){ $x = ($hash >> 32) << 32 >> 32; @@ -1785,7 +1790,7 @@ class Level implements ChunkManager, Metadatable{ * Returns the entities colliding the current one inside the AxisAlignedBB * * @param AxisAlignedBB $bb - * @param Entity $entity + * @param Entity|null $entity * * @return Entity[] */ @@ -2316,8 +2321,6 @@ class Level implements ChunkManager, Metadatable{ if(count($this->chunkSendQueue) > 0){ $this->timings->syncChunkSendTimer->startTiming(); - $x = null; - $z = null; foreach($this->chunkSendQueue as $index => $players){ if(isset($this->chunkSendTasks[$index])){ continue; @@ -2778,9 +2781,6 @@ class Level implements ChunkManager, Metadatable{ public function doChunkGarbageCollection(){ $this->timings->doChunkGC->startTiming(); - $X = null; - $Z = null; - foreach($this->chunks as $index => $chunk){ if(!isset($this->unloadQueue[$index]) and (!isset($this->usedChunks[$index]) or count($this->usedChunks[$index]) === 0)){ Level::getXZ($index, $X, $Z); diff --git a/src/pocketmine/level/Location.php b/src/pocketmine/level/Location.php index e29f6fdde..f482df869 100644 --- a/src/pocketmine/level/Location.php +++ b/src/pocketmine/level/Location.php @@ -50,9 +50,11 @@ class Location extends Position{ * @param Level|null $level default null * @param float $yaw default 0.0 * @param float $pitch default 0.0 + * + * @return Location */ public static function fromObject(Vector3 $pos, Level $level = null, $yaw = 0.0, $pitch = 0.0){ - return new Location($pos->x, $pos->y, $pos->z, $yaw, $pitch, ($level === null) ? (($pos instanceof Position) ? $pos->level : null) : $level); + return new Location($pos->x, $pos->y, $pos->z, $yaw, $pitch, $level ?? (($pos instanceof Position) ? $pos->level : null)); } public function getYaw(){ diff --git a/src/pocketmine/level/format/generic/BaseFullChunk.php b/src/pocketmine/level/format/generic/BaseFullChunk.php index d9c2ecc23..33bf64ce8 100644 --- a/src/pocketmine/level/format/generic/BaseFullChunk.php +++ b/src/pocketmine/level/format/generic/BaseFullChunk.php @@ -84,6 +84,7 @@ abstract class BaseFullChunk implements FullChunk{ * @param int[] $heightMap * @param CompoundTag[] $entities * @param CompoundTag[] $tiles + * @param int[] $extraData */ protected function __construct($provider, $x, $z, $blocks, $data, $skyLight, $blockLight, array $biomeColors = [], array $heightMap = [], array $entities = [], array $tiles = [], array $extraData = []){ $this->provider = $provider; diff --git a/src/pocketmine/nbt/NBT.php b/src/pocketmine/nbt/NBT.php index ff8880a18..fcae202f1 100644 --- a/src/pocketmine/nbt/NBT.php +++ b/src/pocketmine/nbt/NBT.php @@ -34,14 +34,13 @@ use pocketmine\nbt\tag\IntArrayTag; use pocketmine\nbt\tag\IntTag; use pocketmine\nbt\tag\ListTag; use pocketmine\nbt\tag\LongTag; -use pocketmine\nbt\tag\NamedTAG; +use pocketmine\nbt\tag\NamedTag; use pocketmine\nbt\tag\ShortTag; use pocketmine\nbt\tag\StringTag; use pocketmine\nbt\tag\Tag; #ifndef COMPILE use pocketmine\utils\Binary; - #endif @@ -532,7 +531,7 @@ class NBT{ public function writeTag(Tag $tag, bool $network = false){ $this->putByte($tag->getType()); - if($tag instanceof NamedTAG){ + if($tag instanceof NamedTag){ $this->putString($tag->getName(), $network); } $tag->write($this, $network); diff --git a/src/pocketmine/nbt/tag/ListTag.php b/src/pocketmine/nbt/tag/ListTag.php index 43a5be668..4732f9a35 100644 --- a/src/pocketmine/nbt/tag/ListTag.php +++ b/src/pocketmine/nbt/tag/ListTag.php @@ -207,6 +207,8 @@ class ListTag extends NamedTag implements \ArrayAccess, \Countable{ foreach($tags as $tag){ $tag->write($nbt, $network); } + + return true; } public function __toString(){ diff --git a/src/pocketmine/permission/Permission.php b/src/pocketmine/permission/Permission.php index baeadcc22..e46216f7f 100644 --- a/src/pocketmine/permission/Permission.php +++ b/src/pocketmine/permission/Permission.php @@ -173,13 +173,13 @@ class Permission{ * @param string|Permission $name * @param $value * - * @return Permission|void Permission if $name is a string, void if it's a Permission + * @return Permission|null Permission if $name is a string, null if it's a Permission */ public function addParent($name, $value){ if($name instanceof Permission){ $name->getChildren()[$this->getName()] = $value; $name->recalculatePermissibles(); - return; + return null; }else{ $perm = Server::getInstance()->getPluginManager()->getPermission($name); if($perm === null){ diff --git a/src/pocketmine/permission/PermissionAttachment.php b/src/pocketmine/permission/PermissionAttachment.php index f87ebc000..52995431a 100644 --- a/src/pocketmine/permission/PermissionAttachment.php +++ b/src/pocketmine/permission/PermissionAttachment.php @@ -89,9 +89,6 @@ class PermissionAttachment{ return $this->permissions; } - /** - * @return bool[] - */ public function clearPermissions(){ $this->permissions = []; $this->permissible->recalculatePermissions(); diff --git a/src/pocketmine/plugin/PluginBase.php b/src/pocketmine/plugin/PluginBase.php index 963c4b411..7c0c75c6e 100644 --- a/src/pocketmine/plugin/PluginBase.php +++ b/src/pocketmine/plugin/PluginBase.php @@ -259,7 +259,7 @@ abstract class PluginBase implements Plugin{ public function reloadConfig(){ $this->config = new Config($this->configFile); if(($configStream = $this->getResource("config.yml")) !== null){ - $this->config->setDefaults(yaml_parse(config::fixYAMLIndexes(stream_get_contents($configStream)))); + $this->config->setDefaults(yaml_parse(Config::fixYAMLIndexes(stream_get_contents($configStream)))); fclose($configStream); } } diff --git a/src/pocketmine/scheduler/ServerScheduler.php b/src/pocketmine/scheduler/ServerScheduler.php index facae5d04..2c408f2c3 100644 --- a/src/pocketmine/scheduler/ServerScheduler.php +++ b/src/pocketmine/scheduler/ServerScheduler.php @@ -277,18 +277,6 @@ class ServerScheduler{ }elseif(!$task->getOwner()->isEnabled()){ throw new PluginException("Plugin '" . $task->getOwner()->getName() . "' attempted to register a task while disabled"); } - }elseif($task instanceof CallbackTask and Server::getInstance()->getProperty("settings.deprecated-verbose", true)){ - $callable = $task->getCallable(); - if(is_array($callable)){ - if(is_object($callable[0])){ - $taskName = "Callback#" . get_class($callable[0]) . "::" . $callable[1]; - }else{ - $taskName = "Callback#" . $callable[0] . "::" . $callable[1]; - } - }else{ - $taskName = "Callback#" . $callable; - } - Server::getInstance()->getLogger()->warning("A plugin attempted to register a deprecated CallbackTask ($taskName)"); } if($delay <= 0){ diff --git a/src/pocketmine/tile/Container.php b/src/pocketmine/tile/Container.php index e98e4e386..312325178 100644 --- a/src/pocketmine/tile/Container.php +++ b/src/pocketmine/tile/Container.php @@ -22,7 +22,6 @@ namespace pocketmine\tile; use pocketmine\item\Item; -use pocketmine\Network; interface Container{ diff --git a/src/pocketmine/utils/Utils.php b/src/pocketmine/utils/Utils.php index fdec8859f..7d40b427b 100644 --- a/src/pocketmine/utils/Utils.php +++ b/src/pocketmine/utils/Utils.php @@ -168,6 +168,8 @@ class Utils{ * BSD => bsd * Other => other * + * @param bool $recalculate + * * @return string */ public static function getOS($recalculate = false){ From e1253db37cddc04479b5aa19ef55eef825f221a5 Mon Sep 17 00:00:00 2001 From: SOFe Date: Sat, 22 Oct 2016 15:01:23 +0800 Subject: [PATCH 2/3] Some more minor changes for autocompletion in IDEs --- src/pocketmine/Player.php | 4 ++-- src/pocketmine/command/defaults/BanListCommand.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index f27566478..3cfd62329 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -2723,8 +2723,8 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade foreach($ingredients as $ingredient){ $slot = -1; - foreach($this->inventory->getContents() as $index => $i){ - if($ingredient->getId() !== 0 and $ingredient->deepEquals($i, $ingredient->getDamage() !== null) and ($i->getCount() - $used[$index]) >= 1){ + foreach($this->inventory->getContents() as $index => $item){ + if($ingredient->getId() !== 0 and $ingredient->deepEquals($item, $ingredient->getDamage() !== null) and ($item->getCount() - $used[$index]) >= 1){ $slot = $index; $used[$index]++; break; diff --git a/src/pocketmine/command/defaults/BanListCommand.php b/src/pocketmine/command/defaults/BanListCommand.php index d2ecbcf3f..f63c6e213 100644 --- a/src/pocketmine/command/defaults/BanListCommand.php +++ b/src/pocketmine/command/defaults/BanListCommand.php @@ -39,7 +39,7 @@ class BanListCommand extends VanillaCommand{ if(!$this->testPermission($sender)){ return true; } - $list = $sender->getServer()->getNameBans(); + if(isset($args[0])){ $args[0] = strtolower($args[0]); if($args[0] === "ips"){ From bd722bb85f89bcf335e8bf5d3df3f86e7537d9fc Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 15 Dec 2016 09:22:51 +0000 Subject: [PATCH 3/3] fix misplaced doc --- src/pocketmine/lang/BaseLang.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/lang/BaseLang.php b/src/pocketmine/lang/BaseLang.php index 7dec752f2..8370820c7 100644 --- a/src/pocketmine/lang/BaseLang.php +++ b/src/pocketmine/lang/BaseLang.php @@ -91,8 +91,8 @@ class BaseLang{ /** * @param string $str * @param string[] $params - * * @param string|null $onlyPrefix + * * @return string */ public function translateString($str, array $params = [], $onlyPrefix = null){