diff --git a/src/pocketmine/block/Cactus.php b/src/pocketmine/block/Cactus.php index 6e452d0b0..b0a0d6592 100644 --- a/src/pocketmine/block/Cactus.php +++ b/src/pocketmine/block/Cactus.php @@ -32,7 +32,6 @@ use pocketmine\math\AxisAlignedBB; use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; -use pocketmine\Server; class Cactus extends Transparent{ @@ -104,7 +103,8 @@ class Cactus extends Transparent{ for($y = 1; $y < 3; ++$y){ $b = $this->getLevel()->getBlockAt($this->x, $this->y + $y, $this->z); if($b->getId() === self::AIR){ - Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($b, BlockFactory::get(Block::CACTUS))); + $ev = new BlockGrowEvent($b, BlockFactory::get(Block::CACTUS)); + $ev->call(); if(!$ev->isCancelled()){ $this->getLevel()->setBlock($b, $ev->getNewState()); } diff --git a/src/pocketmine/block/Crops.php b/src/pocketmine/block/Crops.php index 5ce339e24..e4bd5d2cf 100644 --- a/src/pocketmine/block/Crops.php +++ b/src/pocketmine/block/Crops.php @@ -28,7 +28,6 @@ use pocketmine\item\Item; use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; -use pocketmine\Server; abstract class Crops extends Flowable{ /** @var int */ @@ -67,8 +66,8 @@ abstract class Crops extends Flowable{ $block->age = 7; } - Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($this, $block)); - + $ev = new BlockGrowEvent($this, $block); + $ev->call(); if(!$ev->isCancelled()){ $this->getLevel()->setBlock($this, $ev->getNewState()); } @@ -95,8 +94,8 @@ abstract class Crops extends Flowable{ if($this->age < 7 and mt_rand(0, 2) === 1){ $block = clone $this; ++$block->age; - Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($this, $block)); - + $ev = new BlockGrowEvent($this, $block); + $ev->call(); if(!$ev->isCancelled()){ $this->getLevel()->setBlock($this, $ev->getNewState()); } diff --git a/src/pocketmine/block/Fire.php b/src/pocketmine/block/Fire.php index f0757c87e..7a5da3ff3 100644 --- a/src/pocketmine/block/Fire.php +++ b/src/pocketmine/block/Fire.php @@ -31,7 +31,6 @@ use pocketmine\event\entity\EntityDamageByBlockEvent; use pocketmine\event\entity\EntityDamageEvent; use pocketmine\item\Item; use pocketmine\math\Facing; -use pocketmine\Server; class Fire extends Flowable{ @@ -84,7 +83,7 @@ class Fire extends Flowable{ if($entity instanceof Arrow){ $ev->setCancelled(); } - Server::getInstance()->getPluginManager()->callEvent($ev); + $ev->call(); if(!$ev->isCancelled()){ $entity->setOnFire($ev->getDuration()); } @@ -168,7 +167,8 @@ class Fire extends Flowable{ private function burnBlock(Block $block, int $chanceBound) : void{ if(mt_rand(0, $chanceBound) < $block->getFlammability()){ - $this->level->getServer()->getPluginManager()->callEvent($ev = new BlockBurnEvent($block, $this)); + $ev = new BlockBurnEvent($block, $this); + $ev->call(); if(!$ev->isCancelled()){ $block->onIncinerate(); diff --git a/src/pocketmine/block/Grass.php b/src/pocketmine/block/Grass.php index b7c57158e..4332cc0d5 100644 --- a/src/pocketmine/block/Grass.php +++ b/src/pocketmine/block/Grass.php @@ -67,7 +67,8 @@ class Grass extends Solid{ $lightAbove = $this->level->getFullLightAt($this->x, $this->y + 1, $this->z); if($lightAbove < 4 and BlockFactory::$lightFilter[$this->level->getBlockIdAt($this->x, $this->y + 1, $this->z)] >= 3){ //2 plus 1 standard filter amount //grass dies - $this->level->getServer()->getPluginManager()->callEvent($ev = new BlockSpreadEvent($this, $this, BlockFactory::get(Block::DIRT))); + $ev = new BlockSpreadEvent($this, $this, BlockFactory::get(Block::DIRT)); + $ev->call(); if(!$ev->isCancelled()){ $this->level->setBlock($this, $ev->getNewState(), false); } @@ -86,7 +87,8 @@ class Grass extends Solid{ continue; } - $this->level->getServer()->getPluginManager()->callEvent($ev = new BlockSpreadEvent($b = $this->level->getBlockAt($x, $y, $z), $this, BlockFactory::get(Block::GRASS))); + $ev = new BlockSpreadEvent($b = $this->level->getBlockAt($x, $y, $z), $this, BlockFactory::get(Block::GRASS)); + $ev->call(); if(!$ev->isCancelled()){ $this->level->setBlock($b, $ev->getNewState(), false); } diff --git a/src/pocketmine/block/Lava.php b/src/pocketmine/block/Lava.php index c653c0d3a..5e6c6e2f7 100644 --- a/src/pocketmine/block/Lava.php +++ b/src/pocketmine/block/Lava.php @@ -29,7 +29,6 @@ use pocketmine\event\entity\EntityDamageByBlockEvent; use pocketmine\event\entity\EntityDamageEvent; use pocketmine\math\Facing; use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; -use pocketmine\Server; class Lava extends Liquid{ @@ -108,7 +107,7 @@ class Lava extends Liquid{ $entity->attack($ev); $ev = new EntityCombustByBlockEvent($this, $entity, 15); - Server::getInstance()->getPluginManager()->callEvent($ev); + $ev->call(); if(!$ev->isCancelled()){ $entity->setOnFire($ev->getDuration()); } diff --git a/src/pocketmine/block/Leaves.php b/src/pocketmine/block/Leaves.php index 52e70d532..118d8e47a 100644 --- a/src/pocketmine/block/Leaves.php +++ b/src/pocketmine/block/Leaves.php @@ -108,8 +108,8 @@ class Leaves extends Transparent{ public function onRandomTick() : void{ if(!$this->noDecay and $this->checkDecay){ - $this->getLevel()->getServer()->getPluginManager()->callEvent($ev = new LeavesDecayEvent($this)); - + $ev = new LeavesDecayEvent($this); + $ev->call(); if($ev->isCancelled() or $this->findLog($this)){ $this->getLevel()->setBlock($this, $this, false); }else{ diff --git a/src/pocketmine/block/Mycelium.php b/src/pocketmine/block/Mycelium.php index b56edf755..5ade8485d 100644 --- a/src/pocketmine/block/Mycelium.php +++ b/src/pocketmine/block/Mycelium.php @@ -27,7 +27,6 @@ use pocketmine\event\block\BlockSpreadEvent; use pocketmine\item\Item; use pocketmine\item\ItemFactory; use pocketmine\math\Facing; -use pocketmine\Server; class Mycelium extends Solid{ @@ -67,7 +66,8 @@ class Mycelium extends Solid{ $block = $this->getLevel()->getBlockAt($x, $y, $z); if($block->getId() === Block::DIRT){ if($block->getSide(Facing::UP) instanceof Transparent){ - Server::getInstance()->getPluginManager()->callEvent($ev = new BlockSpreadEvent($block, $this, BlockFactory::get(Block::MYCELIUM))); + $ev = new BlockSpreadEvent($block, $this, BlockFactory::get(Block::MYCELIUM)); + $ev->call(); if(!$ev->isCancelled()){ $this->getLevel()->setBlock($block, $ev->getNewState()); } diff --git a/src/pocketmine/block/NetherWartPlant.php b/src/pocketmine/block/NetherWartPlant.php index e56dd19c5..91d8eee7f 100644 --- a/src/pocketmine/block/NetherWartPlant.php +++ b/src/pocketmine/block/NetherWartPlant.php @@ -82,8 +82,8 @@ class NetherWartPlant extends Flowable{ if($this->age < 3 and mt_rand(0, 10) === 0){ //Still growing $block = clone $this; $block->age++; - $this->getLevel()->getServer()->getPluginManager()->callEvent($ev = new BlockGrowEvent($this, $block)); - + $ev = new BlockGrowEvent($this, $block); + $ev->call(); if(!$ev->isCancelled()){ $this->getLevel()->setBlock($this, $ev->getNewState()); } diff --git a/src/pocketmine/block/Stem.php b/src/pocketmine/block/Stem.php index 2722e6c83..e5d72f2a3 100644 --- a/src/pocketmine/block/Stem.php +++ b/src/pocketmine/block/Stem.php @@ -27,7 +27,6 @@ use pocketmine\event\block\BlockGrowEvent; use pocketmine\item\Item; use pocketmine\item\ItemFactory; use pocketmine\math\Facing; -use pocketmine\Server; abstract class Stem extends Crops{ @@ -38,7 +37,8 @@ abstract class Stem extends Crops{ if($this->age < 7){ $block = clone $this; ++$block->age; - Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($this, $block)); + $ev = new BlockGrowEvent($this, $block); + $ev->call(); if(!$ev->isCancelled()){ $this->getLevel()->setBlock($this, $ev->getNewState()); } @@ -53,7 +53,8 @@ abstract class Stem extends Crops{ $side = $this->getSide(Facing::HORIZONTAL[array_rand(Facing::HORIZONTAL)]); $d = $side->getSide(Facing::DOWN); if($side->getId() === self::AIR and ($d->getId() === self::FARMLAND or $d->getId() === self::GRASS or $d->getId() === self::DIRT)){ - Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($side, $grow)); + $ev = new BlockGrowEvent($side, $grow); + $ev->call(); if(!$ev->isCancelled()){ $this->getLevel()->setBlock($side, $ev->getNewState()); } diff --git a/src/pocketmine/block/Sugarcane.php b/src/pocketmine/block/Sugarcane.php index 17b632350..a75023f2d 100644 --- a/src/pocketmine/block/Sugarcane.php +++ b/src/pocketmine/block/Sugarcane.php @@ -28,7 +28,6 @@ use pocketmine\item\Item; use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; -use pocketmine\Server; class Sugarcane extends Flowable{ @@ -65,7 +64,8 @@ class Sugarcane extends Flowable{ for($y = 1; $y < 3; ++$y){ $b = $this->getLevel()->getBlockAt($this->x, $this->y + $y, $this->z); if($b->getId() === self::AIR){ - Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($b, BlockFactory::get(Block::SUGARCANE_BLOCK))); + $ev = new BlockGrowEvent($b, BlockFactory::get(Block::SUGARCANE_BLOCK)); + $ev->call(); if(!$ev->isCancelled()){ $this->getLevel()->setBlock($b, $ev->getNewState()); } diff --git a/src/pocketmine/network/Network.php b/src/pocketmine/network/Network.php index 7cc580ffc..cd65f68d6 100644 --- a/src/pocketmine/network/Network.php +++ b/src/pocketmine/network/Network.php @@ -94,7 +94,7 @@ class Network{ $logger->logException($e); } - $this->server->getPluginManager()->callEvent(new NetworkInterfaceCrashEvent($interface, $e)); + (new NetworkInterfaceCrashEvent($interface, $e))->call(); $interface->emergencyShutdown(); $this->unregisterInterface($interface); @@ -113,7 +113,8 @@ class Network{ * @param NetworkInterface $interface */ public function registerInterface(NetworkInterface $interface) : void{ - $this->server->getPluginManager()->callEvent($ev = new NetworkInterfaceRegisterEvent($interface)); + $ev = new NetworkInterfaceRegisterEvent($interface); + $ev->call(); if(!$ev->isCancelled()){ $interface->start(); $this->interfaces[$hash = spl_object_hash($interface)] = $interface; @@ -129,7 +130,7 @@ class Network{ * @param NetworkInterface $interface */ public function unregisterInterface(NetworkInterface $interface) : void{ - $this->server->getPluginManager()->callEvent(new NetworkInterfaceUnregisterEvent($interface)); + (new NetworkInterfaceUnregisterEvent($interface))->call(); unset($this->interfaces[$hash = spl_object_hash($interface)], $this->advancedInterfaces[$hash]); } diff --git a/src/pocketmine/network/mcpe/NetworkSession.php b/src/pocketmine/network/mcpe/NetworkSession.php index 5e6823b46..fd7a78a34 100644 --- a/src/pocketmine/network/mcpe/NetworkSession.php +++ b/src/pocketmine/network/mcpe/NetworkSession.php @@ -92,7 +92,8 @@ class NetworkSession{ } protected function createPlayer() : void{ - $this->server->getPluginManager()->callEvent($ev = new PlayerCreationEvent($this)); + $ev = new PlayerCreationEvent($this); + $ev->call(); $class = $ev->getPlayerClass(); /** @@ -201,7 +202,8 @@ class NetworkSession{ $this->server->getLogger()->debug("Still " . strlen($remains) . " bytes unread in " . $packet->getName() . ": 0x" . bin2hex($remains)); } - $this->server->getPluginManager()->callEvent($ev = new DataPacketReceiveEvent($this->player, $packet)); + $ev = new DataPacketReceiveEvent($this->player, $packet); + $ev->call(); if(!$ev->isCancelled() and !$packet->handle($this->handler)){ $this->server->getLogger()->debug("Unhandled " . $packet->getName() . " received from " . $this->player->getName() . ": 0x" . bin2hex($packet->buffer)); } @@ -213,7 +215,8 @@ class NetworkSession{ $timings = Timings::getSendDataPacketTimings($packet); $timings->startTiming(); try{ - $this->server->getPluginManager()->callEvent($ev = new DataPacketSendEvent($this->player, $packet)); + $ev = new DataPacketSendEvent($this->player, $packet); + $ev->call(); if($ev->isCancelled()){ return false; }