From 9e54980ded2c862d55d77a4318c4455d62aaa995 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 21 Aug 2017 12:58:35 +0100 Subject: [PATCH 01/14] Fixed some usages of Block::get() --- src/pocketmine/level/generator/Flat.php | 17 +++++++++-------- .../level/generator/normal/Normal.php | 17 +++++++++-------- .../level/generator/populator/Pond.php | 3 ++- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/pocketmine/level/generator/Flat.php b/src/pocketmine/level/generator/Flat.php index f907825229..f8914d81ae 100644 --- a/src/pocketmine/level/generator/Flat.php +++ b/src/pocketmine/level/generator/Flat.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\level\generator; use pocketmine\block\Block; +use pocketmine\block\BlockFactory; use pocketmine\item\Item; use pocketmine\level\ChunkManager; use pocketmine\level\format\Chunk; @@ -61,14 +62,14 @@ class Flat extends Generator{ if(isset($this->options["decoration"])){ $ores = new Ore(); $ores->setOreTypes([ - new OreType(Block::get(Block::COAL_ORE), 20, 16, 0, 128), - new OreType(Block::get(Block::IRON_ORE), 20, 8, 0, 64), - new OreType(Block::get(Block::REDSTONE_ORE), 8, 7, 0, 16), - new OreType(Block::get(Block::LAPIS_ORE), 1, 6, 0, 32), - new OreType(Block::get(Block::GOLD_ORE), 2, 8, 0, 32), - new OreType(Block::get(Block::DIAMOND_ORE), 1, 7, 0, 16), - new OreType(Block::get(Block::DIRT), 20, 32, 0, 128), - new OreType(Block::get(Block::GRAVEL), 10, 16, 0, 128) + new OreType(BlockFactory::get(Block::COAL_ORE), 20, 16, 0, 128), + new OreType(BlockFactory::get(Block::IRON_ORE), 20, 8, 0, 64), + new OreType(BlockFactory::get(Block::REDSTONE_ORE), 8, 7, 0, 16), + new OreType(BlockFactory::get(Block::LAPIS_ORE), 1, 6, 0, 32), + new OreType(BlockFactory::get(Block::GOLD_ORE), 2, 8, 0, 32), + new OreType(BlockFactory::get(Block::DIAMOND_ORE), 1, 7, 0, 16), + new OreType(BlockFactory::get(Block::DIRT), 20, 32, 0, 128), + new OreType(BlockFactory::get(Block::GRAVEL), 10, 16, 0, 128) ]); $this->populators[] = $ores; } diff --git a/src/pocketmine/level/generator/normal/Normal.php b/src/pocketmine/level/generator/normal/Normal.php index 84971bbd69..f9f3a7d547 100644 --- a/src/pocketmine/level/generator/normal/Normal.php +++ b/src/pocketmine/level/generator/normal/Normal.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\level\generator\normal; use pocketmine\block\Block; +use pocketmine\block\BlockFactory; use pocketmine\level\ChunkManager; use pocketmine\level\generator\biome\Biome; use pocketmine\level\generator\biome\BiomeSelector; @@ -171,14 +172,14 @@ class Normal extends Generator{ $ores = new Ore(); $ores->setOreTypes([ - new OreType(Block::get(Block::COAL_ORE), 20, 16, 0, 128), - new OreType(Block::get(Block::IRON_ORE), 20, 8, 0, 64), - new OreType(Block::get(Block::REDSTONE_ORE), 8, 7, 0, 16), - new OreType(Block::get(Block::LAPIS_ORE), 1, 6, 0, 32), - new OreType(Block::get(Block::GOLD_ORE), 2, 8, 0, 32), - new OreType(Block::get(Block::DIAMOND_ORE), 1, 7, 0, 16), - new OreType(Block::get(Block::DIRT), 20, 32, 0, 128), - new OreType(Block::get(Block::GRAVEL), 10, 16, 0, 128) + new OreType(BlockFactory::get(Block::COAL_ORE), 20, 16, 0, 128), + new OreType(BlockFactory::get(Block::IRON_ORE), 20, 8, 0, 64), + new OreType(BlockFactory::get(Block::REDSTONE_ORE), 8, 7, 0, 16), + new OreType(BlockFactory::get(Block::LAPIS_ORE), 1, 6, 0, 32), + new OreType(BlockFactory::get(Block::GOLD_ORE), 2, 8, 0, 32), + new OreType(BlockFactory::get(Block::DIAMOND_ORE), 1, 7, 0, 16), + new OreType(BlockFactory::get(Block::DIRT), 20, 32, 0, 128), + new OreType(BlockFactory::get(Block::GRAVEL), 10, 16, 0, 128) ]); $this->populators[] = $ores; } diff --git a/src/pocketmine/level/generator/populator/Pond.php b/src/pocketmine/level/generator/populator/Pond.php index d6ea804019..da4ccaa1c1 100644 --- a/src/pocketmine/level/generator/populator/Pond.php +++ b/src/pocketmine/level/generator/populator/Pond.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\level\generator\populator; use pocketmine\block\Block; +use pocketmine\block\BlockFactory; use pocketmine\block\Water; use pocketmine\level\ChunkManager; use pocketmine\math\Vector3; @@ -39,7 +40,7 @@ class Pond extends Populator{ $x = $random->nextRange($chunkX << 4, ($chunkX << 4) + 16); $y = $random->nextBoundedInt(128); $z = $random->nextRange($chunkZ << 4, ($chunkZ << 4) + 16); - $pond = new \pocketmine\level\generator\object\Pond($random, Block::get(Block::WATER)); + $pond = new \pocketmine\level\generator\object\Pond($random, BlockFactory::get(Block::WATER)); if($pond->canPlaceObject($level, $v = new Vector3($x, $y, $z))){ $pond->placeObject($level, $v); } From b62597fe6343227f139dbe35dc31941f583b6d55 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 21 Aug 2017 13:05:32 +0100 Subject: [PATCH 02/14] Fixed some minor issues in Player events API --- src/pocketmine/event/player/PlayerAnimationEvent.php | 2 +- src/pocketmine/event/player/PlayerBucketEmptyEvent.php | 3 --- src/pocketmine/event/player/PlayerDeathEvent.php | 5 ++++- src/pocketmine/event/player/cheat/PlayerCheatEvent.php | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/pocketmine/event/player/PlayerAnimationEvent.php b/src/pocketmine/event/player/PlayerAnimationEvent.php index f2bc89c72e..f899985f35 100644 --- a/src/pocketmine/event/player/PlayerAnimationEvent.php +++ b/src/pocketmine/event/player/PlayerAnimationEvent.php @@ -45,7 +45,7 @@ class PlayerAnimationEvent extends PlayerEvent implements Cancellable{ * @param Player $player * @param int $animation */ - public function __construct(Player $player, $animation = self::ARM_SWING){ + public function __construct(Player $player, int $animation){ $this->player = $player; $this->animationType = $animation; } diff --git a/src/pocketmine/event/player/PlayerBucketEmptyEvent.php b/src/pocketmine/event/player/PlayerBucketEmptyEvent.php index 2b58ff3210..a4023b17b0 100644 --- a/src/pocketmine/event/player/PlayerBucketEmptyEvent.php +++ b/src/pocketmine/event/player/PlayerBucketEmptyEvent.php @@ -30,7 +30,4 @@ use pocketmine\Player; class PlayerBucketEmptyEvent extends PlayerBucketEvent{ public static $handlerList = null; - public function __construct(Player $who, Block $blockClicked, $blockFace, Item $bucket, Item $itemInHand){ - parent::__construct($who, $blockClicked, $blockFace, $bucket, $itemInHand); - } } \ No newline at end of file diff --git a/src/pocketmine/event/player/PlayerDeathEvent.php b/src/pocketmine/event/player/PlayerDeathEvent.php index f2885c8f7c..936bbc7e9a 100644 --- a/src/pocketmine/event/player/PlayerDeathEvent.php +++ b/src/pocketmine/event/player/PlayerDeathEvent.php @@ -31,6 +31,9 @@ use pocketmine\Player; class PlayerDeathEvent extends EntityDeathEvent{ public static $handlerList = null; + /** @var Player */ + protected $entity; + /** @var TextContainer|string */ private $deathMessage; private $keepInventory = false; @@ -48,7 +51,7 @@ class PlayerDeathEvent extends EntityDeathEvent{ /** * @return Player */ - public function getEntity() : Player{ + public function getEntity(){ return $this->entity; } diff --git a/src/pocketmine/event/player/cheat/PlayerCheatEvent.php b/src/pocketmine/event/player/cheat/PlayerCheatEvent.php index a993beca77..191d6e0c56 100644 --- a/src/pocketmine/event/player/cheat/PlayerCheatEvent.php +++ b/src/pocketmine/event/player/cheat/PlayerCheatEvent.php @@ -22,7 +22,7 @@ declare(strict_types=1); /** - * Events called when a player attempts to cheat + * Events called when the server detected that a player is cheating */ namespace pocketmine\event\player\cheat; From 456ddd3fb3ca96a4bc340837f8b620e05fa08dc2 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 21 Aug 2017 13:18:39 +0100 Subject: [PATCH 03/14] Removed obsolete parameters from Entity->attack() and Entity->heal() --- src/pocketmine/Player.php | 4 ++-- src/pocketmine/block/Cactus.php | 2 +- src/pocketmine/block/Fire.php | 2 +- src/pocketmine/block/Lava.php | 2 +- src/pocketmine/block/Magma.php | 2 +- src/pocketmine/entity/Effect.php | 10 +++++----- src/pocketmine/entity/Entity.php | 12 ++++-------- src/pocketmine/entity/FallingSand.php | 4 ++-- src/pocketmine/entity/Human.php | 6 +++--- src/pocketmine/entity/Item.php | 4 ++-- src/pocketmine/entity/Living.php | 20 ++++++++++---------- src/pocketmine/entity/PrimedTNT.php | 4 ++-- src/pocketmine/entity/Projectile.php | 6 +++--- src/pocketmine/entity/Squid.php | 4 ++-- src/pocketmine/level/Explosion.php | 2 +- 15 files changed, 40 insertions(+), 44 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index bce2aa1807..16be224990 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -3715,7 +3715,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } } - public function attack($damage, EntityDamageEvent $source){ + public function attack(EntityDamageEvent $source){ if(!$this->isAlive()){ return; } @@ -3730,7 +3730,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $source->setCancelled(); } - parent::attack($damage, $source); + parent::attack($source); if($source->isCancelled()){ return; diff --git a/src/pocketmine/block/Cactus.php b/src/pocketmine/block/Cactus.php index f9f4c1ac13..62da396d83 100644 --- a/src/pocketmine/block/Cactus.php +++ b/src/pocketmine/block/Cactus.php @@ -68,7 +68,7 @@ class Cactus extends Transparent{ public function onEntityCollide(Entity $entity){ $ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_CONTACT, 1); - $entity->attack($ev->getFinalDamage(), $ev); + $entity->attack($ev); } public function onUpdate(int $type){ diff --git a/src/pocketmine/block/Fire.php b/src/pocketmine/block/Fire.php index 6e62d516f9..51a872fec1 100644 --- a/src/pocketmine/block/Fire.php +++ b/src/pocketmine/block/Fire.php @@ -63,7 +63,7 @@ class Fire extends Flowable{ public function onEntityCollide(Entity $entity){ $ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_FIRE, 1); - $entity->attack($ev->getFinalDamage(), $ev); + $entity->attack($ev); $ev = new EntityCombustByBlockEvent($this, $entity, 8); if($entity instanceof Arrow){ diff --git a/src/pocketmine/block/Lava.php b/src/pocketmine/block/Lava.php index 2b557fa2cd..d5001c9e63 100644 --- a/src/pocketmine/block/Lava.php +++ b/src/pocketmine/block/Lava.php @@ -52,7 +52,7 @@ class Lava extends Liquid{ $entity->fallDistance *= 0.5; $ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_LAVA, 4); - $entity->attack($ev->getFinalDamage(), $ev); + $entity->attack($ev); $ev = new EntityCombustByBlockEvent($this, $entity, 15); Server::getInstance()->getPluginManager()->callEvent($ev); diff --git a/src/pocketmine/block/Magma.php b/src/pocketmine/block/Magma.php index beff40d1a4..81578023cb 100644 --- a/src/pocketmine/block/Magma.php +++ b/src/pocketmine/block/Magma.php @@ -60,7 +60,7 @@ class Magma extends Solid{ public function onEntityCollide(Entity $entity){ if(!$entity->isSneaking()){ $ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_FIRE, 1); - $entity->attack($ev->getFinalDamage(), $ev); + $entity->attack($ev); } } diff --git a/src/pocketmine/entity/Effect.php b/src/pocketmine/entity/Effect.php index 1241c5b340..e06b16a62e 100644 --- a/src/pocketmine/entity/Effect.php +++ b/src/pocketmine/entity/Effect.php @@ -337,19 +337,19 @@ class Effect{ case Effect::POISON: if($entity->getHealth() > 1){ $ev = new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_MAGIC, 1); - $entity->attack($ev->getFinalDamage(), $ev); + $entity->attack($ev); } break; case Effect::WITHER: $ev = new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_MAGIC, 1); - $entity->attack($ev->getFinalDamage(), $ev); + $entity->attack($ev); break; case Effect::REGENERATION: if($entity->getHealth() < $entity->getMaxHealth()){ $ev = new EntityRegainHealthEvent($entity, 1, EntityRegainHealthEvent::CAUSE_MAGIC); - $entity->heal($ev->getAmount(), $ev); + $entity->heal($ev); } break; @@ -362,13 +362,13 @@ class Effect{ //TODO: add particles (witch spell) if($entity->getHealth() < $entity->getMaxHealth()){ $amount = 2 * (2 ** ($this->getEffectLevel() % 32)); - $entity->heal($amount, new EntityRegainHealthEvent($entity, $amount, EntityRegainHealthEvent::CAUSE_MAGIC)); + $entity->heal(new EntityRegainHealthEvent($entity, $amount, EntityRegainHealthEvent::CAUSE_MAGIC)); } break; case Effect::INSTANT_DAMAGE: //TODO: add particles (witch spell) $amount = 2 * (2 ** ($this->getEffectLevel() % 32)); - $entity->attack($amount, new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_MAGIC, $amount)); + $entity->attack(new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_MAGIC, $amount)); break; } } diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 114da9a6b2..b776a2d459 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -883,11 +883,9 @@ abstract class Entity extends Location implements Metadatable{ } /** - * @param float $damage * @param EntityDamageEvent $source - * */ - public function attack($damage, EntityDamageEvent $source){ + public function attack(EntityDamageEvent $source){ $this->server->getPluginManager()->callEvent($source); if($source->isCancelled()){ return; @@ -913,11 +911,9 @@ abstract class Entity extends Location implements Metadatable{ } /** - * @param float $amount * @param EntityRegainHealthEvent $source - * */ - public function heal($amount, EntityRegainHealthEvent $source){ + public function heal(EntityRegainHealthEvent $source){ $this->server->getPluginManager()->callEvent($source); if($source->isCancelled()){ return; @@ -1125,7 +1121,7 @@ abstract class Entity extends Location implements Metadatable{ if($this->y <= -16 and $this->isAlive()){ $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_VOID, 10); - $this->attack($ev->getFinalDamage(), $ev); + $this->attack($ev); $hasUpdate = true; } @@ -1173,7 +1169,7 @@ abstract class Entity extends Location implements Metadatable{ */ protected function dealFireDamage(){ $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_FIRE_TICK, 1); - $this->attack($ev->getFinalDamage(), $ev); + $this->attack($ev); } protected function updateMovement(){ diff --git a/src/pocketmine/entity/FallingSand.php b/src/pocketmine/entity/FallingSand.php index c542982186..1ee67cf037 100644 --- a/src/pocketmine/entity/FallingSand.php +++ b/src/pocketmine/entity/FallingSand.php @@ -74,9 +74,9 @@ class FallingSand extends Entity{ return false; } - public function attack($damage, EntityDamageEvent $source){ + public function attack(EntityDamageEvent $source){ if($source->getCause() === EntityDamageEvent::CAUSE_VOID){ - parent::attack($damage, $source); + parent::attack($source); } } diff --git a/src/pocketmine/entity/Human.php b/src/pocketmine/entity/Human.php index db36c093c6..121746bc8f 100644 --- a/src/pocketmine/entity/Human.php +++ b/src/pocketmine/entity/Human.php @@ -402,19 +402,19 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ $this->addFood(1.0); } if($this->foodTickTimer % 20 === 0 and $health < $this->getMaxHealth()){ - $this->heal(1, new EntityRegainHealthEvent($this, 1, EntityRegainHealthEvent::CAUSE_SATURATION)); + $this->heal(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->heal(new EntityRegainHealthEvent($this, 1, EntityRegainHealthEvent::CAUSE_SATURATION)); $this->exhaust(3.0, PlayerExhaustEvent::CAUSE_HEALTH_REGEN); } }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)); + $this->attack(new EntityDamageEvent($this, EntityDamageEvent::CAUSE_STARVATION, 1)); } } } diff --git a/src/pocketmine/entity/Item.php b/src/pocketmine/entity/Item.php index f45088c0ca..93dd238dfb 100644 --- a/src/pocketmine/entity/Item.php +++ b/src/pocketmine/entity/Item.php @@ -87,14 +87,14 @@ class Item extends Entity{ $this->server->getPluginManager()->callEvent(new ItemSpawnEvent($this)); } - public function attack($damage, EntityDamageEvent $source){ + public function attack(EntityDamageEvent $source){ if( $source->getCause() === EntityDamageEvent::CAUSE_VOID or $source->getCause() === EntityDamageEvent::CAUSE_FIRE_TICK or $source->getCause() === EntityDamageEvent::CAUSE_ENTITY_EXPLOSION or $source->getCause() === EntityDamageEvent::CAUSE_BLOCK_EXPLOSION ){ - parent::attack($damage, $source); + parent::attack($source); } } diff --git a/src/pocketmine/entity/Living.php b/src/pocketmine/entity/Living.php index 11b9b4cb73..be73a05820 100644 --- a/src/pocketmine/entity/Living.php +++ b/src/pocketmine/entity/Living.php @@ -157,8 +157,8 @@ abstract class Living extends Entity implements Damageable{ //return $this->getLevel()->rayTraceBlocks(Vector3::createVector($this->x, $this->y + $this->height, $this->z), Vector3::createVector($entity->x, $entity->y + $entity->height, $entity->z)) === null; } - public function heal($amount, EntityRegainHealthEvent $source){ - parent::heal($amount, $source); + public function heal(EntityRegainHealthEvent $source){ + parent::heal($source); if($source->isCancelled()){ return; } @@ -321,14 +321,14 @@ abstract class Living extends Entity implements Damageable{ $damage = floor($fallDistance - 3 - ($this->hasEffect(Effect::JUMP) ? $this->getEffect(Effect::JUMP)->getEffectLevel() : 0)); if($damage > 0){ $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_FALL, $damage); - $this->attack($ev->getFinalDamage(), $ev); + $this->attack($ev); } } - public function attack($damage, EntityDamageEvent $source){ + public function attack(EntityDamageEvent $source){ if($this->attackTime > 0 or $this->noDamageTicks > 0){ $lastCause = $this->getLastDamageCause(); - if($lastCause !== null and $lastCause->getDamage() >= $damage){ + if($lastCause !== null and $lastCause->getDamage() >= $source->getDamage()){ $source->setCancelled(); } } @@ -346,7 +346,7 @@ abstract class Living extends Entity implements Damageable{ $source->setDamage(-($source->getDamage(EntityDamageEvent::MODIFIER_BASE) * 0.20 * $this->getEffect(Effect::DAMAGE_RESISTANCE)->getEffectLevel()), EntityDamageEvent::MODIFIER_RESISTANCE); } - parent::attack($damage, $source); + parent::attack($source); if($source->isCancelled()){ return; @@ -365,7 +365,7 @@ abstract class Living extends Entity implements Damageable{ $deltaX = $this->x - $e->x; $deltaZ = $this->z - $e->z; - $this->knockBack($e, $damage, $deltaX, $deltaZ, $source->getKnockBack()); + $this->knockBack($e, $source->getDamage(), $deltaX, $deltaZ, $source->getKnockBack()); } } @@ -428,7 +428,7 @@ abstract class Living extends Entity implements Damageable{ if($this->isInsideOfSolid()){ $hasUpdate = true; $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_SUFFOCATION, 1); - $this->attack($ev->getFinalDamage(), $ev); + $this->attack($ev); } if(!$this->hasEffect(Effect::WATER_BREATHING) and $this->isInsideOfWater()){ @@ -441,7 +441,7 @@ abstract class Living extends Entity implements Damageable{ $airTicks = 0; $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_DROWNING, 2); - $this->attack($ev->getFinalDamage(), $ev); + $this->attack($ev); } $this->setDataProperty(self::DATA_AIR, self::DATA_TYPE_SHORT, $airTicks); } @@ -453,7 +453,7 @@ abstract class Living extends Entity implements Damageable{ $airTicks = 0; $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_SUFFOCATION, 2); - $this->attack($ev->getFinalDamage(), $ev); + $this->attack($ev); } $this->setDataProperty(self::DATA_AIR, self::DATA_TYPE_SHORT, $airTicks); }else{ diff --git a/src/pocketmine/entity/PrimedTNT.php b/src/pocketmine/entity/PrimedTNT.php index 1d248a8a4d..2530ee5acd 100644 --- a/src/pocketmine/entity/PrimedTNT.php +++ b/src/pocketmine/entity/PrimedTNT.php @@ -48,9 +48,9 @@ class PrimedTNT extends Entity implements Explosive{ public $canCollide = false; - public function attack($damage, EntityDamageEvent $source){ + public function attack(EntityDamageEvent $source){ if($source->getCause() === EntityDamageEvent::CAUSE_VOID){ - parent::attack($damage, $source); + parent::attack($source); } } diff --git a/src/pocketmine/entity/Projectile.php b/src/pocketmine/entity/Projectile.php index 03ef87172a..b8e8fb6189 100644 --- a/src/pocketmine/entity/Projectile.php +++ b/src/pocketmine/entity/Projectile.php @@ -49,9 +49,9 @@ abstract class Projectile extends Entity{ parent::__construct($level, $nbt); } - public function attack($damage, EntityDamageEvent $source){ + public function attack(EntityDamageEvent $source){ if($source->getCause() === EntityDamageEvent::CAUSE_VOID){ - parent::attack($damage, $source); + parent::attack($source); } } @@ -88,7 +88,7 @@ abstract class Projectile extends Entity{ $ev = new EntityDamageByChildEntityEvent($this->getOwningEntity(), $this, $entity, EntityDamageEvent::CAUSE_PROJECTILE, $damage); } - $entity->attack($ev->getFinalDamage(), $ev); + $entity->attack($ev); $this->hadCollision = true; diff --git a/src/pocketmine/entity/Squid.php b/src/pocketmine/entity/Squid.php index 40826c4464..b46cf3d33e 100644 --- a/src/pocketmine/entity/Squid.php +++ b/src/pocketmine/entity/Squid.php @@ -53,8 +53,8 @@ class Squid extends WaterAnimal{ return "Squid"; } - public function attack($damage, EntityDamageEvent $source){ - parent::attack($damage, $source); + public function attack(EntityDamageEvent $source){ + parent::attack($source); if($source->isCancelled()){ return; } diff --git a/src/pocketmine/level/Explosion.php b/src/pocketmine/level/Explosion.php index 18d419d1a5..03313efef0 100644 --- a/src/pocketmine/level/Explosion.php +++ b/src/pocketmine/level/Explosion.php @@ -187,7 +187,7 @@ class Explosion{ $ev = new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_BLOCK_EXPLOSION, $damage); } - $entity->attack($ev->getFinalDamage(), $ev); + $entity->attack($ev); $entity->setMotion($motion->multiply($impact)); } } From 672b7610a9b4b3a037cdf74477978ba6db021c9e Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 21 Aug 2017 13:51:58 +0100 Subject: [PATCH 04/14] Maybe I should stop using PhpStorm EAPs --- 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 16be224990..04723de85a 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -2309,7 +2309,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $ev->setCancelled(); } - $target->attack($ev->getFinalDamage(), $ev); + $target->attack($ev); if($ev->isCancelled()){ if($item->isTool() and $this->isSurvival()){ From d2ace6bdd204b7e16cd47f0fe42e86fcd25f4857 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 21 Aug 2017 17:17:14 +0100 Subject: [PATCH 05/14] added some typedocs shut up PhpStorm --- src/pocketmine/item/Item.php | 2 ++ src/pocketmine/level/Level.php | 1 + 2 files changed, 3 insertions(+) diff --git a/src/pocketmine/item/Item.php b/src/pocketmine/item/Item.php index 1c5fee5324..498c03018b 100644 --- a/src/pocketmine/item/Item.php +++ b/src/pocketmine/item/Item.php @@ -729,6 +729,7 @@ class Item implements ItemIds, \JsonSerializable{ $tag = $this->getNamedTagEntry("display"); if($tag instanceof CompoundTag and isset($tag->Lore) and $tag->Lore instanceof ListTag){ $lines = []; + /** @var StringTag $line */ foreach($tag->Lore->getValue() as $line){ $lines[] = $line->getValue(); } @@ -1121,6 +1122,7 @@ class Item implements ItemIds, \JsonSerializable{ } if(isset($tag->tag) and $tag->tag instanceof CompoundTag){ + /** @var CompoundTag $t */ $t = clone $tag->tag; $t->setName(""); $item->setNamedTag($t); diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 0b922b494d..6c8c6df5d7 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -1887,6 +1887,7 @@ class Level implements ChunkManager, Metadatable{ for($x = $minX; $x <= $maxX; ++$x){ for($z = $minZ; $z <= $maxZ; ++$z){ foreach($this->getChunkEntities($x, $z) as $ent){ + /** @var Entity|null $entity */ if(($entity === null or ($ent !== $entity and $entity->canCollideWith($ent))) and $ent->boundingBox->intersectsWith($bb)){ $nearby[] = $ent; } From 604d11a8fd34f4cfa7956482180512a02d2478e1 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 21 Aug 2017 17:39:02 +0100 Subject: [PATCH 06/14] import cleanup and fixed an inspection --- src/pocketmine/Player.php | 7 ++++--- src/pocketmine/block/BrownMushroom.php | 4 ---- src/pocketmine/event/player/PlayerBucketEmptyEvent.php | 4 ---- src/pocketmine/item/FlintSteel.php | 1 - src/pocketmine/level/Explosion.php | 1 - src/pocketmine/level/Level.php | 1 - src/pocketmine/level/generator/populator/Pond.php | 1 - 7 files changed, 4 insertions(+), 15 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 04723de85a..2d7ed1c088 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -23,7 +23,6 @@ declare(strict_types=1); namespace pocketmine; -use pocketmine\block\Air; use pocketmine\block\Bed; use pocketmine\block\Block; use pocketmine\block\BlockFactory; @@ -2571,8 +2570,10 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $this->inventory->setItemInHand($bow); } } - if($ev->getProjectile() instanceof Projectile){ - $this->server->getPluginManager()->callEvent($projectileEv = new ProjectileLaunchEvent($ev->getProjectile())); + + $projectile = $ev->getProjectile(); + if($projectile instanceof Projectile){ + $this->server->getPluginManager()->callEvent($projectileEv = new ProjectileLaunchEvent($projectile)); if($projectileEv->isCancelled()){ $ev->getProjectile()->kill(); }else{ diff --git a/src/pocketmine/block/BrownMushroom.php b/src/pocketmine/block/BrownMushroom.php index d5002344e7..2ca5ce0108 100644 --- a/src/pocketmine/block/BrownMushroom.php +++ b/src/pocketmine/block/BrownMushroom.php @@ -67,8 +67,4 @@ class BrownMushroom extends Flowable{ return false; } - protected function recalculateBoundingBox(){ - return null; - } - } \ No newline at end of file diff --git a/src/pocketmine/event/player/PlayerBucketEmptyEvent.php b/src/pocketmine/event/player/PlayerBucketEmptyEvent.php index a4023b17b0..14a1cda409 100644 --- a/src/pocketmine/event/player/PlayerBucketEmptyEvent.php +++ b/src/pocketmine/event/player/PlayerBucketEmptyEvent.php @@ -23,10 +23,6 @@ declare(strict_types=1); namespace pocketmine\event\player; -use pocketmine\block\Block; -use pocketmine\item\Item; -use pocketmine\Player; - class PlayerBucketEmptyEvent extends PlayerBucketEvent{ public static $handlerList = null; diff --git a/src/pocketmine/item/FlintSteel.php b/src/pocketmine/item/FlintSteel.php index 60d5813e75..33686758ac 100644 --- a/src/pocketmine/item/FlintSteel.php +++ b/src/pocketmine/item/FlintSteel.php @@ -25,7 +25,6 @@ namespace pocketmine\item; use pocketmine\block\Block; use pocketmine\block\BlockFactory; -use pocketmine\block\Fire; use pocketmine\block\Solid; use pocketmine\level\Level; use pocketmine\math\Vector3; diff --git a/src/pocketmine/level/Explosion.php b/src/pocketmine/level/Explosion.php index 03313efef0..73df0c067c 100644 --- a/src/pocketmine/level/Explosion.php +++ b/src/pocketmine/level/Explosion.php @@ -33,7 +33,6 @@ use pocketmine\event\entity\EntityDamageByEntityEvent; use pocketmine\event\entity\EntityDamageEvent; use pocketmine\event\entity\EntityExplodeEvent; use pocketmine\item\Item; -use pocketmine\level\format\SubChunkInterface; use pocketmine\level\particle\HugeExplodeSeedParticle; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Math; diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 6c8c6df5d7..b7eeff4797 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -26,7 +26,6 @@ declare(strict_types=1); */ namespace pocketmine\level; -use pocketmine\block\Air; use pocketmine\block\Beetroot; use pocketmine\block\Block; use pocketmine\block\BlockFactory; diff --git a/src/pocketmine/level/generator/populator/Pond.php b/src/pocketmine/level/generator/populator/Pond.php index da4ccaa1c1..417f89b93c 100644 --- a/src/pocketmine/level/generator/populator/Pond.php +++ b/src/pocketmine/level/generator/populator/Pond.php @@ -25,7 +25,6 @@ namespace pocketmine\level\generator\populator; use pocketmine\block\Block; use pocketmine\block\BlockFactory; -use pocketmine\block\Water; use pocketmine\level\ChunkManager; use pocketmine\math\Vector3; use pocketmine\utils\Random; From 876659cc73bae9cf689ed3744f22cbc33f62487b Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 20 Aug 2017 19:11:21 +0100 Subject: [PATCH 07/14] Item factory refactor and added capability to register custom items --- src/pocketmine/Player.php | 21 +- src/pocketmine/Server.php | 4 +- src/pocketmine/block/Anvil.php | 3 +- src/pocketmine/block/Bed.php | 5 +- src/pocketmine/block/Beetroot.php | 7 +- src/pocketmine/block/Block.php | 3 +- src/pocketmine/block/Bookshelf.php | 3 +- src/pocketmine/block/Carrot.php | 3 +- src/pocketmine/block/Clay.php | 3 +- src/pocketmine/block/CoalOre.php | 3 +- src/pocketmine/block/DiamondOre.php | 3 +- src/pocketmine/block/DoublePlant.php | 3 +- src/pocketmine/block/DoubleStoneSlab.php | 3 +- src/pocketmine/block/DoubleWoodenSlab.php | 3 +- src/pocketmine/block/EmeraldOre.php | 3 +- src/pocketmine/block/Farmland.php | 3 +- src/pocketmine/block/FlowerPot.php | 3 +- src/pocketmine/block/Glowstone.php | 3 +- src/pocketmine/block/Grass.php | 3 +- src/pocketmine/block/GrassPath.php | 3 +- src/pocketmine/block/Gravel.php | 3 +- src/pocketmine/block/ItemFrame.php | 3 +- src/pocketmine/block/LapisOre.php | 3 +- src/pocketmine/block/Leaves.php | 7 +- src/pocketmine/block/Leaves2.php | 5 +- src/pocketmine/block/Melon.php | 3 +- src/pocketmine/block/MelonStem.php | 3 +- src/pocketmine/block/Mycelium.php | 3 +- src/pocketmine/block/NetherQuartzOre.php | 3 +- src/pocketmine/block/NetherReactor.php | 5 +- src/pocketmine/block/NetherWartPlant.php | 3 +- src/pocketmine/block/Potato.php | 3 +- src/pocketmine/block/PumpkinStem.php | 3 +- src/pocketmine/block/RedstoneOre.php | 3 +- src/pocketmine/block/Sapling.php | 3 +- src/pocketmine/block/SeaLantern.php | 3 +- src/pocketmine/block/Skull.php | 3 +- src/pocketmine/block/SnowLayer.php | 3 +- src/pocketmine/block/Stone.php | 3 +- src/pocketmine/block/TallGrass.php | 3 +- src/pocketmine/block/Wheat.php | 7 +- src/pocketmine/block/WoodenStairs.php | 3 +- .../command/defaults/GiveCommand.php | 4 +- .../command/defaults/ParticleCommand.php | 9 +- src/pocketmine/entity/FallingSand.php | 3 +- src/pocketmine/entity/Squid.php | 3 +- src/pocketmine/entity/Zombie.php | 9 +- src/pocketmine/inventory/BaseInventory.php | 5 +- src/pocketmine/inventory/CraftingManager.php | 3 +- src/pocketmine/inventory/PlayerInventory.php | 11 +- src/pocketmine/inventory/ShapedRecipe.php | 5 +- src/pocketmine/item/BeetrootSoup.php | 2 +- src/pocketmine/item/Food.php | 2 +- src/pocketmine/item/Item.php | 281 +++-------------- src/pocketmine/item/ItemFactory.php | 285 ++++++++++++++++++ src/pocketmine/item/MushroomStew.php | 2 +- src/pocketmine/level/Explosion.php | 3 +- src/pocketmine/level/Level.php | 13 +- src/pocketmine/level/generator/Flat.php | 4 +- .../network/mcpe/protocol/DataPacket.php | 4 +- src/pocketmine/tile/Chest.php | 3 +- src/pocketmine/tile/FlowerPot.php | 5 +- src/pocketmine/tile/Furnace.php | 9 +- src/pocketmine/tile/ItemFrame.php | 3 +- src/pocketmine/utils/BinaryStream.php | 5 +- tests/plugins/PocketMine-TesterPlugin | 2 +- 66 files changed, 491 insertions(+), 347 deletions(-) create mode 100644 src/pocketmine/item/ItemFactory.php diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 2d7ed1c088..f26c637989 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -83,6 +83,7 @@ use pocketmine\inventory\ShapedRecipe; use pocketmine\inventory\ShapelessRecipe; use pocketmine\inventory\SimpleTransactionGroup; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\level\ChunkLoader; use pocketmine\level\format\Chunk; use pocketmine\level\Level; @@ -1416,7 +1417,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } if($entity instanceof Arrow and $entity->hadCollision){ - $item = Item::get(Item::ARROW, 0, 1); + $item = ItemFactory::get(Item::ARROW, 0, 1); if($this->isSurvival() and !$this->inventory->canAddItem($item)){ continue; } @@ -2320,7 +2321,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ if($this->isSurvival()){ if($item->isTool()){ if($item->useOn($target) and $item->getDamage() >= $item->getMaxDurability()){ - $this->inventory->setItemInHand(Item::get(Item::AIR, 0, 1)); + $this->inventory->setItemInHand(ItemFactory::get(Item::AIR, 0, 1)); }else{ $this->inventory->setItemInHand($item); } @@ -2453,7 +2454,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $snowball->setMotion($snowball->getMotion()->multiply($f)); if($this->isSurvival()){ $item->setCount($item->getCount() - 1); - $this->inventory->setItemInHand($item->getCount() > 0 ? $item : Item::get(Item::AIR)); + $this->inventory->setItemInHand($item->getCount() > 0 ? $item : ItemFactory::get(Item::AIR)); } if($snowball instanceof Projectile){ $this->server->getPluginManager()->callEvent($projectileEv = new ProjectileLaunchEvent($snowball)); @@ -2521,7 +2522,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ if($this->startAction > -1 and $this->getGenericFlag(self::DATA_FLAG_ACTION)){ if($this->inventory->getItemInHand()->getId() === Item::BOW){ $bow = $this->inventory->getItemInHand(); - if($this->isSurvival() and !$this->inventory->contains(Item::get(Item::ARROW, 0, 1))){ + if($this->isSurvival() and !$this->inventory->contains(ItemFactory::get(Item::ARROW, 0, 1))){ $this->inventory->sendContents($this); break; } @@ -2562,10 +2563,10 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ }else{ $ev->getProjectile()->setMotion($ev->getProjectile()->getMotion()->multiply($ev->getForce())); if($this->isSurvival()){ - $this->inventory->removeItem(Item::get(Item::ARROW, 0, 1)); + $this->inventory->removeItem(ItemFactory::get(Item::ARROW, 0, 1)); $bow->setDamage($bow->getDamage() + 1); if($bow->getDamage() >= 385){ - $this->inventory->setItemInHand(Item::get(Item::AIR, 0, 0)); + $this->inventory->setItemInHand(ItemFactory::get(Item::AIR, 0, 0)); }else{ $this->inventory->setItemInHand($bow); } @@ -2602,7 +2603,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $slot = $this->inventory->getItemInHand(); --$slot->count; $this->inventory->setItemInHand($slot); - $this->inventory->addItem(Item::get(Item::BUCKET, 0, 1)); + $this->inventory->addItem(ItemFactory::get(Item::BUCKET, 0, 1)); } $this->removeAllEffects(); @@ -2757,7 +2758,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ return true; } - $this->inventory->setItemInHand(Item::get(Item::AIR, 0, 1)); + $this->inventory->setItemInHand(ItemFactory::get(Item::AIR, 0, 1)); $motion = $this->getDirectionVector()->multiply(0.4); $this->level->dropItem($this->add(0, 1.3, 0), $item, $motion, 40); @@ -2983,7 +2984,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $newItem = clone $item; $newItem->setCount($item->getCount() - $count); }else{ - $newItem = Item::get(Item::AIR, 0, 0); + $newItem = ItemFactory::get(Item::AIR, 0, 0); } $this->inventory->setItem($slot, $newItem); @@ -3015,7 +3016,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ case Item::CAKE: //TODO: detect complex recipes like cake that leave remains $this->awardAchievement("bakeCake"); - $this->inventory->addItem(Item::get(Item::BUCKET, 0, 3)); + $this->inventory->addItem(ItemFactory::get(Item::BUCKET, 0, 3)); break; case Item::STONE_PICKAXE: case Item::GOLDEN_PICKAXE: diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index 332f7829c0..88fc96bdbf 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -50,7 +50,7 @@ use pocketmine\inventory\CraftingManager; use pocketmine\inventory\InventoryType; use pocketmine\inventory\Recipe; use pocketmine\item\enchantment\Enchantment; -use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\lang\BaseLang; use pocketmine\level\format\io\leveldb\LevelDB; use pocketmine\level\format\io\LevelProvider; @@ -1585,7 +1585,7 @@ class Server{ InventoryType::init(); BlockFactory::init(); Enchantment::init(); - Item::init(); + ItemFactory::init(); Biome::init(); Effect::init(); Attribute::init(); diff --git a/src/pocketmine/block/Anvil.php b/src/pocketmine/block/Anvil.php index 0ed31ca764..f0e4f3fff3 100644 --- a/src/pocketmine/block/Anvil.php +++ b/src/pocketmine/block/Anvil.php @@ -25,6 +25,7 @@ namespace pocketmine\block; use pocketmine\inventory\AnvilInventory; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\item\Tool; use pocketmine\math\Vector3; use pocketmine\Player; @@ -83,7 +84,7 @@ class Anvil extends Fallable{ public function getDrops(Item $item) : array{ if($item->isPickaxe() >= Tool::TIER_WOODEN){ return [ - Item::get($this->getItemId(), $this->getDamage() & 0x0c, 1), + ItemFactory::get($this->getItemId(), $this->getDamage() & 0x0c, 1), ]; } diff --git a/src/pocketmine/block/Bed.php b/src/pocketmine/block/Bed.php index 29440ec2da..c8b6029e19 100644 --- a/src/pocketmine/block/Bed.php +++ b/src/pocketmine/block/Bed.php @@ -25,6 +25,7 @@ namespace pocketmine\block; use pocketmine\event\TranslationContainer; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\level\Level; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Vector3; @@ -219,11 +220,11 @@ class Bed extends Transparent{ $tile = $this->getLevel()->getTile($this); if($tile instanceof TileBed){ return [ - Item::get($this->getItemId(), $tile->getColor(), 1) + ItemFactory::get($this->getItemId(), $tile->getColor(), 1) ]; }else{ return [ - Item::get($this->getItemId(), 14, 1) //Red + ItemFactory::get($this->getItemId(), 14, 1) //Red ]; } } diff --git a/src/pocketmine/block/Beetroot.php b/src/pocketmine/block/Beetroot.php index b52cee56d2..d8f2e05719 100644 --- a/src/pocketmine/block/Beetroot.php +++ b/src/pocketmine/block/Beetroot.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; class Beetroot extends Crops{ @@ -40,13 +41,13 @@ class Beetroot extends Crops{ public function getDrops(Item $item) : array{ if($this->meta >= 0x07){ return [ - Item::get(Item::BEETROOT, 0, 1), - Item::get(Item::BEETROOT_SEEDS, 0, mt_rand(0, 3)) + ItemFactory::get(Item::BEETROOT, 0, 1), + ItemFactory::get(Item::BEETROOT_SEEDS, 0, mt_rand(0, 3)) ]; } return [ - Item::get(Item::BEETROOT_SEEDS, 0, 1) + ItemFactory::get(Item::BEETROOT_SEEDS, 0, 1) ]; } } \ No newline at end of file diff --git a/src/pocketmine/block/Block.php b/src/pocketmine/block/Block.php index 9e772db14f..adc0158680 100644 --- a/src/pocketmine/block/Block.php +++ b/src/pocketmine/block/Block.php @@ -28,6 +28,7 @@ namespace pocketmine\block; use pocketmine\entity\Entity; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\item\Tool; use pocketmine\level\Level; use pocketmine\level\MovingObjectPosition; @@ -338,7 +339,7 @@ class Block extends Position implements BlockIds, Metadatable{ */ public function getDrops(Item $item) : array{ return [ - Item::get($this->getItemId(), $this->getDamage() & $this->getVariantBitmask(), 1), + ItemFactory::get($this->getItemId(), $this->getDamage() & $this->getVariantBitmask(), 1), ]; } diff --git a/src/pocketmine/block/Bookshelf.php b/src/pocketmine/block/Bookshelf.php index 690877d43c..62b6e0baf4 100644 --- a/src/pocketmine/block/Bookshelf.php +++ b/src/pocketmine/block/Bookshelf.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\item\Tool; class Bookshelf extends Solid{ @@ -48,7 +49,7 @@ class Bookshelf extends Solid{ public function getDrops(Item $item) : array{ return [ - Item::get(Item::BOOK, 0, 3) + ItemFactory::get(Item::BOOK, 0, 3) ]; } diff --git a/src/pocketmine/block/Carrot.php b/src/pocketmine/block/Carrot.php index e1014775b7..7c41eb1b1b 100644 --- a/src/pocketmine/block/Carrot.php +++ b/src/pocketmine/block/Carrot.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; class Carrot extends Crops{ @@ -39,7 +40,7 @@ class Carrot extends Crops{ public function getDrops(Item $item) : array{ return [ - Item::get(Item::CARROT, 0, $this->meta >= 0x07 ? mt_rand(1, 4) : 1) + ItemFactory::get(Item::CARROT, 0, $this->meta >= 0x07 ? mt_rand(1, 4) : 1) ]; } } \ No newline at end of file diff --git a/src/pocketmine/block/Clay.php b/src/pocketmine/block/Clay.php index fac2194fa0..44556cb0ae 100644 --- a/src/pocketmine/block/Clay.php +++ b/src/pocketmine/block/Clay.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\item\Tool; class Clay extends Solid{ @@ -48,7 +49,7 @@ class Clay extends Solid{ public function getDrops(Item $item) : array{ return [ - Item::get(Item::CLAY_BALL, 0, 4) + ItemFactory::get(Item::CLAY_BALL, 0, 4) ]; } } \ No newline at end of file diff --git a/src/pocketmine/block/CoalOre.php b/src/pocketmine/block/CoalOre.php index de4aff9558..d352bb3021 100644 --- a/src/pocketmine/block/CoalOre.php +++ b/src/pocketmine/block/CoalOre.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\item\Tool; class CoalOre extends Solid{ @@ -49,7 +50,7 @@ class CoalOre extends Solid{ public function getDrops(Item $item) : array{ if($item->isPickaxe() >= Tool::TIER_WOODEN){ return [ - Item::get(Item::COAL, 0, 1) + ItemFactory::get(Item::COAL, 0, 1) ]; } diff --git a/src/pocketmine/block/DiamondOre.php b/src/pocketmine/block/DiamondOre.php index 3fef5ad2ee..fd8e1c1443 100644 --- a/src/pocketmine/block/DiamondOre.php +++ b/src/pocketmine/block/DiamondOre.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\item\Tool; class DiamondOre extends Solid{ @@ -49,7 +50,7 @@ class DiamondOre extends Solid{ public function getDrops(Item $item) : array{ if($item->isPickaxe() >= Tool::TIER_IRON){ return [ - Item::get(Item::DIAMOND, 0, 1) + ItemFactory::get(Item::DIAMOND, 0, 1) ]; } diff --git a/src/pocketmine/block/DoublePlant.php b/src/pocketmine/block/DoublePlant.php index 1d08e1e77f..f2abf8a9a4 100644 --- a/src/pocketmine/block/DoublePlant.php +++ b/src/pocketmine/block/DoublePlant.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\level\Level; use pocketmine\math\Vector3; use pocketmine\Player; @@ -112,7 +113,7 @@ class DoublePlant extends Flowable{ if(!$item->isShears() and ($this->meta === 2 or $this->meta === 3)){ //grass or fern if(mt_rand(0, 24) === 0){ return [ - Item::get(Item::SEEDS, 0, 1) + ItemFactory::get(Item::SEEDS, 0, 1) ]; } diff --git a/src/pocketmine/block/DoubleStoneSlab.php b/src/pocketmine/block/DoubleStoneSlab.php index 8970f6b591..07850aba6a 100644 --- a/src/pocketmine/block/DoubleStoneSlab.php +++ b/src/pocketmine/block/DoubleStoneSlab.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\item\Tool; class DoubleStoneSlab extends Solid{ @@ -59,7 +60,7 @@ class DoubleStoneSlab extends Solid{ public function getDrops(Item $item) : array{ if($item->isPickaxe() >= Tool::TIER_WOODEN){ return [ - Item::get(Item::STONE_SLAB, $this->getDamage() & 0x07, 2), + ItemFactory::get(Item::STONE_SLAB, $this->getDamage() & 0x07, 2), ]; } diff --git a/src/pocketmine/block/DoubleWoodenSlab.php b/src/pocketmine/block/DoubleWoodenSlab.php index 297f94d48a..640a068963 100644 --- a/src/pocketmine/block/DoubleWoodenSlab.php +++ b/src/pocketmine/block/DoubleWoodenSlab.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\item\Tool; class DoubleWoodenSlab extends Solid{ @@ -56,7 +57,7 @@ class DoubleWoodenSlab extends Solid{ public function getDrops(Item $item) : array{ return [ - Item::get(Item::WOODEN_SLAB, $this->getDamage() & 0x07, 2) + ItemFactory::get(Item::WOODEN_SLAB, $this->getDamage() & 0x07, 2) ]; } diff --git a/src/pocketmine/block/EmeraldOre.php b/src/pocketmine/block/EmeraldOre.php index 9468819e15..24ba01db1d 100644 --- a/src/pocketmine/block/EmeraldOre.php +++ b/src/pocketmine/block/EmeraldOre.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\item\Tool; class EmeraldOre extends Solid{ @@ -49,7 +50,7 @@ class EmeraldOre extends Solid{ public function getDrops(Item $item) : array{ if($item->isPickaxe() >= Tool::TIER_IRON){ return [ - Item::get(Item::EMERALD, 0, 1), + ItemFactory::get(Item::EMERALD, 0, 1), ]; } diff --git a/src/pocketmine/block/Farmland.php b/src/pocketmine/block/Farmland.php index 31d9ef6b5d..0c42b79375 100644 --- a/src/pocketmine/block/Farmland.php +++ b/src/pocketmine/block/Farmland.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\item\Tool; use pocketmine\math\AxisAlignedBB; @@ -60,7 +61,7 @@ class Farmland extends Transparent{ public function getDrops(Item $item) : array{ return [ - Item::get(Item::DIRT, 0, 1) + ItemFactory::get(Item::DIRT, 0, 1) ]; } } \ No newline at end of file diff --git a/src/pocketmine/block/FlowerPot.php b/src/pocketmine/block/FlowerPot.php index 206c7c0890..643bc2848c 100644 --- a/src/pocketmine/block/FlowerPot.php +++ b/src/pocketmine/block/FlowerPot.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\level\Level; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Vector3; @@ -116,7 +117,7 @@ class FlowerPot extends Flowable{ if($player instanceof Player){ if($player->isSurvival()){ $item->setCount($item->getCount() - 1); - $player->getInventory()->setItemInHand($item->getCount() > 0 ? $item : Item::get(Item::AIR)); + $player->getInventory()->setItemInHand($item->getCount() > 0 ? $item : ItemFactory::get(Item::AIR)); } } return true; diff --git a/src/pocketmine/block/Glowstone.php b/src/pocketmine/block/Glowstone.php index 35ae6101ed..5ac7ab34f3 100644 --- a/src/pocketmine/block/Glowstone.php +++ b/src/pocketmine/block/Glowstone.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\item\Tool; class Glowstone extends Transparent{ @@ -52,7 +53,7 @@ class Glowstone extends Transparent{ public function getDrops(Item $item) : array{ return [ - Item::get(Item::GLOWSTONE_DUST, 0, mt_rand(2, 4)) + ItemFactory::get(Item::GLOWSTONE_DUST, 0, mt_rand(2, 4)) ]; } } \ No newline at end of file diff --git a/src/pocketmine/block/Grass.php b/src/pocketmine/block/Grass.php index 0ecc8da59a..338b0864ed 100644 --- a/src/pocketmine/block/Grass.php +++ b/src/pocketmine/block/Grass.php @@ -25,6 +25,7 @@ namespace pocketmine\block; use pocketmine\event\block\BlockSpreadEvent; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\item\Tool; use pocketmine\level\generator\object\TallGrass as TallGrassObject; use pocketmine\level\Level; @@ -54,7 +55,7 @@ class Grass extends Solid{ public function getDrops(Item $item) : array{ return [ - Item::get(Item::DIRT, 0, 1), + ItemFactory::get(Item::DIRT, 0, 1), ]; } diff --git a/src/pocketmine/block/GrassPath.php b/src/pocketmine/block/GrassPath.php index 0fce7e0480..5b5a08c008 100644 --- a/src/pocketmine/block/GrassPath.php +++ b/src/pocketmine/block/GrassPath.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\item\Tool; use pocketmine\math\AxisAlignedBB; @@ -60,7 +61,7 @@ class GrassPath extends Transparent{ public function getDrops(Item $item) : array{ return [ - Item::get(Item::DIRT, 0, 1) + ItemFactory::get(Item::DIRT, 0, 1) ]; } } \ No newline at end of file diff --git a/src/pocketmine/block/Gravel.php b/src/pocketmine/block/Gravel.php index 1355298b36..12ce9272bc 100644 --- a/src/pocketmine/block/Gravel.php +++ b/src/pocketmine/block/Gravel.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\item\Tool; class Gravel extends Fallable{ @@ -49,7 +50,7 @@ class Gravel extends Fallable{ public function getDrops(Item $item) : array{ if(mt_rand(1, 10) === 1){ return [ - Item::get(Item::FLINT, 0, 1) + ItemFactory::get(Item::FLINT, 0, 1) ]; } diff --git a/src/pocketmine/block/ItemFrame.php b/src/pocketmine/block/ItemFrame.php index 2399ac4428..cc8abd8d96 100644 --- a/src/pocketmine/block/ItemFrame.php +++ b/src/pocketmine/block/ItemFrame.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\level\Level; use pocketmine\math\Vector3; use pocketmine\nbt\tag\{ @@ -69,7 +70,7 @@ class ItemFrame extends Flowable{ $item->setCount($item->getCount() - 1); $tile->setItem($frameItem); if($player instanceof Player and $player->isSurvival()){ - $player->getInventory()->setItemInHand($item->getCount() <= 0 ? Item::get(Item::AIR) : $item); + $player->getInventory()->setItemInHand($item->getCount() <= 0 ? ItemFactory::get(Item::AIR) : $item); } } } diff --git a/src/pocketmine/block/LapisOre.php b/src/pocketmine/block/LapisOre.php index 168e63cd11..a27220b980 100644 --- a/src/pocketmine/block/LapisOre.php +++ b/src/pocketmine/block/LapisOre.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\item\Tool; class LapisOre extends Solid{ @@ -49,7 +50,7 @@ class LapisOre extends Solid{ public function getDrops(Item $item) : array{ if($item->isPickaxe() >= Tool::TIER_STONE){ return [ - Item::get(Item::DYE, 4, mt_rand(4, 8)) + ItemFactory::get(Item::DYE, 4, mt_rand(4, 8)) ]; } diff --git a/src/pocketmine/block/Leaves.php b/src/pocketmine/block/Leaves.php index a83f04a511..689deede93 100644 --- a/src/pocketmine/block/Leaves.php +++ b/src/pocketmine/block/Leaves.php @@ -25,6 +25,7 @@ namespace pocketmine\block; use pocketmine\event\block\LeavesDecayEvent; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\item\Tool; use pocketmine\level\Level; use pocketmine\math\Vector3; @@ -170,13 +171,13 @@ class Leaves extends Transparent{ $variantMeta = $this->getDamage() & 0x03; if($item->isShears()){ - $drops[] = Item::get($this->getItemId(), $variantMeta, 1); + $drops[] = ItemFactory::get($this->getItemId(), $variantMeta, 1); }else{ if(mt_rand(1, 20) === 1){ //Saplings - $drops[] = Item::get(Item::SAPLING, $variantMeta, 1); + $drops[] = ItemFactory::get(Item::SAPLING, $variantMeta, 1); } if($variantMeta === self::OAK and mt_rand(1, 200) === 1){ //Apples - $drops[] = Item::get(Item::APPLE, 0, 1); + $drops[] = ItemFactory::get(Item::APPLE, 0, 1); } } diff --git a/src/pocketmine/block/Leaves2.php b/src/pocketmine/block/Leaves2.php index e05ee91366..fb8c77920e 100644 --- a/src/pocketmine/block/Leaves2.php +++ b/src/pocketmine/block/Leaves2.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; class Leaves2 extends Leaves{ @@ -43,11 +44,11 @@ class Leaves2 extends Leaves{ if($item->isShears()){ return [ - Item::get($this->getItemId(), $variantMeta, 1) + ItemFactory::get($this->getItemId(), $variantMeta, 1) ]; }elseif(mt_rand(1, 20) === 1){ //Saplings return [ - Item::get(Item::SAPLING, $variantMeta + 4, 1) + ItemFactory::get(Item::SAPLING, $variantMeta + 4, 1) ]; } diff --git a/src/pocketmine/block/Melon.php b/src/pocketmine/block/Melon.php index 3a8a4a4dc9..6e2725f110 100644 --- a/src/pocketmine/block/Melon.php +++ b/src/pocketmine/block/Melon.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\item\Tool; class Melon extends Transparent{ @@ -48,7 +49,7 @@ class Melon extends Transparent{ public function getDrops(Item $item) : array{ return [ - Item::get(Item::MELON_SLICE, 0, mt_rand(3, 7)) + ItemFactory::get(Item::MELON_SLICE, 0, mt_rand(3, 7)) ]; } } \ No newline at end of file diff --git a/src/pocketmine/block/MelonStem.php b/src/pocketmine/block/MelonStem.php index d3223d55ca..fde7f63d7c 100644 --- a/src/pocketmine/block/MelonStem.php +++ b/src/pocketmine/block/MelonStem.php @@ -25,6 +25,7 @@ namespace pocketmine\block; use pocketmine\event\block\BlockGrowEvent; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\level\Level; use pocketmine\math\Vector3; use pocketmine\Server; @@ -84,7 +85,7 @@ class MelonStem extends Crops{ public function getDrops(Item $item) : array{ return [ - Item::get(Item::MELON_SEEDS, 0, mt_rand(0, 2)) + ItemFactory::get(Item::MELON_SEEDS, 0, mt_rand(0, 2)) ]; } } \ No newline at end of file diff --git a/src/pocketmine/block/Mycelium.php b/src/pocketmine/block/Mycelium.php index 32ad6acc85..5d143af045 100644 --- a/src/pocketmine/block/Mycelium.php +++ b/src/pocketmine/block/Mycelium.php @@ -25,6 +25,7 @@ namespace pocketmine\block; use pocketmine\event\block\BlockSpreadEvent; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\item\Tool; use pocketmine\level\Level; use pocketmine\math\Vector3; @@ -52,7 +53,7 @@ class Mycelium extends Solid{ public function getDrops(Item $item) : array{ return [ - Item::get(Item::DIRT, 0, 1) + ItemFactory::get(Item::DIRT, 0, 1) ]; } diff --git a/src/pocketmine/block/NetherQuartzOre.php b/src/pocketmine/block/NetherQuartzOre.php index fc1aa5ab52..97c95e25a3 100644 --- a/src/pocketmine/block/NetherQuartzOre.php +++ b/src/pocketmine/block/NetherQuartzOre.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\item\Tool; class NetherQuartzOre extends Solid{ @@ -49,7 +50,7 @@ class NetherQuartzOre extends Solid{ public function getDrops(Item $item) : array{ if($item->isPickaxe() >= Tool::TIER_WOODEN){ return [ - Item::get(Item::QUARTZ, 0, 1) + ItemFactory::get(Item::QUARTZ, 0, 1) ]; } diff --git a/src/pocketmine/block/NetherReactor.php b/src/pocketmine/block/NetherReactor.php index 42e824e370..98038e5d98 100644 --- a/src/pocketmine/block/NetherReactor.php +++ b/src/pocketmine/block/NetherReactor.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\item\Tool; class NetherReactor extends Solid{ @@ -53,8 +54,8 @@ class NetherReactor extends Solid{ public function getDrops(Item $item) : array{ if($item->isPickaxe() >= Tool::TIER_WOODEN){ return [ - Item::get(Item::IRON_INGOT, 0, 6), - Item::get(Item::DIAMOND, 0, 3) + ItemFactory::get(Item::IRON_INGOT, 0, 6), + ItemFactory::get(Item::DIAMOND, 0, 3) ]; } diff --git a/src/pocketmine/block/NetherWartPlant.php b/src/pocketmine/block/NetherWartPlant.php index 47f549d11a..f7c0d11855 100644 --- a/src/pocketmine/block/NetherWartPlant.php +++ b/src/pocketmine/block/NetherWartPlant.php @@ -26,6 +26,7 @@ namespace pocketmine\block; use pocketmine\event\block\BlockGrowEvent; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\level\Level; use pocketmine\math\Vector3; use pocketmine\Player; @@ -78,7 +79,7 @@ class NetherWartPlant extends Flowable{ public function getDrops(Item $item) : array{ return [ - Item::get($this->getItemId(), 0, ($this->getDamage() === 3 ? mt_rand(2, 4) : 1)) + ItemFactory::get($this->getItemId(), 0, ($this->getDamage() === 3 ? mt_rand(2, 4) : 1)) ]; } } \ No newline at end of file diff --git a/src/pocketmine/block/Potato.php b/src/pocketmine/block/Potato.php index 341e382672..c18aeaafa4 100644 --- a/src/pocketmine/block/Potato.php +++ b/src/pocketmine/block/Potato.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; class Potato extends Crops{ @@ -39,7 +40,7 @@ class Potato extends Crops{ public function getDrops(Item $item) : array{ return [ - Item::get(Item::POTATO, 0, $this->getDamage() >= 0x07 ? mt_rand(1, 4) : 1) + ItemFactory::get(Item::POTATO, 0, $this->getDamage() >= 0x07 ? mt_rand(1, 4) : 1) ]; } } \ No newline at end of file diff --git a/src/pocketmine/block/PumpkinStem.php b/src/pocketmine/block/PumpkinStem.php index d2ac52e3c0..d2aaa2c5ae 100644 --- a/src/pocketmine/block/PumpkinStem.php +++ b/src/pocketmine/block/PumpkinStem.php @@ -25,6 +25,7 @@ namespace pocketmine\block; use pocketmine\event\block\BlockGrowEvent; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\level\Level; use pocketmine\math\Vector3; use pocketmine\Server; @@ -84,7 +85,7 @@ class PumpkinStem extends Crops{ public function getDrops(Item $item) : array{ return [ - Item::get(Item::PUMPKIN_SEEDS, 0, mt_rand(0, 2)) + ItemFactory::get(Item::PUMPKIN_SEEDS, 0, mt_rand(0, 2)) ]; } } \ No newline at end of file diff --git a/src/pocketmine/block/RedstoneOre.php b/src/pocketmine/block/RedstoneOre.php index 4ffe5fe658..7034ba4ce6 100644 --- a/src/pocketmine/block/RedstoneOre.php +++ b/src/pocketmine/block/RedstoneOre.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\item\Tool; use pocketmine\level\Level; use pocketmine\math\Vector3; @@ -66,7 +67,7 @@ class RedstoneOre extends Solid{ public function getDrops(Item $item) : array{ if($item->isPickaxe() >= Tool::TIER_IRON){ return [ - Item::get(Item::REDSTONE_DUST, 0, mt_rand(4, 5)) + ItemFactory::get(Item::REDSTONE_DUST, 0, mt_rand(4, 5)) ]; } diff --git a/src/pocketmine/block/Sapling.php b/src/pocketmine/block/Sapling.php index d4d7f7640d..910c1eb1dc 100644 --- a/src/pocketmine/block/Sapling.php +++ b/src/pocketmine/block/Sapling.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\level\generator\object\Tree; use pocketmine\level\Level; use pocketmine\math\Vector3; @@ -109,7 +110,7 @@ class Sapling extends Flowable{ public function getDrops(Item $item) : array{ return [ - Item::get($this->getItemId(), $this->getDamage() & 0x07, 1) + ItemFactory::get($this->getItemId(), $this->getDamage() & 0x07, 1) ]; } diff --git a/src/pocketmine/block/SeaLantern.php b/src/pocketmine/block/SeaLantern.php index 4dd87fb809..093d1dcad3 100644 --- a/src/pocketmine/block/SeaLantern.php +++ b/src/pocketmine/block/SeaLantern.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; class SeaLantern extends Transparent{ @@ -47,7 +48,7 @@ class SeaLantern extends Transparent{ public function getDrops(Item $item) : array{ return [ - Item::get(Item::PRISMARINE_CRYSTALS, 0, 3) + ItemFactory::get(Item::PRISMARINE_CRYSTALS, 0, 3) ]; } diff --git a/src/pocketmine/block/Skull.php b/src/pocketmine/block/Skull.php index d088c888c0..7f20eb678b 100644 --- a/src/pocketmine/block/Skull.php +++ b/src/pocketmine/block/Skull.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Vector3; use pocketmine\nbt\tag\ByteTag; @@ -94,7 +95,7 @@ class Skull extends Flowable{ $tile = $this->level->getTile($this); if($tile instanceof SkullTile){ return [ - Item::get(Item::SKULL, $tile->getType(), 1) + ItemFactory::get(Item::SKULL, $tile->getType(), 1) ]; } diff --git a/src/pocketmine/block/SnowLayer.php b/src/pocketmine/block/SnowLayer.php index dbdf663ebd..565d746f5c 100644 --- a/src/pocketmine/block/SnowLayer.php +++ b/src/pocketmine/block/SnowLayer.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\item\Tool; use pocketmine\level\Level; use pocketmine\math\Vector3; @@ -86,7 +87,7 @@ class SnowLayer extends Flowable{ public function getDrops(Item $item) : array{ if($item->isShovel() !== false){ return [ - Item::get(Item::SNOWBALL, 0, 1) //TODO: check layer count + ItemFactory::get(Item::SNOWBALL, 0, 1) //TODO: check layer count ]; } diff --git a/src/pocketmine/block/Stone.php b/src/pocketmine/block/Stone.php index fa6edb6efc..9c93607944 100644 --- a/src/pocketmine/block/Stone.php +++ b/src/pocketmine/block/Stone.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\item\Tool; class Stone extends Solid{ @@ -66,7 +67,7 @@ class Stone extends Solid{ if($item->isPickaxe() >= Tool::TIER_WOODEN){ if($this->getDamage() === self::NORMAL){ return [ - Item::get(Item::COBBLESTONE, $this->getDamage(), 1) + ItemFactory::get(Item::COBBLESTONE, $this->getDamage(), 1) ]; } diff --git a/src/pocketmine/block/TallGrass.php b/src/pocketmine/block/TallGrass.php index 14c5830b5d..9caeaee52b 100644 --- a/src/pocketmine/block/TallGrass.php +++ b/src/pocketmine/block/TallGrass.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\level\Level; use pocketmine\math\Vector3; use pocketmine\Player; @@ -76,7 +77,7 @@ class TallGrass extends Flowable{ public function getDrops(Item $item) : array{ if(mt_rand(0, 15) === 0){ return [ - Item::get(Item::WHEAT_SEEDS, 0, 1) + ItemFactory::get(Item::WHEAT_SEEDS, 0, 1) ]; } diff --git a/src/pocketmine/block/Wheat.php b/src/pocketmine/block/Wheat.php index 06a3a8468b..622026719d 100644 --- a/src/pocketmine/block/Wheat.php +++ b/src/pocketmine/block/Wheat.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; class Wheat extends Crops{ @@ -40,12 +41,12 @@ class Wheat extends Crops{ public function getDrops(Item $item) : array{ if($this->meta >= 0x07){ return [ - Item::get(Item::WHEAT, 0, 1), - Item::get(Item::WHEAT_SEEDS, 0, mt_rand(0, 3)) + ItemFactory::get(Item::WHEAT, 0, 1), + ItemFactory::get(Item::WHEAT_SEEDS, 0, mt_rand(0, 3)) ]; }else{ return [ - Item::get(Item::WHEAT_SEEDS, 0, 1) + ItemFactory::get(Item::WHEAT_SEEDS, 0, 1) ]; } } diff --git a/src/pocketmine/block/WoodenStairs.php b/src/pocketmine/block/WoodenStairs.php index dcff14e123..09dc4f88db 100644 --- a/src/pocketmine/block/WoodenStairs.php +++ b/src/pocketmine/block/WoodenStairs.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\item\Tool; class WoodenStairs extends Stair{ @@ -43,7 +44,7 @@ class WoodenStairs extends Stair{ public function getDrops(Item $item) : array{ //TODO: Hierarchy problem (base class is for stone stairs) return [ - Item::get($this->getItemId(), $this->getDamage() & $this->getVariantBitmask(), 1) + ItemFactory::get($this->getItemId(), $this->getDamage() & $this->getVariantBitmask(), 1) ]; } } \ No newline at end of file diff --git a/src/pocketmine/command/defaults/GiveCommand.php b/src/pocketmine/command/defaults/GiveCommand.php index 27093f8933..0e70368141 100644 --- a/src/pocketmine/command/defaults/GiveCommand.php +++ b/src/pocketmine/command/defaults/GiveCommand.php @@ -27,7 +27,7 @@ use pocketmine\command\Command; use pocketmine\command\CommandSender; use pocketmine\command\utils\InvalidCommandSyntaxException; use pocketmine\event\TranslationContainer; -use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\nbt\JsonNBTParser; use pocketmine\nbt\tag\CompoundTag; use pocketmine\Player; @@ -54,7 +54,7 @@ class GiveCommand extends VanillaCommand{ } $player = $sender->getServer()->getPlayer($args[0]); - $item = Item::fromString($args[1]); + $item = ItemFactory::fromString($args[1]); if(!isset($args[2])){ $item->setCount($item->getMaxStackSize()); diff --git a/src/pocketmine/command/defaults/ParticleCommand.php b/src/pocketmine/command/defaults/ParticleCommand.php index 7bbe3de5b9..a11c6ae156 100644 --- a/src/pocketmine/command/defaults/ParticleCommand.php +++ b/src/pocketmine/command/defaults/ParticleCommand.php @@ -28,6 +28,7 @@ use pocketmine\command\CommandSender; use pocketmine\command\utils\InvalidCommandSyntaxException; use pocketmine\event\TranslationContainer; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\level\particle\AngryVillagerParticle; use pocketmine\level\particle\BlockForceFieldParticle; use pocketmine\level\particle\BubbleParticle; @@ -173,12 +174,12 @@ class ParticleCommand extends VanillaCommand{ case "reddust": return new RedstoneParticle($pos, $data ?? 1); case "snowballpoof": - return new ItemBreakParticle($pos, Item::get(Item::SNOWBALL)); + return new ItemBreakParticle($pos, ItemFactory::get(Item::SNOWBALL)); case "slime": - return new ItemBreakParticle($pos, Item::get(Item::SLIMEBALL)); + return new ItemBreakParticle($pos, ItemFactory::get(Item::SLIMEBALL)); case "itembreak": if($data !== null and $data !== 0){ - return new ItemBreakParticle($pos, Item::get($data)); + return new ItemBreakParticle($pos, ItemFactory::get($data)); } break; case "terrain": @@ -206,7 +207,7 @@ class ParticleCommand extends VanillaCommand{ if(strpos($name, "iconcrack_") === 0){ $d = explode("_", $name); if(count($d) === 3){ - return new ItemBreakParticle($pos, Item::get((int) $d[1], (int) $d[2])); + return new ItemBreakParticle($pos, ItemFactory::get((int) $d[1], (int) $d[2])); } }elseif(strpos($name, "blockcrack_") === 0){ $d = explode("_", $name); diff --git a/src/pocketmine/entity/FallingSand.php b/src/pocketmine/entity/FallingSand.php index 1ee67cf037..93a4bdedf6 100644 --- a/src/pocketmine/entity/FallingSand.php +++ b/src/pocketmine/entity/FallingSand.php @@ -27,6 +27,7 @@ use pocketmine\block\BlockFactory; use pocketmine\event\entity\EntityBlockChangeEvent; use pocketmine\event\entity\EntityDamageEvent; use pocketmine\item\Item as ItemItem; +use pocketmine\item\ItemFactory; use pocketmine\math\Vector3; use pocketmine\nbt\tag\ByteTag; use pocketmine\nbt\tag\IntTag; @@ -95,7 +96,7 @@ class FallingSand extends Entity{ $block = $this->level->getBlock($pos); if($block->getId() > 0 and $block->isTransparent() and !$block->canBeReplaced()){ //FIXME: anvils are supposed to destroy torches - $this->getLevel()->dropItem($this, ItemItem::get($this->getBlock(), $this->getDamage(), 1)); + $this->getLevel()->dropItem($this, ItemFactory::get($this->getBlock(), $this->getDamage(), 1)); }else{ $this->server->getPluginManager()->callEvent($ev = new EntityBlockChangeEvent($this, $block, BlockFactory::get($this->getBlock(), $this->getDamage()))); if(!$ev->isCancelled()){ diff --git a/src/pocketmine/entity/Squid.php b/src/pocketmine/entity/Squid.php index b46cf3d33e..4b9e969ba0 100644 --- a/src/pocketmine/entity/Squid.php +++ b/src/pocketmine/entity/Squid.php @@ -26,6 +26,7 @@ namespace pocketmine\entity; use pocketmine\event\entity\EntityDamageByEntityEvent; use pocketmine\event\entity\EntityDamageEvent; use pocketmine\item\Item as ItemItem; +use pocketmine\item\ItemFactory; use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\AddEntityPacket; use pocketmine\network\mcpe\protocol\EntityEventPacket; @@ -147,7 +148,7 @@ class Squid extends WaterAnimal{ public function getDrops() : array{ return [ - ItemItem::get(ItemItem::DYE, 0, mt_rand(1, 3)) + ItemFactory::get(ItemItem::DYE, 0, mt_rand(1, 3)) ]; } } diff --git a/src/pocketmine/entity/Zombie.php b/src/pocketmine/entity/Zombie.php index 4d578a67be..cf1a5631ea 100644 --- a/src/pocketmine/entity/Zombie.php +++ b/src/pocketmine/entity/Zombie.php @@ -25,6 +25,7 @@ namespace pocketmine\entity; use pocketmine\event\entity\EntityDamageByEntityEvent; use pocketmine\item\Item as ItemItem; +use pocketmine\item\ItemFactory; use pocketmine\network\mcpe\protocol\AddEntityPacket; use pocketmine\Player; @@ -59,19 +60,19 @@ class Zombie extends Monster{ public function getDrops() : array{ $drops = [ - ItemItem::get(ItemItem::FEATHER, 0, 1) + ItemFactory::get(ItemItem::FEATHER, 0, 1) ]; if($this->lastDamageCause instanceof EntityDamageByEntityEvent and $this->lastDamageCause->getEntity() instanceof Player){ if(mt_rand(0, 199) < 5){ switch(mt_rand(0, 2)){ case 0: - $drops[] = ItemItem::get(ItemItem::IRON_INGOT, 0, 1); + $drops[] = ItemFactory::get(ItemItem::IRON_INGOT, 0, 1); break; case 1: - $drops[] = ItemItem::get(ItemItem::CARROT, 0, 1); + $drops[] = ItemFactory::get(ItemItem::CARROT, 0, 1); break; case 2: - $drops[] = ItemItem::get(ItemItem::POTATO, 0, 1); + $drops[] = ItemFactory::get(ItemItem::POTATO, 0, 1); break; } } diff --git a/src/pocketmine/inventory/BaseInventory.php b/src/pocketmine/inventory/BaseInventory.php index fa9960c057..50e8607ddf 100644 --- a/src/pocketmine/inventory/BaseInventory.php +++ b/src/pocketmine/inventory/BaseInventory.php @@ -27,6 +27,7 @@ use pocketmine\entity\Entity; use pocketmine\event\entity\EntityInventoryChangeEvent; use pocketmine\event\inventory\InventoryOpenEvent; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\network\mcpe\protocol\ContainerSetContentPacket; use pocketmine\network\mcpe\protocol\ContainerSetSlotPacket; use pocketmine\Player; @@ -106,7 +107,7 @@ abstract class BaseInventory implements Inventory{ public function getItem(int $index) : Item{ assert($index >= 0, "Inventory slot should not be negative"); - return isset($this->slots[$index]) ? clone $this->slots[$index] : Item::get(Item::AIR, 0, 0); + return isset($this->slots[$index]) ? clone $this->slots[$index] : ItemFactory::get(Item::AIR, 0, 0); } public function getContents() : array{ @@ -340,7 +341,7 @@ abstract class BaseInventory implements Inventory{ public function clear(int $index) : bool{ if(isset($this->slots[$index])){ - $item = Item::get(Item::AIR, 0, 0); + $item = ItemFactory::get(Item::AIR, 0, 0); $old = $this->slots[$index]; $holder = $this->getHolder(); if($holder instanceof Entity){ diff --git a/src/pocketmine/inventory/CraftingManager.php b/src/pocketmine/inventory/CraftingManager.php index 43cebd6a4d..747b7cdc4f 100644 --- a/src/pocketmine/inventory/CraftingManager.php +++ b/src/pocketmine/inventory/CraftingManager.php @@ -25,6 +25,7 @@ namespace pocketmine\inventory; use pocketmine\event\Timings; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\network\mcpe\protocol\CraftingDataPacket; use pocketmine\Server; use pocketmine\utils\Config; @@ -81,7 +82,7 @@ class CraftingManager{ case 3: $result = $recipe["output"]; $resultItem = Item::jsonDeserialize($result); - $this->registerRecipe(new FurnaceRecipe($resultItem, Item::get($recipe["inputId"], $recipe["inputDamage"] ?? -1, 1))); + $this->registerRecipe(new FurnaceRecipe($resultItem, ItemFactory::get($recipe["inputId"], $recipe["inputDamage"] ?? -1, 1))); break; default: break; diff --git a/src/pocketmine/inventory/PlayerInventory.php b/src/pocketmine/inventory/PlayerInventory.php index 6250b62c0a..59ca38fbc8 100644 --- a/src/pocketmine/inventory/PlayerInventory.php +++ b/src/pocketmine/inventory/PlayerInventory.php @@ -28,6 +28,7 @@ use pocketmine\event\entity\EntityArmorChangeEvent; use pocketmine\event\entity\EntityInventoryChangeEvent; use pocketmine\event\player\PlayerItemHeldEvent; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\network\mcpe\protocol\ContainerSetContentPacket; use pocketmine\network\mcpe\protocol\ContainerSetSlotPacket; use pocketmine\network\mcpe\protocol\MobArmorEquipmentPacket; @@ -76,7 +77,7 @@ class PlayerInventory extends BaseInventory{ } if($inventorySlot === -1){ - $item = Item::get(Item::AIR, 0, 0); + $item = ItemFactory::get(Item::AIR, 0, 0); }else{ $item = $this->getItem($inventorySlot); } @@ -143,7 +144,7 @@ class PlayerInventory extends BaseInventory{ if($inventorySlot !== -1){ return $this->getItem($inventorySlot); }else{ - return Item::get(Item::AIR, 0, 0); + return ItemFactory::get(Item::AIR, 0, 0); } } @@ -350,7 +351,7 @@ class PlayerInventory extends BaseInventory{ public function clear(int $index) : bool{ if(isset($this->slots[$index])){ - $item = Item::get(Item::AIR, 0, 0); + $item = ItemFactory::get(Item::AIR, 0, 0); $old = $this->slots[$index]; if($index >= $this->getSize() and $index < $this->size){ //Armor change Server::getInstance()->getPluginManager()->callEvent($ev = new EntityArmorChangeEvent($this->getHolder(), $old, $item, $index)); @@ -441,7 +442,7 @@ class PlayerInventory extends BaseInventory{ public function setArmorContents(array $items){ for($i = 0; $i < 4; ++$i){ if(!isset($items[$i]) or !($items[$i] instanceof Item)){ - $items[$i] = Item::get(Item::AIR, 0, 0); + $items[$i] = ItemFactory::get(Item::AIR, 0, 0); } if($items[$i]->getId() === Item::AIR){ @@ -500,7 +501,7 @@ class PlayerInventory extends BaseInventory{ //Because PE is stupid and shows 9 less slots than you send it, give it 9 dummy slots so it shows all the REAL slots. for($i = $this->getSize(); $i < $this->getSize() + $this->getHotbarSize(); ++$i){ - $pk->slots[$i] = Item::get(Item::AIR, 0, 0); + $pk->slots[$i] = ItemFactory::get(Item::AIR, 0, 0); } foreach($target as $player){ diff --git a/src/pocketmine/inventory/ShapedRecipe.php b/src/pocketmine/inventory/ShapedRecipe.php index 5009af261e..cb3aa37a9c 100644 --- a/src/pocketmine/inventory/ShapedRecipe.php +++ b/src/pocketmine/inventory/ShapedRecipe.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\inventory; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\math\Vector2; use pocketmine\Server; use pocketmine\utils\UUID; @@ -141,7 +142,7 @@ class ShapedRecipe implements Recipe{ if($ingredient !== null){ $ingredients[$y][$x] = clone $ingredient; }else{ - $ingredients[$y][$x] = Item::get(Item::AIR); + $ingredients[$y][$x] = ItemFactory::get(Item::AIR); } } } @@ -156,7 +157,7 @@ class ShapedRecipe implements Recipe{ * @return Item */ public function getIngredient(int $x, int $y) : Item{ - return $this->ingredients[$y][$x] ?? Item::get(Item::AIR); + return $this->ingredients[$y][$x] ?? ItemFactory::get(Item::AIR); } /** diff --git a/src/pocketmine/item/BeetrootSoup.php b/src/pocketmine/item/BeetrootSoup.php index 4054a23a2a..0b0f628567 100644 --- a/src/pocketmine/item/BeetrootSoup.php +++ b/src/pocketmine/item/BeetrootSoup.php @@ -42,6 +42,6 @@ class BeetrootSoup extends Food{ } public function getResidue(){ - return Item::get(Item::BOWL); + return ItemFactory::get(Item::BOWL); } } \ No newline at end of file diff --git a/src/pocketmine/item/Food.php b/src/pocketmine/item/Food.php index 48207d9e0c..6681294430 100644 --- a/src/pocketmine/item/Food.php +++ b/src/pocketmine/item/Food.php @@ -40,7 +40,7 @@ abstract class Food extends Item implements FoodSource{ public function getResidue(){ if($this->getCount() === 1){ - return Item::get(0); + return ItemFactory::get(0); }else{ $new = clone $this; $new->count--; diff --git a/src/pocketmine/item/Item.php b/src/pocketmine/item/Item.php index 498c03018b..08a467df45 100644 --- a/src/pocketmine/item/Item.php +++ b/src/pocketmine/item/Item.php @@ -76,185 +76,35 @@ class Item implements ItemIds, \JsonSerializable{ return self::$cachedParser->write(); } - /** @var \SplFixedArray */ - public static $list = null; - /** @var Block|null */ - protected $block; - /** @var int */ - protected $id; - /** @var int */ - protected $meta; - /** @var string */ - private $tags = ""; - /** @var CompoundTag|null */ - private $cachedNBT = null; - /** @var int */ - public $count; - /** @var string */ - protected $name; + /** + * @param int $id + * @param int $meta + * @param int $count + * @param CompoundTag|string $tags + * + * @return Item + */ - public static function init(){ - if(self::$list === null){ - self::$list = new \SplFixedArray(65536); - - self::$list[self::IRON_SHOVEL] = IronShovel::class; - self::$list[self::IRON_PICKAXE] = IronPickaxe::class; - self::$list[self::IRON_AXE] = IronAxe::class; - self::$list[self::FLINT_STEEL] = FlintSteel::class; - self::$list[self::APPLE] = Apple::class; - self::$list[self::BOW] = Bow::class; - self::$list[self::ARROW] = Arrow::class; - self::$list[self::COAL] = Coal::class; - self::$list[self::DIAMOND] = Diamond::class; - self::$list[self::IRON_INGOT] = IronIngot::class; - self::$list[self::GOLD_INGOT] = GoldIngot::class; - self::$list[self::IRON_SWORD] = IronSword::class; - self::$list[self::WOODEN_SWORD] = WoodenSword::class; - self::$list[self::WOODEN_SHOVEL] = WoodenShovel::class; - self::$list[self::WOODEN_PICKAXE] = WoodenPickaxe::class; - self::$list[self::WOODEN_AXE] = WoodenAxe::class; - self::$list[self::STONE_SWORD] = StoneSword::class; - self::$list[self::STONE_SHOVEL] = StoneShovel::class; - self::$list[self::STONE_PICKAXE] = StonePickaxe::class; - self::$list[self::STONE_AXE] = StoneAxe::class; - self::$list[self::DIAMOND_SWORD] = DiamondSword::class; - self::$list[self::DIAMOND_SHOVEL] = DiamondShovel::class; - self::$list[self::DIAMOND_PICKAXE] = DiamondPickaxe::class; - self::$list[self::DIAMOND_AXE] = DiamondAxe::class; - self::$list[self::STICK] = Stick::class; - self::$list[self::BOWL] = Bowl::class; - self::$list[self::MUSHROOM_STEW] = MushroomStew::class; - self::$list[self::GOLDEN_SWORD] = GoldSword::class; - self::$list[self::GOLDEN_SHOVEL] = GoldShovel::class; - self::$list[self::GOLDEN_PICKAXE] = GoldPickaxe::class; - self::$list[self::GOLDEN_AXE] = GoldAxe::class; - self::$list[self::STRING] = StringItem::class; - self::$list[self::FEATHER] = Feather::class; - self::$list[self::GUNPOWDER] = Gunpowder::class; - self::$list[self::WOODEN_HOE] = WoodenHoe::class; - self::$list[self::STONE_HOE] = StoneHoe::class; - self::$list[self::IRON_HOE] = IronHoe::class; - self::$list[self::DIAMOND_HOE] = DiamondHoe::class; - self::$list[self::GOLDEN_HOE] = GoldHoe::class; - self::$list[self::WHEAT_SEEDS] = WheatSeeds::class; - self::$list[self::WHEAT] = Wheat::class; - self::$list[self::BREAD] = Bread::class; - self::$list[self::LEATHER_CAP] = LeatherCap::class; - self::$list[self::LEATHER_TUNIC] = LeatherTunic::class; - self::$list[self::LEATHER_PANTS] = LeatherPants::class; - self::$list[self::LEATHER_BOOTS] = LeatherBoots::class; - self::$list[self::CHAINMAIL_HELMET] = ChainHelmet::class; - self::$list[self::CHAINMAIL_CHESTPLATE] = ChainChestplate::class; - self::$list[self::CHAINMAIL_LEGGINGS] = ChainLeggings::class; - self::$list[self::CHAINMAIL_BOOTS] = ChainBoots::class; - self::$list[self::IRON_HELMET] = IronHelmet::class; - self::$list[self::IRON_CHESTPLATE] = IronChestplate::class; - self::$list[self::IRON_LEGGINGS] = IronLeggings::class; - self::$list[self::IRON_BOOTS] = IronBoots::class; - self::$list[self::DIAMOND_HELMET] = DiamondHelmet::class; - self::$list[self::DIAMOND_CHESTPLATE] = DiamondChestplate::class; - self::$list[self::DIAMOND_LEGGINGS] = DiamondLeggings::class; - self::$list[self::DIAMOND_BOOTS] = DiamondBoots::class; - self::$list[self::GOLDEN_HELMET] = GoldHelmet::class; - self::$list[self::GOLDEN_CHESTPLATE] = GoldChestplate::class; - self::$list[self::GOLDEN_LEGGINGS] = GoldLeggings::class; - self::$list[self::GOLDEN_BOOTS] = GoldBoots::class; - self::$list[self::FLINT] = Flint::class; - self::$list[self::RAW_PORKCHOP] = RawPorkchop::class; - self::$list[self::COOKED_PORKCHOP] = CookedPorkchop::class; - self::$list[self::PAINTING] = Painting::class; - self::$list[self::GOLDEN_APPLE] = GoldenApple::class; - self::$list[self::SIGN] = Sign::class; - self::$list[self::WOODEN_DOOR] = WoodenDoor::class; - self::$list[self::BUCKET] = Bucket::class; - - self::$list[self::MINECART] = Minecart::class; - - self::$list[self::IRON_DOOR] = IronDoor::class; - self::$list[self::REDSTONE] = Redstone::class; - self::$list[self::SNOWBALL] = Snowball::class; - self::$list[self::BOAT] = Boat::class; - self::$list[self::LEATHER] = Leather::class; - - self::$list[self::BRICK] = Brick::class; - self::$list[self::CLAY] = Clay::class; - self::$list[self::SUGARCANE] = Sugarcane::class; - self::$list[self::PAPER] = Paper::class; - self::$list[self::BOOK] = Book::class; - self::$list[self::SLIMEBALL] = Slimeball::class; - - self::$list[self::EGG] = Egg::class; - self::$list[self::COMPASS] = Compass::class; - self::$list[self::FISHING_ROD] = FishingRod::class; - self::$list[self::CLOCK] = Clock::class; - self::$list[self::GLOWSTONE_DUST] = GlowstoneDust::class; - self::$list[self::RAW_FISH] = Fish::class; - self::$list[self::COOKED_FISH] = CookedFish::class; - self::$list[self::DYE] = Dye::class; - self::$list[self::BONE] = Bone::class; - self::$list[self::SUGAR] = Sugar::class; - self::$list[self::CAKE] = Cake::class; - self::$list[self::BED] = Bed::class; - - self::$list[self::COOKIE] = Cookie::class; - - self::$list[self::SHEARS] = Shears::class; - self::$list[self::MELON] = Melon::class; - self::$list[self::PUMPKIN_SEEDS] = PumpkinSeeds::class; - self::$list[self::MELON_SEEDS] = MelonSeeds::class; - self::$list[self::RAW_BEEF] = RawBeef::class; - self::$list[self::STEAK] = Steak::class; - self::$list[self::RAW_CHICKEN] = RawChicken::class; - self::$list[self::COOKED_CHICKEN] = CookedChicken::class; - - self::$list[self::GOLD_NUGGET] = GoldNugget::class; - self::$list[self::NETHER_WART] = NetherWart::class; - self::$list[self::POTION] = Potion::class; - self::$list[self::GLASS_BOTTLE] = GlassBottle::class; - self::$list[self::SPIDER_EYE] = SpiderEye::class; - self::$list[self::FERMENTED_SPIDER_EYE] = FermentedSpiderEye::class; - self::$list[self::BLAZE_POWDER] = BlazePowder::class; - self::$list[self::MAGMA_CREAM] = MagmaCream::class; - self::$list[self::BREWING_STAND] = BrewingStand::class; - - self::$list[self::GLISTERING_MELON] = GlisteringMelon::class; - self::$list[self::SPAWN_EGG] = SpawnEgg::class; - - self::$list[self::EMERALD] = Emerald::class; - self::$list[self::ITEM_FRAME] = ItemFrame::class; - self::$list[self::FLOWER_POT] = FlowerPot::class; - self::$list[self::CARROT] = Carrot::class; - self::$list[self::POTATO] = Potato::class; - self::$list[self::BAKED_POTATO] = BakedPotato::class; - - self::$list[self::GOLDEN_CARROT] = GoldenCarrot::class; - self::$list[self::SKULL] = Skull::class; - - self::$list[self::NETHER_STAR] = NetherStar::class; - self::$list[self::PUMPKIN_PIE] = PumpkinPie::class; - - self::$list[self::NETHER_BRICK] = NetherBrick::class; - self::$list[self::NETHER_QUARTZ] = NetherQuartz::class; - - self::$list[self::PRISMARINE_SHARD] = PrismarineShard::class; - - self::$list[self::COOKED_RABBIT] = CookedRabbit::class; - - self::$list[self::PRISMARINE_CRYSTALS] = PrismarineCrystals::class; - - self::$list[self::BEETROOT] = Beetroot::class; - self::$list[self::BEETROOT_SEEDS] = BeetrootSeeds::class; - self::$list[self::BEETROOT_SOUP] = BeetrootSoup::class; - - self::$list[self::ENCHANTED_GOLDEN_APPLE] = GoldenAppleEnchanted::class; - } - - self::initCreativeItems(); + public static function get(int $id, int $meta = 0, int $count = 1, $tags = "") : Item{ + return ItemFactory::get($id, $meta, $count, $tags); } + /** + * @param string $str + * @param bool $multiple + * + * @return Item[]|Item + */ + + public static function fromString(string $str, bool $multiple = false){ + return ItemFactory::fromString($str, $multiple); + } + + + /** @var Item[] */ private static $creative = []; - private static function initCreativeItems(){ + public static function initCreativeItems(){ self::clearCreativeItems(); $creativeItems = new Config(Server::getInstance()->getFilePath() . "src/pocketmine/resources/creativeitems.json", Config::JSON, []); @@ -316,67 +166,20 @@ class Item implements ItemIds, \JsonSerializable{ return -1; } - /** - * Returns an instance of the Item with the specified id, meta, count and NBT. - * - * @param int $id - * @param int $meta - * @param int $count - * @param CompoundTag|string $tags - * - * @return Item - */ - public static function get(int $id, int $meta = 0, int $count = 1, $tags = "") : Item{ - try{ - if($id < 256){ - return (new ItemBlock(BlockFactory::get($id, $meta), $meta, $count))->setCompoundTag($tags); - }else{ - $class = self::$list[$id]; - if($class === null){ - return (new Item($id, $meta, $count))->setCompoundTag($tags); - }else{ - return (new $class($meta, $count))->setCompoundTag($tags); - } - } - }catch(\RuntimeException $e){ - return (new Item($id, $meta, $count))->setCompoundTag($tags); - } - } - - /** - * @param string $str - * @param bool $multiple - * - * @return Item[]|Item - */ - public static function fromString(string $str, bool $multiple = false){ - if($multiple === true){ - $blocks = []; - foreach(explode(",", $str) as $b){ - $blocks[] = self::fromString($b, false); - } - - return $blocks; - }else{ - $b = explode(":", str_replace([" ", "minecraft:"], ["_", ""], trim($str))); - if(!isset($b[1])){ - $meta = 0; - }else{ - $meta = $b[1] & 0xFFFF; - } - - if(defined(Item::class . "::" . strtoupper($b[0]))){ - $item = self::get(constant(Item::class . "::" . strtoupper($b[0])), $meta); - if($item->getId() === self::AIR and strtoupper($b[0]) !== "AIR"){ - $item = self::get($b[0] & 0xFFFF, $meta); - } - }else{ - $item = self::get($b[0] & 0xFFFF, $meta); - } - - return $item; - } - } + /** @var Block|null */ + protected $block; + /** @var int */ + protected $id; + /** @var int */ + protected $meta; + /** @var string */ + private $tags = ""; + /** @var CompoundTag|null */ + private $cachedNBT = null; + /** @var int */ + public $count; + /** @var string */ + protected $name; /** * @param int $id @@ -1061,7 +864,7 @@ class Item implements ItemIds, \JsonSerializable{ * @return Item */ final public static function jsonDeserialize(array $data) : Item{ - return Item::get( + return ItemFactory::get( (int) $data["id"], (int) $data["damage"], (int) $data["count"], @@ -1105,16 +908,16 @@ class Item implements ItemIds, \JsonSerializable{ */ public static function nbtDeserialize(CompoundTag $tag) : Item{ if(!isset($tag->id) or !isset($tag->Count)){ - return Item::get(0); + return ItemFactory::get(0); } $count = Binary::unsignByte($tag->Count->getValue()); $meta = isset($tag->Damage) ? $tag->Damage->getValue() : 0; if($tag->id instanceof ShortTag){ - $item = Item::get($tag->id->getValue(), $meta, $count); + $item = ItemFactory::get($tag->id->getValue(), $meta, $count); }elseif($tag->id instanceof StringTag){ //PC item save format - $item = Item::fromString($tag->id->getValue()); + $item = ItemFactory::fromString($tag->id->getValue()); $item->setDamage($meta); $item->setCount($count); }else{ diff --git a/src/pocketmine/item/ItemFactory.php b/src/pocketmine/item/ItemFactory.php new file mode 100644 index 0000000000..f05f7915d7 --- /dev/null +++ b/src/pocketmine/item/ItemFactory.php @@ -0,0 +1,285 @@ +getId(); + if(!$override and self::$list[$id] !== null){ + throw new \RuntimeException("Trying to overwrite an already registered item"); + } + + self::$list[$id] = clone $item; + } + + /** + * Returns an instance of the Item with the specified id, meta, count and NBT. + * + * @param int $id + * @param int $meta + * @param int $count + * @param CompoundTag|string $tags + * + * @return Item + */ + public static function get(int $id, int $meta = 0, int $count = 1, $tags = "") : Item{ + try{ + if($id < 256){ + return (new ItemBlock(BlockFactory::get($id, $meta), $meta, $count))->setCompoundTag($tags); + }else{ + /** @var Item|null $item */ + $item = self::$list[$id]; + if($item === null){ + return (new Item($id, $meta, $count))->setCompoundTag($tags); + }else{ + $item = clone $item; + $item->setDamage($meta); + $item->setCount($count); + $item->setCompoundTag($tags); + + return $item; + } + } + }catch(\RuntimeException $e){ + return (new Item($id, $meta, $count))->setCompoundTag($tags); + } + } + + /** + * @param string $str + * @param bool $multiple + * + * @return Item[]|Item + */ + public static function fromString(string $str, bool $multiple = false){ + if($multiple === true){ + $blocks = []; + foreach(explode(",", $str) as $b){ + $blocks[] = self::fromString($b, false); + } + + return $blocks; + }else{ + $b = explode(":", str_replace([" ", "minecraft:"], ["_", ""], trim($str))); + if(!isset($b[1])){ + $meta = 0; + }else{ + $meta = $b[1] & 0xFFFF; + } + + if(defined(Item::class . "::" . strtoupper($b[0]))){ + $item = self::get(constant(Item::class . "::" . strtoupper($b[0])), $meta); + if($item->getId() === Item::AIR and strtoupper($b[0]) !== "AIR"){ + $item = self::get($b[0] & 0xFFFF, $meta); + } + }else{ + $item = self::get($b[0] & 0xFFFF, $meta); + } + + return $item; + } + } +} \ No newline at end of file diff --git a/src/pocketmine/item/MushroomStew.php b/src/pocketmine/item/MushroomStew.php index 5330c2ec7b..51929c5ec3 100644 --- a/src/pocketmine/item/MushroomStew.php +++ b/src/pocketmine/item/MushroomStew.php @@ -41,6 +41,6 @@ class MushroomStew extends Food{ } public function getResidue(){ - return Item::get(Item::BOWL); + return ItemFactory::get(Item::BOWL); } } diff --git a/src/pocketmine/level/Explosion.php b/src/pocketmine/level/Explosion.php index 73df0c067c..bdbe310e38 100644 --- a/src/pocketmine/level/Explosion.php +++ b/src/pocketmine/level/Explosion.php @@ -33,6 +33,7 @@ use pocketmine\event\entity\EntityDamageByEntityEvent; use pocketmine\event\entity\EntityDamageEvent; use pocketmine\event\entity\EntityExplodeEvent; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\level\particle\HugeExplodeSeedParticle; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Math; @@ -192,7 +193,7 @@ class Explosion{ } - $air = Item::get(Item::AIR); + $air = ItemFactory::get(Item::AIR); foreach($this->affectedBlocks as $block){ if($block instanceof TNT){ diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index b7eeff4797..b22f2756e1 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -66,6 +66,7 @@ use pocketmine\event\player\PlayerInteractEvent; use pocketmine\event\Timings; use pocketmine\inventory\InventoryHolder; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\level\format\Chunk; use pocketmine\level\format\io\BaseLevelProvider; use pocketmine\level\format\io\LevelProvider; @@ -1585,7 +1586,7 @@ class Level implements ChunkManager, Metadatable{ $target = $this->getBlock($vector); if($item === null){ - $item = Item::get(Item::AIR, 0, 0); + $item = ItemFactory::get(Item::AIR, 0, 0); } if($player !== null){ @@ -1607,7 +1608,7 @@ class Level implements ChunkManager, Metadatable{ if($tag instanceof ListTag){ foreach($tag as $v){ if($v instanceof StringTag){ - $entry = Item::fromString($v->getValue()); + $entry = ItemFactory::fromString($v->getValue()); if($entry->getId() > 0 and $entry->getBlock() !== null and $entry->getBlock()->getId() === $target->getId()){ $canBreak = true; break; @@ -1685,7 +1686,7 @@ class Level implements ChunkManager, Metadatable{ if($item !== null){ $item->useOn($target); if($item->isTool() and $item->getDamage() >= $item->getMaxDurability()){ - $item = Item::get(Item::AIR, 0, 0); + $item = ItemFactory::get(Item::AIR, 0, 0); } } @@ -1745,7 +1746,7 @@ class Level implements ChunkManager, Metadatable{ if($tag instanceof ListTag){ foreach($tag as $v){ if($v instanceof StringTag){ - $entry = Item::fromString($v->getValue()); + $entry = ItemFactory::fromString($v->getValue()); if($entry->getId() > 0 and $entry->getBlock() !== null and $entry->getBlock()->getId() === $target->getId()){ $canPlace = true; break; @@ -1766,7 +1767,7 @@ class Level implements ChunkManager, Metadatable{ if(!$player->isSneaking() and $item->onActivate($this, $player, $block, $target, $face, $facePos)){ if($item->getCount() <= 0){ - $item = Item::get(Item::AIR, 0, 0); + $item = ItemFactory::get(Item::AIR, 0, 0); return true; } @@ -1842,7 +1843,7 @@ class Level implements ChunkManager, Metadatable{ $item->setCount($item->getCount() - 1); if($item->getCount() <= 0){ - $item = Item::get(Item::AIR, 0, 0); + $item = ItemFactory::get(Item::AIR, 0, 0); } return true; diff --git a/src/pocketmine/level/generator/Flat.php b/src/pocketmine/level/generator/Flat.php index f8914d81ae..2b2e5bcfbe 100644 --- a/src/pocketmine/level/generator/Flat.php +++ b/src/pocketmine/level/generator/Flat.php @@ -25,7 +25,7 @@ namespace pocketmine\level\generator; use pocketmine\block\Block; use pocketmine\block\BlockFactory; -use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\level\ChunkManager; use pocketmine\level\format\Chunk; use pocketmine\level\generator\object\OreType; @@ -84,7 +84,7 @@ class Flat extends Generator{ preg_match_all('#^(([0-9]*x|)([0-9]{1,3})(|:[0-9]{0,2}))$#m', str_replace(",", "\n", $layers), $matches); $y = 0; foreach($matches[3] as $i => $b){ - $b = Item::fromString($b . $matches[4][$i]); + $b = ItemFactory::fromString($b . $matches[4][$i]); $cnt = $matches[2][$i] === "" ? 1 : (int) $matches[2][$i]; for($cY = $y, $y += $cnt; $cY < $y; ++$cY){ $result[$cY] = [$b->getId(), $b->getDamage()]; diff --git a/src/pocketmine/network/mcpe/protocol/DataPacket.php b/src/pocketmine/network/mcpe/protocol/DataPacket.php index dd70a4e909..6e9b7a04eb 100644 --- a/src/pocketmine/network/mcpe/protocol/DataPacket.php +++ b/src/pocketmine/network/mcpe/protocol/DataPacket.php @@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\entity\Attribute; use pocketmine\entity\Entity; -use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\network\mcpe\NetworkSession; use pocketmine\utils\BinaryStream; use pocketmine\utils\Utils; @@ -209,7 +209,7 @@ abstract class DataPacket extends BinaryStream{ break; case Entity::DATA_TYPE_SLOT: //TODO: change this implementation (use objects) - $this->putSlot(Item::get($d[1][0], $d[1][2], $d[1][1])); //ID, damage, count + $this->putSlot(ItemFactory::get($d[1][0], $d[1][2], $d[1][1])); //ID, damage, count break; case Entity::DATA_TYPE_POS: //TODO: change this implementation (use objects) diff --git a/src/pocketmine/tile/Chest.php b/src/pocketmine/tile/Chest.php index fb66179a42..fc3e472f3f 100644 --- a/src/pocketmine/tile/Chest.php +++ b/src/pocketmine/tile/Chest.php @@ -27,6 +27,7 @@ use pocketmine\inventory\ChestInventory; use pocketmine\inventory\DoubleChestInventory; use pocketmine\inventory\InventoryHolder; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\level\Level; use pocketmine\math\Vector3; use pocketmine\nbt\NBT; @@ -113,7 +114,7 @@ class Chest extends Spawnable implements InventoryHolder, Container, Nameable{ public function getItem(int $index) : Item{ $i = $this->getSlotIndex($index); if($i < 0){ - return Item::get(Item::AIR, 0, 0); + return ItemFactory::get(Item::AIR, 0, 0); }else{ return Item::nbtDeserialize($this->namedtag->Items[$i]); } diff --git a/src/pocketmine/tile/FlowerPot.php b/src/pocketmine/tile/FlowerPot.php index f5950186c3..cf60978c0a 100644 --- a/src/pocketmine/tile/FlowerPot.php +++ b/src/pocketmine/tile/FlowerPot.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\tile; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\level\Level; use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\IntTag; @@ -65,7 +66,7 @@ class FlowerPot extends Spawnable{ } public function getItem() : Item{ - return Item::get($this->namedtag->item->getValue(), $this->namedtag->mData->getValue(), 1); + return ItemFactory::get($this->namedtag->item->getValue(), $this->namedtag->mData->getValue(), 1); } public function setItem(Item $item){ @@ -75,7 +76,7 @@ class FlowerPot extends Spawnable{ } public function removeItem(){ - $this->setItem(Item::get(Item::AIR)); + $this->setItem(ItemFactory::get(Item::AIR)); } public function isEmpty() : bool{ diff --git a/src/pocketmine/tile/Furnace.php b/src/pocketmine/tile/Furnace.php index 54647bbaf3..9984e7bb2f 100644 --- a/src/pocketmine/tile/Furnace.php +++ b/src/pocketmine/tile/Furnace.php @@ -31,6 +31,7 @@ use pocketmine\inventory\FurnaceInventory; use pocketmine\inventory\FurnaceRecipe; use pocketmine\inventory\InventoryHolder; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\level\Level; use pocketmine\nbt\NBT; use pocketmine\nbt\tag\CompoundTag; @@ -141,7 +142,7 @@ class Furnace extends Spawnable implements InventoryHolder, Container, Nameable{ public function getItem(int $index) : Item{ $i = $this->getSlotIndex($index); if($i < 0){ - return Item::get(Item::AIR, 0, 0); + return ItemFactory::get(Item::AIR, 0, 0); }else{ return Item::nbtDeserialize($this->namedtag->Items[$i]); } @@ -198,7 +199,7 @@ class Furnace extends Spawnable implements InventoryHolder, Container, Nameable{ if($this->namedtag->BurnTime->getValue() > 0 and $ev->isBurning()){ $fuel->setCount($fuel->getCount() - 1); if($fuel->getCount() === 0){ - $fuel = Item::get(Item::AIR, 0, 0); + $fuel = ItemFactory::get(Item::AIR, 0, 0); } $this->inventory->setFuel($fuel); } @@ -230,7 +231,7 @@ class Furnace extends Spawnable implements InventoryHolder, Container, Nameable{ if($smelt instanceof FurnaceRecipe and $canSmelt){ $this->namedtag->CookTime->setValue($this->namedtag->CookTime->getValue() + 1); if($this->namedtag->CookTime->getValue() >= 200){ //10 seconds - $product = Item::get($smelt->getResult()->getId(), $smelt->getResult()->getDamage(), $product->getCount() + 1); + $product = ItemFactory::get($smelt->getResult()->getId(), $smelt->getResult()->getDamage(), $product->getCount() + 1); $this->server->getPluginManager()->callEvent($ev = new FurnaceSmeltEvent($this, $raw, $product)); @@ -238,7 +239,7 @@ class Furnace extends Spawnable implements InventoryHolder, Container, Nameable{ $this->inventory->setResult($ev->getResult()); $raw->setCount($raw->getCount() - 1); if($raw->getCount() === 0){ - $raw = Item::get(Item::AIR, 0, 0); + $raw = ItemFactory::get(Item::AIR, 0, 0); } $this->inventory->setSmelting($raw); } diff --git a/src/pocketmine/tile/ItemFrame.php b/src/pocketmine/tile/ItemFrame.php index 388c8efe90..2c955fc6d0 100644 --- a/src/pocketmine/tile/ItemFrame.php +++ b/src/pocketmine/tile/ItemFrame.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\tile; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\level\Level; use pocketmine\nbt\tag\ByteTag; use pocketmine\nbt\tag\CompoundTag; @@ -51,7 +52,7 @@ class ItemFrame extends Spawnable{ if(isset($this->namedtag->Item)){ return Item::nbtDeserialize($this->namedtag->Item); }else{ - return Item::get(Item::AIR); + return ItemFactory::get(Item::AIR); } } diff --git a/src/pocketmine/utils/BinaryStream.php b/src/pocketmine/utils/BinaryStream.php index 74e34a0940..2091c1e121 100644 --- a/src/pocketmine/utils/BinaryStream.php +++ b/src/pocketmine/utils/BinaryStream.php @@ -26,6 +26,7 @@ namespace pocketmine\utils; #include use pocketmine\item\Item; +use pocketmine\item\ItemFactory; class BinaryStream{ @@ -248,7 +249,7 @@ class BinaryStream{ public function getSlot() : Item{ $id = $this->getVarInt(); if($id <= 0){ - return Item::get(0, 0, 0); + return ItemFactory::get(0, 0, 0); } $auxValue = $this->getVarInt(); @@ -281,7 +282,7 @@ class BinaryStream{ } } - return Item::get($id, $data, $cnt, $nbt); + return ItemFactory::get($id, $data, $cnt, $nbt); } diff --git a/tests/plugins/PocketMine-TesterPlugin b/tests/plugins/PocketMine-TesterPlugin index 5867bf4d03..d4f3d38e42 160000 --- a/tests/plugins/PocketMine-TesterPlugin +++ b/tests/plugins/PocketMine-TesterPlugin @@ -1 +1 @@ -Subproject commit 5867bf4d03af74a2f667ae1c867200487f275f0f +Subproject commit d4f3d38e42b6962b85fcd72dcf52a3e2650005a6 From 592ce3c9e96ba7b893c005ba75adc42696f6eff4 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 21 Aug 2017 19:02:30 +0100 Subject: [PATCH 08/14] Adding some missed commands typehints and documentation --- .../command/defaults/BanCommand.php | 2 +- .../command/defaults/BanIpCommand.php | 4 +-- .../command/defaults/BanListCommand.php | 2 +- .../defaults/DefaultGamemodeCommand.php | 2 +- .../command/defaults/DeopCommand.php | 2 +- .../command/defaults/DifficultyCommand.php | 2 +- .../command/defaults/DumpMemoryCommand.php | 2 +- .../command/defaults/EffectCommand.php | 2 +- .../command/defaults/EnchantCommand.php | 2 +- .../command/defaults/GamemodeCommand.php | 2 +- .../defaults/GarbageCollectorCommand.php | 2 +- .../command/defaults/GiveCommand.php | 2 +- .../command/defaults/HelpCommand.php | 2 +- .../command/defaults/KickCommand.php | 2 +- .../command/defaults/KillCommand.php | 2 +- .../command/defaults/ListCommand.php | 2 +- src/pocketmine/command/defaults/MeCommand.php | 2 +- src/pocketmine/command/defaults/OpCommand.php | 2 +- .../command/defaults/PardonCommand.php | 2 +- .../command/defaults/PardonIpCommand.php | 2 +- .../command/defaults/ParticleCommand.php | 5 ++- .../command/defaults/PluginsCommand.php | 2 +- .../command/defaults/ReloadCommand.php | 2 +- .../command/defaults/SaveCommand.php | 2 +- .../command/defaults/SaveOffCommand.php | 2 +- .../command/defaults/SaveOnCommand.php | 2 +- .../command/defaults/SayCommand.php | 2 +- .../command/defaults/SeedCommand.php | 2 +- .../command/defaults/SetWorldSpawnCommand.php | 2 +- .../command/defaults/SpawnpointCommand.php | 2 +- .../command/defaults/StatusCommand.php | 2 +- .../command/defaults/StopCommand.php | 2 +- .../command/defaults/TeleportCommand.php | 2 +- .../command/defaults/TellCommand.php | 2 +- .../command/defaults/TimeCommand.php | 2 +- .../command/defaults/TimingsCommand.php | 2 +- .../command/defaults/TitleCommand.php | 2 +- .../defaults/TransferServerCommand.php | 2 +- .../command/defaults/VanillaCommand.php | 35 +++++++++++++++---- .../command/defaults/VersionCommand.php | 2 +- .../command/defaults/WhitelistCommand.php | 4 +-- 41 files changed, 71 insertions(+), 51 deletions(-) diff --git a/src/pocketmine/command/defaults/BanCommand.php b/src/pocketmine/command/defaults/BanCommand.php index 4ace5acb60..6eb24ad1db 100644 --- a/src/pocketmine/command/defaults/BanCommand.php +++ b/src/pocketmine/command/defaults/BanCommand.php @@ -31,7 +31,7 @@ use pocketmine\Player; class BanCommand extends VanillaCommand{ - public function __construct($name){ + public function __construct(string $name){ parent::__construct( $name, "%pocketmine.command.ban.player.description", diff --git a/src/pocketmine/command/defaults/BanIpCommand.php b/src/pocketmine/command/defaults/BanIpCommand.php index b6ccb496ca..add40c4829 100644 --- a/src/pocketmine/command/defaults/BanIpCommand.php +++ b/src/pocketmine/command/defaults/BanIpCommand.php @@ -31,7 +31,7 @@ use pocketmine\Player; class BanIpCommand extends VanillaCommand{ - public function __construct($name){ + public function __construct(string $name){ parent::__construct( $name, "%pocketmine.command.ban.ip.description", @@ -71,7 +71,7 @@ class BanIpCommand extends VanillaCommand{ return true; } - private function processIPBan($ip, CommandSender $sender, $reason){ + private function processIPBan(string $ip, CommandSender $sender, string $reason){ $sender->getServer()->getIPBans()->addBan($ip, $reason, null, $sender->getName()); foreach($sender->getServer()->getOnlinePlayers() as $player){ diff --git a/src/pocketmine/command/defaults/BanListCommand.php b/src/pocketmine/command/defaults/BanListCommand.php index b609abf3a2..064c777f7d 100644 --- a/src/pocketmine/command/defaults/BanListCommand.php +++ b/src/pocketmine/command/defaults/BanListCommand.php @@ -30,7 +30,7 @@ use pocketmine\permission\BanEntry; class BanListCommand extends VanillaCommand{ - public function __construct($name){ + public function __construct(string $name){ parent::__construct( $name, "%pocketmine.command.banlist.description", diff --git a/src/pocketmine/command/defaults/DefaultGamemodeCommand.php b/src/pocketmine/command/defaults/DefaultGamemodeCommand.php index be4539aa2b..3bd0fd6170 100644 --- a/src/pocketmine/command/defaults/DefaultGamemodeCommand.php +++ b/src/pocketmine/command/defaults/DefaultGamemodeCommand.php @@ -30,7 +30,7 @@ use pocketmine\Server; class DefaultGamemodeCommand extends VanillaCommand{ - public function __construct($name){ + public function __construct(string $name){ parent::__construct( $name, "%pocketmine.command.defaultgamemode.description", diff --git a/src/pocketmine/command/defaults/DeopCommand.php b/src/pocketmine/command/defaults/DeopCommand.php index 9f71fb91a5..c8523921f2 100644 --- a/src/pocketmine/command/defaults/DeopCommand.php +++ b/src/pocketmine/command/defaults/DeopCommand.php @@ -32,7 +32,7 @@ use pocketmine\utils\TextFormat; class DeopCommand extends VanillaCommand{ - public function __construct($name){ + public function __construct(string $name){ parent::__construct( $name, "%pocketmine.command.deop.description", diff --git a/src/pocketmine/command/defaults/DifficultyCommand.php b/src/pocketmine/command/defaults/DifficultyCommand.php index b11832f348..5b8cae9d6e 100644 --- a/src/pocketmine/command/defaults/DifficultyCommand.php +++ b/src/pocketmine/command/defaults/DifficultyCommand.php @@ -32,7 +32,7 @@ use pocketmine\Server; class DifficultyCommand extends VanillaCommand{ - public function __construct($name){ + public function __construct(string $name){ parent::__construct( $name, "%pocketmine.command.difficulty.description", diff --git a/src/pocketmine/command/defaults/DumpMemoryCommand.php b/src/pocketmine/command/defaults/DumpMemoryCommand.php index 593533ea15..ccdd3055ab 100644 --- a/src/pocketmine/command/defaults/DumpMemoryCommand.php +++ b/src/pocketmine/command/defaults/DumpMemoryCommand.php @@ -29,7 +29,7 @@ class DumpMemoryCommand extends VanillaCommand{ private static $executions = 0; - public function __construct($name){ + public function __construct(string $name){ parent::__construct( $name, "Dumps the memory", diff --git a/src/pocketmine/command/defaults/EffectCommand.php b/src/pocketmine/command/defaults/EffectCommand.php index 51b185d69e..6efcbb5d06 100644 --- a/src/pocketmine/command/defaults/EffectCommand.php +++ b/src/pocketmine/command/defaults/EffectCommand.php @@ -31,7 +31,7 @@ use pocketmine\utils\TextFormat; class EffectCommand extends VanillaCommand{ - public function __construct($name){ + public function __construct(string $name){ parent::__construct( $name, "%pocketmine.command.effect.description", diff --git a/src/pocketmine/command/defaults/EnchantCommand.php b/src/pocketmine/command/defaults/EnchantCommand.php index 40fcf6fdf4..9c1051f1c6 100644 --- a/src/pocketmine/command/defaults/EnchantCommand.php +++ b/src/pocketmine/command/defaults/EnchantCommand.php @@ -31,7 +31,7 @@ use pocketmine\utils\TextFormat; class EnchantCommand extends VanillaCommand{ - public function __construct($name){ + public function __construct(string $name){ parent::__construct( $name, "%pocketmine.command.enchant.description", diff --git a/src/pocketmine/command/defaults/GamemodeCommand.php b/src/pocketmine/command/defaults/GamemodeCommand.php index 65c245f33d..0efc305abe 100644 --- a/src/pocketmine/command/defaults/GamemodeCommand.php +++ b/src/pocketmine/command/defaults/GamemodeCommand.php @@ -33,7 +33,7 @@ use pocketmine\utils\TextFormat; class GamemodeCommand extends VanillaCommand{ - public function __construct($name){ + public function __construct(string $name){ parent::__construct( $name, "%pocketmine.command.gamemode.description", diff --git a/src/pocketmine/command/defaults/GarbageCollectorCommand.php b/src/pocketmine/command/defaults/GarbageCollectorCommand.php index 526482d858..eca388788f 100644 --- a/src/pocketmine/command/defaults/GarbageCollectorCommand.php +++ b/src/pocketmine/command/defaults/GarbageCollectorCommand.php @@ -28,7 +28,7 @@ use pocketmine\utils\TextFormat; class GarbageCollectorCommand extends VanillaCommand{ - public function __construct($name){ + public function __construct(string $name){ parent::__construct( $name, "%pocketmine.command.gc.description", diff --git a/src/pocketmine/command/defaults/GiveCommand.php b/src/pocketmine/command/defaults/GiveCommand.php index 0e70368141..0124e87670 100644 --- a/src/pocketmine/command/defaults/GiveCommand.php +++ b/src/pocketmine/command/defaults/GiveCommand.php @@ -35,7 +35,7 @@ use pocketmine\utils\TextFormat; class GiveCommand extends VanillaCommand{ - public function __construct($name){ + public function __construct(string $name){ parent::__construct( $name, "%pocketmine.command.give.description", diff --git a/src/pocketmine/command/defaults/HelpCommand.php b/src/pocketmine/command/defaults/HelpCommand.php index 8542847a93..bc7ca13532 100644 --- a/src/pocketmine/command/defaults/HelpCommand.php +++ b/src/pocketmine/command/defaults/HelpCommand.php @@ -30,7 +30,7 @@ use pocketmine\utils\TextFormat; class HelpCommand extends VanillaCommand{ - public function __construct($name){ + public function __construct(string $name){ parent::__construct( $name, "%pocketmine.command.help.description", diff --git a/src/pocketmine/command/defaults/KickCommand.php b/src/pocketmine/command/defaults/KickCommand.php index 7368b42761..543d6f915b 100644 --- a/src/pocketmine/command/defaults/KickCommand.php +++ b/src/pocketmine/command/defaults/KickCommand.php @@ -32,7 +32,7 @@ use pocketmine\utils\TextFormat; class KickCommand extends VanillaCommand{ - public function __construct($name){ + public function __construct(string $name){ parent::__construct( $name, "%pocketmine.command.kick.description", diff --git a/src/pocketmine/command/defaults/KillCommand.php b/src/pocketmine/command/defaults/KillCommand.php index 1e772ae2d1..74ee5ca600 100644 --- a/src/pocketmine/command/defaults/KillCommand.php +++ b/src/pocketmine/command/defaults/KillCommand.php @@ -33,7 +33,7 @@ use pocketmine\utils\TextFormat; class KillCommand extends VanillaCommand{ - public function __construct($name){ + public function __construct(string $name){ parent::__construct( $name, "%pocketmine.command.kill.description", diff --git a/src/pocketmine/command/defaults/ListCommand.php b/src/pocketmine/command/defaults/ListCommand.php index edc4839824..56526eb5b3 100644 --- a/src/pocketmine/command/defaults/ListCommand.php +++ b/src/pocketmine/command/defaults/ListCommand.php @@ -29,7 +29,7 @@ use pocketmine\Player; class ListCommand extends VanillaCommand{ - public function __construct($name){ + public function __construct(string $name){ parent::__construct( $name, "%pocketmine.command.list.description", diff --git a/src/pocketmine/command/defaults/MeCommand.php b/src/pocketmine/command/defaults/MeCommand.php index 380b7f93b9..16fbc5ec7c 100644 --- a/src/pocketmine/command/defaults/MeCommand.php +++ b/src/pocketmine/command/defaults/MeCommand.php @@ -31,7 +31,7 @@ use pocketmine\utils\TextFormat; class MeCommand extends VanillaCommand{ - public function __construct($name){ + public function __construct(string $name){ parent::__construct( $name, "%pocketmine.command.me.description", diff --git a/src/pocketmine/command/defaults/OpCommand.php b/src/pocketmine/command/defaults/OpCommand.php index 0000f84100..bec3ba92f5 100644 --- a/src/pocketmine/command/defaults/OpCommand.php +++ b/src/pocketmine/command/defaults/OpCommand.php @@ -32,7 +32,7 @@ use pocketmine\utils\TextFormat; class OpCommand extends VanillaCommand{ - public function __construct($name){ + public function __construct(string $name){ parent::__construct( $name, "%pocketmine.command.op.description", diff --git a/src/pocketmine/command/defaults/PardonCommand.php b/src/pocketmine/command/defaults/PardonCommand.php index c0b97ae7d6..406745d6c3 100644 --- a/src/pocketmine/command/defaults/PardonCommand.php +++ b/src/pocketmine/command/defaults/PardonCommand.php @@ -30,7 +30,7 @@ use pocketmine\event\TranslationContainer; class PardonCommand extends VanillaCommand{ - public function __construct($name){ + public function __construct(string $name){ parent::__construct( $name, "%pocketmine.command.unban.player.description", diff --git a/src/pocketmine/command/defaults/PardonIpCommand.php b/src/pocketmine/command/defaults/PardonIpCommand.php index cfe7571edb..18e9c66793 100644 --- a/src/pocketmine/command/defaults/PardonIpCommand.php +++ b/src/pocketmine/command/defaults/PardonIpCommand.php @@ -30,7 +30,7 @@ use pocketmine\event\TranslationContainer; class PardonIpCommand extends VanillaCommand{ - public function __construct($name){ + public function __construct(string $name){ parent::__construct( $name, "%pocketmine.command.unban.ip.description", diff --git a/src/pocketmine/command/defaults/ParticleCommand.php b/src/pocketmine/command/defaults/ParticleCommand.php index a11c6ae156..dba99fc591 100644 --- a/src/pocketmine/command/defaults/ParticleCommand.php +++ b/src/pocketmine/command/defaults/ParticleCommand.php @@ -64,7 +64,7 @@ use pocketmine\utils\TextFormat; class ParticleCommand extends VanillaCommand{ - public function __construct($name){ + public function __construct(string $name){ parent::__construct( $name, "%pocketmine.command.particle.description", @@ -126,7 +126,6 @@ class ParticleCommand extends VanillaCommand{ /** * @param string $name - * * @param Vector3 $pos * @param float $xd * @param float $yd @@ -135,7 +134,7 @@ class ParticleCommand extends VanillaCommand{ * * @return Particle|null */ - private function getParticle($name, Vector3 $pos, $xd, $yd, $zd, $data){ + private function getParticle(string $name, Vector3 $pos, float $xd, float $yd, float $zd, int $data = null){ switch($name){ case "explode": return new ExplodeParticle($pos); diff --git a/src/pocketmine/command/defaults/PluginsCommand.php b/src/pocketmine/command/defaults/PluginsCommand.php index a43d06d297..e932811005 100644 --- a/src/pocketmine/command/defaults/PluginsCommand.php +++ b/src/pocketmine/command/defaults/PluginsCommand.php @@ -29,7 +29,7 @@ use pocketmine\utils\TextFormat; class PluginsCommand extends VanillaCommand{ - public function __construct($name){ + public function __construct(string $name){ parent::__construct( $name, "%pocketmine.command.plugins.description", diff --git a/src/pocketmine/command/defaults/ReloadCommand.php b/src/pocketmine/command/defaults/ReloadCommand.php index 0097c30cb8..b601c19328 100644 --- a/src/pocketmine/command/defaults/ReloadCommand.php +++ b/src/pocketmine/command/defaults/ReloadCommand.php @@ -30,7 +30,7 @@ use pocketmine\utils\TextFormat; class ReloadCommand extends VanillaCommand{ - public function __construct($name){ + public function __construct(string $name){ parent::__construct( $name, "%pocketmine.command.reload.description", diff --git a/src/pocketmine/command/defaults/SaveCommand.php b/src/pocketmine/command/defaults/SaveCommand.php index 5631e99d62..81e6d5ba16 100644 --- a/src/pocketmine/command/defaults/SaveCommand.php +++ b/src/pocketmine/command/defaults/SaveCommand.php @@ -29,7 +29,7 @@ use pocketmine\event\TranslationContainer; class SaveCommand extends VanillaCommand{ - public function __construct($name){ + public function __construct(string $name){ parent::__construct( $name, "%pocketmine.command.save.description", diff --git a/src/pocketmine/command/defaults/SaveOffCommand.php b/src/pocketmine/command/defaults/SaveOffCommand.php index 2aba6c39cc..7917fa7e28 100644 --- a/src/pocketmine/command/defaults/SaveOffCommand.php +++ b/src/pocketmine/command/defaults/SaveOffCommand.php @@ -29,7 +29,7 @@ use pocketmine\event\TranslationContainer; class SaveOffCommand extends VanillaCommand{ - public function __construct($name){ + public function __construct(string $name){ parent::__construct( $name, "%pocketmine.command.saveoff.description", diff --git a/src/pocketmine/command/defaults/SaveOnCommand.php b/src/pocketmine/command/defaults/SaveOnCommand.php index bfe8aff7e3..044c41a845 100644 --- a/src/pocketmine/command/defaults/SaveOnCommand.php +++ b/src/pocketmine/command/defaults/SaveOnCommand.php @@ -29,7 +29,7 @@ use pocketmine\event\TranslationContainer; class SaveOnCommand extends VanillaCommand{ - public function __construct($name){ + public function __construct(string $name){ parent::__construct( $name, "%pocketmine.command.saveon.description", diff --git a/src/pocketmine/command/defaults/SayCommand.php b/src/pocketmine/command/defaults/SayCommand.php index 16960b2468..9055bc5e18 100644 --- a/src/pocketmine/command/defaults/SayCommand.php +++ b/src/pocketmine/command/defaults/SayCommand.php @@ -32,7 +32,7 @@ use pocketmine\utils\TextFormat; class SayCommand extends VanillaCommand{ - public function __construct($name){ + public function __construct(string $name){ parent::__construct( $name, "%pocketmine.command.say.description", diff --git a/src/pocketmine/command/defaults/SeedCommand.php b/src/pocketmine/command/defaults/SeedCommand.php index 5d3edbcdf6..34a4e4c0dd 100644 --- a/src/pocketmine/command/defaults/SeedCommand.php +++ b/src/pocketmine/command/defaults/SeedCommand.php @@ -29,7 +29,7 @@ use pocketmine\Player; class SeedCommand extends VanillaCommand{ - public function __construct($name){ + public function __construct(string $name){ parent::__construct( $name, "%pocketmine.command.seed.description", diff --git a/src/pocketmine/command/defaults/SetWorldSpawnCommand.php b/src/pocketmine/command/defaults/SetWorldSpawnCommand.php index 228dcf8fae..b1ac729af2 100644 --- a/src/pocketmine/command/defaults/SetWorldSpawnCommand.php +++ b/src/pocketmine/command/defaults/SetWorldSpawnCommand.php @@ -33,7 +33,7 @@ use pocketmine\utils\TextFormat; class SetWorldSpawnCommand extends VanillaCommand{ - public function __construct($name){ + public function __construct(string $name){ parent::__construct( $name, "%pocketmine.command.setworldspawn.description", diff --git a/src/pocketmine/command/defaults/SpawnpointCommand.php b/src/pocketmine/command/defaults/SpawnpointCommand.php index 9b35625ee6..590f9b4cff 100644 --- a/src/pocketmine/command/defaults/SpawnpointCommand.php +++ b/src/pocketmine/command/defaults/SpawnpointCommand.php @@ -34,7 +34,7 @@ use pocketmine\utils\TextFormat; class SpawnpointCommand extends VanillaCommand{ - public function __construct($name){ + public function __construct(string $name){ parent::__construct( $name, "%pocketmine.command.spawnpoint.description", diff --git a/src/pocketmine/command/defaults/StatusCommand.php b/src/pocketmine/command/defaults/StatusCommand.php index 621b90771b..6142880d05 100644 --- a/src/pocketmine/command/defaults/StatusCommand.php +++ b/src/pocketmine/command/defaults/StatusCommand.php @@ -29,7 +29,7 @@ use pocketmine\utils\Utils; class StatusCommand extends VanillaCommand{ - public function __construct($name){ + public function __construct(string $name){ parent::__construct( $name, "%pocketmine.command.status.description", diff --git a/src/pocketmine/command/defaults/StopCommand.php b/src/pocketmine/command/defaults/StopCommand.php index 67c66be907..36126307e9 100644 --- a/src/pocketmine/command/defaults/StopCommand.php +++ b/src/pocketmine/command/defaults/StopCommand.php @@ -29,7 +29,7 @@ use pocketmine\event\TranslationContainer; class StopCommand extends VanillaCommand{ - public function __construct($name){ + public function __construct(string $name){ parent::__construct( $name, "%pocketmine.command.stop.description", diff --git a/src/pocketmine/command/defaults/TeleportCommand.php b/src/pocketmine/command/defaults/TeleportCommand.php index 9eed0a9729..cd0e42a7da 100644 --- a/src/pocketmine/command/defaults/TeleportCommand.php +++ b/src/pocketmine/command/defaults/TeleportCommand.php @@ -33,7 +33,7 @@ use pocketmine\utils\TextFormat; class TeleportCommand extends VanillaCommand{ - public function __construct($name){ + public function __construct(string $name){ parent::__construct( $name, "%pocketmine.command.tp.description", diff --git a/src/pocketmine/command/defaults/TellCommand.php b/src/pocketmine/command/defaults/TellCommand.php index ab89cc4227..4dccfda90f 100644 --- a/src/pocketmine/command/defaults/TellCommand.php +++ b/src/pocketmine/command/defaults/TellCommand.php @@ -31,7 +31,7 @@ use pocketmine\utils\TextFormat; class TellCommand extends VanillaCommand{ - public function __construct($name){ + public function __construct(string $name){ parent::__construct( $name, "%pocketmine.command.tell.description", diff --git a/src/pocketmine/command/defaults/TimeCommand.php b/src/pocketmine/command/defaults/TimeCommand.php index 8c7f1ccb14..3d5b171378 100644 --- a/src/pocketmine/command/defaults/TimeCommand.php +++ b/src/pocketmine/command/defaults/TimeCommand.php @@ -33,7 +33,7 @@ use pocketmine\utils\TextFormat; class TimeCommand extends VanillaCommand{ - public function __construct($name){ + public function __construct(string $name){ parent::__construct( $name, "%pocketmine.command.time.description", diff --git a/src/pocketmine/command/defaults/TimingsCommand.php b/src/pocketmine/command/defaults/TimingsCommand.php index 584740a27d..cfe1740b7c 100644 --- a/src/pocketmine/command/defaults/TimingsCommand.php +++ b/src/pocketmine/command/defaults/TimingsCommand.php @@ -35,7 +35,7 @@ class TimingsCommand extends VanillaCommand{ public static $timingStart = 0; - public function __construct($name){ + public function __construct(string $name){ parent::__construct( $name, "%pocketmine.command.timings.description", diff --git a/src/pocketmine/command/defaults/TitleCommand.php b/src/pocketmine/command/defaults/TitleCommand.php index 9f9b42ba40..0545cd9b33 100644 --- a/src/pocketmine/command/defaults/TitleCommand.php +++ b/src/pocketmine/command/defaults/TitleCommand.php @@ -29,7 +29,7 @@ use pocketmine\event\TranslationContainer; class TitleCommand extends VanillaCommand{ - public function __construct($name){ + public function __construct(string $name){ parent::__construct( $name, "%pocketmine.command.title.description", diff --git a/src/pocketmine/command/defaults/TransferServerCommand.php b/src/pocketmine/command/defaults/TransferServerCommand.php index b4db230c4a..86502b3a0a 100644 --- a/src/pocketmine/command/defaults/TransferServerCommand.php +++ b/src/pocketmine/command/defaults/TransferServerCommand.php @@ -31,7 +31,7 @@ use pocketmine\Player; class TransferServerCommand extends VanillaCommand{ - public function __construct($name){ + public function __construct(string $name){ parent::__construct( $name, "%pocketmine.command.transferserver.description", diff --git a/src/pocketmine/command/defaults/VanillaCommand.php b/src/pocketmine/command/defaults/VanillaCommand.php index 951893337e..7b247acfd7 100644 --- a/src/pocketmine/command/defaults/VanillaCommand.php +++ b/src/pocketmine/command/defaults/VanillaCommand.php @@ -30,11 +30,15 @@ abstract class VanillaCommand extends Command{ const MAX_COORD = 30000000; const MIN_COORD = -30000000; - public function __construct($name, $description = "", $usageMessage = null, array $aliases = []){ - parent::__construct($name, $description, $usageMessage, $aliases); - } - - protected function getInteger(CommandSender $sender, $value, $min = self::MIN_COORD, $max = self::MAX_COORD){ + /** + * @param CommandSender $sender + * @param mixed $value + * @param int $min + * @param int $max + * + * @return int + */ + protected function getInteger(CommandSender $sender, $value, int $min = self::MIN_COORD, int $max = self::MAX_COORD) : int{ $i = (int) $value; if($i < $min){ @@ -46,7 +50,16 @@ abstract class VanillaCommand extends Command{ return $i; } - protected function getRelativeDouble($original, CommandSender $sender, $input, $min = self::MIN_COORD, $max = self::MAX_COORD){ + /** + * @param float $original + * @param CommandSender $sender + * @param string $input + * @param float $min + * @param float $max + * + * @return float + */ + protected function getRelativeDouble(float $original, CommandSender $sender, string $input, float $min = self::MIN_COORD, float $max = self::MAX_COORD) : float{ if($input{0} === "~"){ $value = $this->getDouble($sender, substr($input, 1)); @@ -56,7 +69,15 @@ abstract class VanillaCommand extends Command{ return $this->getDouble($sender, $input, $min, $max); } - protected function getDouble(CommandSender $sender, $value, $min = self::MIN_COORD, $max = self::MAX_COORD){ + /** + * @param CommandSender $sender + * @param mixed $value + * @param float $min + * @param float $max + * + * @return float + */ + protected function getDouble(CommandSender $sender, $value, float $min = self::MIN_COORD, float $max = self::MAX_COORD) : float{ $i = (double) $value; if($i < $min){ diff --git a/src/pocketmine/command/defaults/VersionCommand.php b/src/pocketmine/command/defaults/VersionCommand.php index c3dba90642..2576517658 100644 --- a/src/pocketmine/command/defaults/VersionCommand.php +++ b/src/pocketmine/command/defaults/VersionCommand.php @@ -31,7 +31,7 @@ use pocketmine\utils\TextFormat; class VersionCommand extends VanillaCommand{ - public function __construct($name){ + public function __construct(string $name){ parent::__construct( $name, "%pocketmine.command.version.description", diff --git a/src/pocketmine/command/defaults/WhitelistCommand.php b/src/pocketmine/command/defaults/WhitelistCommand.php index a012508e2c..89eedae3c5 100644 --- a/src/pocketmine/command/defaults/WhitelistCommand.php +++ b/src/pocketmine/command/defaults/WhitelistCommand.php @@ -31,7 +31,7 @@ use pocketmine\utils\TextFormat; class WhitelistCommand extends VanillaCommand{ - public function __construct($name){ + public function __construct(string $name){ parent::__construct( $name, "%pocketmine.command.whitelist.description", @@ -108,7 +108,7 @@ class WhitelistCommand extends VanillaCommand{ return true; } - private function badPerm(CommandSender $sender, $perm){ + private function badPerm(CommandSender $sender, string $perm) : bool{ if(!$sender->hasPermission("pocketmine.command.whitelist.$perm")){ $sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.permission")); From b8ade188886babf00d908105ea8a6c77ff1f0bd2 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 21 Aug 2017 19:25:04 +0100 Subject: [PATCH 09/14] Fixed double plants and beds sometimes dropping in creative --- src/pocketmine/block/Bed.php | 4 ++-- src/pocketmine/block/Block.php | 5 +++-- src/pocketmine/block/Chest.php | 2 +- src/pocketmine/block/Door.php | 2 +- src/pocketmine/block/DoublePlant.php | 24 ++++++++++++++---------- src/pocketmine/block/Ice.php | 3 ++- src/pocketmine/block/ItemFrame.php | 4 ++-- src/pocketmine/level/Level.php | 2 +- 8 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/pocketmine/block/Bed.php b/src/pocketmine/block/Bed.php index c8b6029e19..3cbad37586 100644 --- a/src/pocketmine/block/Bed.php +++ b/src/pocketmine/block/Bed.php @@ -206,10 +206,10 @@ class Bed extends Transparent{ return false; } - public function onBreak(Item $item) : bool{ + public function onBreak(Item $item, Player $player = null) : bool{ $this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), true, true); if(($other = $this->getOtherHalf()) !== null){ - $this->getLevel()->useBreakOn($other); //make sure tiles get removed + $this->getLevel()->useBreakOn($other, $item, $player, $player !== null); //make sure tiles get removed } return true; diff --git a/src/pocketmine/block/Block.php b/src/pocketmine/block/Block.php index adc0158680..37bd54387a 100644 --- a/src/pocketmine/block/Block.php +++ b/src/pocketmine/block/Block.php @@ -161,11 +161,12 @@ class Block extends Position implements BlockIds, Metadatable{ /** * Do the actions needed so the block is broken with the Item * - * @param Item $item + * @param Item $item + * @param Player|null $player * * @return bool */ - public function onBreak(Item $item) : bool{ + public function onBreak(Item $item, Player $player = null) : bool{ return $this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), true, true); } diff --git a/src/pocketmine/block/Chest.php b/src/pocketmine/block/Chest.php index 3ed499621c..a3a3376c17 100644 --- a/src/pocketmine/block/Chest.php +++ b/src/pocketmine/block/Chest.php @@ -124,7 +124,7 @@ class Chest extends Transparent{ return true; } - public function onBreak(Item $item) : bool{ + public function onBreak(Item $item, Player $player = null) : bool{ $t = $this->getLevel()->getTile($this); if($t instanceof TileChest){ $t->unpair(); diff --git a/src/pocketmine/block/Door.php b/src/pocketmine/block/Door.php index bec9b29980..bd6b2f899d 100644 --- a/src/pocketmine/block/Door.php +++ b/src/pocketmine/block/Door.php @@ -246,7 +246,7 @@ abstract class Door extends Transparent{ return false; } - public function onBreak(Item $item) : bool{ + public function onBreak(Item $item, Player $player = null) : bool{ if(($this->getDamage() & 0x08) === 0x08){ $down = $this->getSide(Vector3::SIDE_DOWN); if($down->getId() === $this->getId()){ diff --git a/src/pocketmine/block/DoublePlant.php b/src/pocketmine/block/DoublePlant.php index f2abf8a9a4..4050536c67 100644 --- a/src/pocketmine/block/DoublePlant.php +++ b/src/pocketmine/block/DoublePlant.php @@ -97,9 +97,9 @@ class DoublePlant extends Flowable{ return false; } - public function onBreak(Item $item) : bool{ - if(parent::onBreak($item) and $this->isValidHalfPlant()){ - return $this->getLevel()->setBlock($this->getSide(($this->meta & self::BITFLAG_TOP) !== 0 ? Vector3::SIDE_DOWN : Vector3::SIDE_UP), BlockFactory::get(Block::AIR)); + public function onBreak(Item $item, Player $player = null) : bool{ + if(parent::onBreak($item, $player) and $this->isValidHalfPlant()){ + $this->getLevel()->useBreakOn($this->getSide(($this->meta & self::BITFLAG_TOP) !== 0 ? Vector3::SIDE_DOWN : Vector3::SIDE_UP), $item, $player, $player !== null); } return false; @@ -110,16 +110,20 @@ class DoublePlant extends Flowable{ } public function getDrops(Item $item) : array{ - if(!$item->isShears() and ($this->meta === 2 or $this->meta === 3)){ //grass or fern - if(mt_rand(0, 24) === 0){ - return [ - ItemFactory::get(Item::SEEDS, 0, 1) - ]; + if($this->meta & self::BITFLAG_TOP){ + if(!$item->isShears() and ($this->meta === 2 or $this->meta === 3)){ //grass or fern + if(mt_rand(0, 24) === 0){ + return [ + ItemFactory::get(Item::SEEDS, 0, 1) + ]; + } + + return []; } - return []; + return parent::getDrops($item); } - return parent::getDrops($item); + return []; } } \ No newline at end of file diff --git a/src/pocketmine/block/Ice.php b/src/pocketmine/block/Ice.php index bbf20fbcb2..3829fa4a6b 100644 --- a/src/pocketmine/block/Ice.php +++ b/src/pocketmine/block/Ice.php @@ -26,6 +26,7 @@ namespace pocketmine\block; use pocketmine\item\Item; use pocketmine\item\Tool; use pocketmine\level\Level; +use pocketmine\Player; class Ice extends Transparent{ @@ -51,7 +52,7 @@ class Ice extends Transparent{ return Tool::TYPE_PICKAXE; } - public function onBreak(Item $item) : bool{ + public function onBreak(Item $item, Player $player = null) : bool{ $this->getLevel()->setBlock($this, BlockFactory::get(Block::WATER), true); return true; diff --git a/src/pocketmine/block/ItemFrame.php b/src/pocketmine/block/ItemFrame.php index cc8abd8d96..d92e16a3a5 100644 --- a/src/pocketmine/block/ItemFrame.php +++ b/src/pocketmine/block/ItemFrame.php @@ -78,7 +78,7 @@ class ItemFrame extends Flowable{ return true; } - public function onBreak(Item $item) : bool{ + public function onBreak(Item $item, Player $player = null) : bool{ $tile = $this->level->getTile($this); if($tile instanceof TileItemFrame){ //TODO: add events @@ -86,7 +86,7 @@ class ItemFrame extends Flowable{ $this->level->dropItem($tile->getBlock(), $tile->getItem()); } } - return parent::onBreak($item); + return parent::onBreak($item, $player); } public function onUpdate(int $type){ diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index b22f2756e1..0d80423c62 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -1666,7 +1666,7 @@ class Level implements ChunkManager, Metadatable{ $this->addParticle(new DestroyBlockParticle($target->add(0.5, 0.5, 0.5), $target)); } - $target->onBreak($item); + $target->onBreak($item, $player); $tile = $this->getTile($target); if($tile !== null){ From c32b75fa188bcee58aa46977e97e140532fc47ba Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 21 Aug 2017 20:28:30 +0100 Subject: [PATCH 10/14] Further (major!) performance enhancements to entity ticking --- src/pocketmine/entity/Entity.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index b776a2d459..7f880ecf79 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -1097,7 +1097,6 @@ abstract class Entity extends Location implements Metadatable{ public function entityBaseTick(int $tickDiff = 1) : bool{ //TODO: check vehicles - $this->blocksAround = null; $this->justCreated = false; if(!$this->isAlive()){ @@ -1313,6 +1312,8 @@ abstract class Entity extends Location implements Metadatable{ final public function setForceMovementUpdate(bool $value = true){ $this->forceMovementUpdate = $value; $this->onGround = false; + + $this->blocksAround = null; } /** @@ -1473,6 +1474,8 @@ abstract class Entity extends Location implements Metadatable{ } public function fastMove(float $dx, float $dy, float $dz) : bool{ + $this->blocksAround = null; + if($dx == 0 and $dz == 0 and $dy == 0){ return true; } @@ -1512,13 +1515,12 @@ abstract class Entity extends Location implements Metadatable{ } public function move(float $dx, float $dy, float $dz) : bool{ + $this->blocksAround = null; if($dx == 0 and $dz == 0 and $dy == 0){ return true; } - $this->blocksAround = null; - if($this->keepMovement){ $this->boundingBox->offset($dx, $dy, $dz); $this->setPosition($this->temporalVector->setComponents(($this->boundingBox->minX + $this->boundingBox->maxX) / 2, $this->boundingBox->minY, ($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2)); From 8a35b9da2990486147757ad72555b2b281b97945 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 22 Aug 2017 10:28:43 +0100 Subject: [PATCH 11/14] Added some documentation --- src/pocketmine/block/Block.php | 4 +++- src/pocketmine/block/BlockFactory.php | 2 ++ src/pocketmine/item/Item.php | 10 ++++++++-- src/pocketmine/item/ItemFactory.php | 10 ++++++++++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/pocketmine/block/Block.php b/src/pocketmine/block/Block.php index 37bd54387a..0dc4cd5a5e 100644 --- a/src/pocketmine/block/Block.php +++ b/src/pocketmine/block/Block.php @@ -43,7 +43,9 @@ use pocketmine\plugin\Plugin; class Block extends Position implements BlockIds, Metadatable{ /** - * @deprecated This functionality has moved to {@link BlockFactory#get} + * Returns a new Block instance with the specified ID, meta and position. + * + * This function redirects to {@link BlockFactory#get}. * * @param int $id * @param int $meta diff --git a/src/pocketmine/block/BlockFactory.php b/src/pocketmine/block/BlockFactory.php index ecaeb12d46..f00d8e15f0 100644 --- a/src/pocketmine/block/BlockFactory.php +++ b/src/pocketmine/block/BlockFactory.php @@ -360,6 +360,8 @@ class BlockFactory{ } /** + * Returns a new Block instance with the specified ID, meta and position. + * * @param int $id * @param int $meta * @param Position $pos diff --git a/src/pocketmine/item/Item.php b/src/pocketmine/item/Item.php index 08a467df45..8adc74152c 100644 --- a/src/pocketmine/item/Item.php +++ b/src/pocketmine/item/Item.php @@ -77,6 +77,10 @@ class Item implements ItemIds, \JsonSerializable{ } /** + * Returns a new Item instance with the specified ID, damage, count and NBT. + * + * This function redirects to {@link ItemFactory#get}. + * * @param int $id * @param int $meta * @param int $count @@ -84,18 +88,20 @@ class Item implements ItemIds, \JsonSerializable{ * * @return Item */ - public static function get(int $id, int $meta = 0, int $count = 1, $tags = "") : Item{ return ItemFactory::get($id, $meta, $count, $tags); } /** + * Tries to parse the specified string into Item ID/meta identifiers, and returns Item instances it created. + * + * This function redirects to {@link ItemFactory#fromString}. + * * @param string $str * @param bool $multiple * * @return Item[]|Item */ - public static function fromString(string $str, bool $multiple = false){ return ItemFactory::fromString($str, $multiple); } diff --git a/src/pocketmine/item/ItemFactory.php b/src/pocketmine/item/ItemFactory.php index f05f7915d7..382d27cab9 100644 --- a/src/pocketmine/item/ItemFactory.php +++ b/src/pocketmine/item/ItemFactory.php @@ -249,6 +249,16 @@ class ItemFactory{ } /** + * Tries to parse the specified string into Item ID/meta identifiers, and returns Item instances it created. + * + * Example accepted formats: + * - `diamond_pickaxe:5` + * - `minecraft:string` + * - `351:4 (lapis lazuli ID:meta)` + * + * If multiple item instances are to be created, their identifiers must be comma-separated, for example: + * `diamond_pickaxe,wooden_shovel:18,iron_ingot` + * * @param string $str * @param bool $multiple * From 938af607333806b46845269db50204f279bf47d2 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 22 Aug 2017 10:46:20 +0100 Subject: [PATCH 12/14] Update ISSUE_TEMPLATE.md --- .github/ISSUE_TEMPLATE.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index fb4b044e6a..de1e10d97a 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -1,5 +1,9 @@ ### Issue description - +