diff --git a/src/pocketmine/block/Cactus.php b/src/pocketmine/block/Cactus.php index adba25529..9f2b6470f 100644 --- a/src/pocketmine/block/Cactus.php +++ b/src/pocketmine/block/Cactus.php @@ -31,7 +31,6 @@ use pocketmine\item\Item; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Vector3; use pocketmine\Player; -use pocketmine\Server; class Cactus extends Transparent{ @@ -95,7 +94,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(), true); } diff --git a/src/pocketmine/block/Crops.php b/src/pocketmine/block/Crops.php index 43be76732..8e69b53bc 100644 --- a/src/pocketmine/block/Crops.php +++ b/src/pocketmine/block/Crops.php @@ -27,7 +27,6 @@ use pocketmine\event\block\BlockGrowEvent; use pocketmine\item\Item; use pocketmine\math\Vector3; use pocketmine\Player; -use pocketmine\Server; abstract class Crops extends Flowable{ @@ -50,8 +49,8 @@ abstract class Crops extends Flowable{ $block->meta = 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(), true, true); } @@ -79,8 +78,8 @@ abstract class Crops extends Flowable{ if($this->meta < 0x07){ $block = clone $this; ++$block->meta; - 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(), true, true); } diff --git a/src/pocketmine/block/Fire.php b/src/pocketmine/block/Fire.php index ace4a385d..ecc30761f 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\Vector3; -use pocketmine\Server; class Fire extends Flowable{ @@ -69,7 +68,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()); } @@ -153,7 +152,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 a2887e0fd..eb27c3ab6 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, 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, false); } diff --git a/src/pocketmine/block/Lava.php b/src/pocketmine/block/Lava.php index 057ad42f4..aa111d28a 100644 --- a/src/pocketmine/block/Lava.php +++ b/src/pocketmine/block/Lava.php @@ -31,7 +31,6 @@ use pocketmine\item\Item; use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; use pocketmine\Player; -use pocketmine\Server; class Lava extends Liquid{ @@ -107,7 +106,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 05ef8a882..bbe527cbc 100644 --- a/src/pocketmine/block/Leaves.php +++ b/src/pocketmine/block/Leaves.php @@ -147,8 +147,8 @@ class Leaves extends Transparent{ $this->meta &= 0x03; $visited = []; - $this->getLevel()->getServer()->getPluginManager()->callEvent($ev = new LeavesDecayEvent($this)); - + $ev = new LeavesDecayEvent($this); + $ev->call(); if($ev->isCancelled() or $this->findLog($this, $visited, 0)){ $this->getLevel()->setBlock($this, $this, false, false); }else{ diff --git a/src/pocketmine/block/MelonStem.php b/src/pocketmine/block/MelonStem.php index eb4c6d0ee..f7d67c773 100644 --- a/src/pocketmine/block/MelonStem.php +++ b/src/pocketmine/block/MelonStem.php @@ -27,7 +27,6 @@ use pocketmine\event\block\BlockGrowEvent; use pocketmine\item\Item; use pocketmine\item\ItemFactory; use pocketmine\math\Vector3; -use pocketmine\Server; class MelonStem extends Crops{ @@ -46,7 +45,8 @@ class MelonStem extends Crops{ if($this->meta < 0x07){ $block = clone $this; ++$block->meta; - 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(), true); } @@ -60,7 +60,8 @@ class MelonStem extends Crops{ $side = $this->getSide(mt_rand(2, 5)); $d = $side->getSide(Vector3::SIDE_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, BlockFactory::get(Block::MELON_BLOCK))); + $ev = new BlockGrowEvent($side, BlockFactory::get(Block::MELON_BLOCK)); + $ev->call(); if(!$ev->isCancelled()){ $this->getLevel()->setBlock($side, $ev->getNewState(), true); } diff --git a/src/pocketmine/block/Mycelium.php b/src/pocketmine/block/Mycelium.php index 36439e0e8..f309d373c 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\Vector3; -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(Vector3::SIDE_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 14e82f548..e27dd1397 100644 --- a/src/pocketmine/block/NetherWartPlant.php +++ b/src/pocketmine/block/NetherWartPlant.php @@ -68,8 +68,8 @@ class NetherWartPlant extends Flowable{ if($this->meta < 3 and mt_rand(0, 10) === 0){ //Still growing $block = clone $this; $block->meta++; - $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(), false, true); } diff --git a/src/pocketmine/block/PumpkinStem.php b/src/pocketmine/block/PumpkinStem.php index 33d83470f..581190b4b 100644 --- a/src/pocketmine/block/PumpkinStem.php +++ b/src/pocketmine/block/PumpkinStem.php @@ -27,7 +27,6 @@ use pocketmine\event\block\BlockGrowEvent; use pocketmine\item\Item; use pocketmine\item\ItemFactory; use pocketmine\math\Vector3; -use pocketmine\Server; class PumpkinStem extends Crops{ @@ -46,7 +45,8 @@ class PumpkinStem extends Crops{ if($this->meta < 0x07){ $block = clone $this; ++$block->meta; - 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(), true); } @@ -60,7 +60,8 @@ class PumpkinStem extends Crops{ $side = $this->getSide(mt_rand(2, 5)); $d = $side->getSide(Vector3::SIDE_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, BlockFactory::get(Block::PUMPKIN))); + $ev = new BlockGrowEvent($side, BlockFactory::get(Block::PUMPKIN)); + $ev->call(); if(!$ev->isCancelled()){ $this->getLevel()->setBlock($side, $ev->getNewState(), true); } diff --git a/src/pocketmine/block/Sugarcane.php b/src/pocketmine/block/Sugarcane.php index bddd9ec1c..99d0f5243 100644 --- a/src/pocketmine/block/Sugarcane.php +++ b/src/pocketmine/block/Sugarcane.php @@ -27,7 +27,6 @@ use pocketmine\event\block\BlockGrowEvent; use pocketmine\item\Item; use pocketmine\math\Vector3; use pocketmine\Player; -use pocketmine\Server; class Sugarcane extends Flowable{ @@ -49,7 +48,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(), true); } diff --git a/src/pocketmine/network/Network.php b/src/pocketmine/network/Network.php index 6edb9977f..898d2e6ed 100644 --- a/src/pocketmine/network/Network.php +++ b/src/pocketmine/network/Network.php @@ -98,7 +98,7 @@ class Network{ $logger->logException($e); } - $this->server->getPluginManager()->callEvent(new NetworkInterfaceCrashEvent($interface, $e)); + (new NetworkInterfaceCrashEvent($interface, $e))->call(); $interface->emergencyShutdown(); $this->unregisterInterface($interface); @@ -110,7 +110,8 @@ class Network{ * @param SourceInterface $interface */ public function registerInterface(SourceInterface $interface){ - $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; @@ -126,7 +127,7 @@ class Network{ * @param SourceInterface $interface */ public function unregisterInterface(SourceInterface $interface){ - $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/PlayerNetworkSessionAdapter.php b/src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter.php index d405905cc..5186cdd6a 100644 --- a/src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter.php +++ b/src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter.php @@ -88,7 +88,8 @@ class PlayerNetworkSessionAdapter extends 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)){ $this->server->getLogger()->debug("Unhandled " . $packet->getName() . " received from " . $this->player->getName() . ": 0x" . bin2hex($packet->buffer)); } diff --git a/src/pocketmine/network/mcpe/RakLibInterface.php b/src/pocketmine/network/mcpe/RakLibInterface.php index 036f2c856..f8eefa12a 100644 --- a/src/pocketmine/network/mcpe/RakLibInterface.php +++ b/src/pocketmine/network/mcpe/RakLibInterface.php @@ -137,7 +137,7 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{ public function openSession(string $identifier, string $address, int $port, int $clientID) : void{ $ev = new PlayerCreationEvent($this, Player::class, Player::class, $address, $port); - $this->server->getPluginManager()->callEvent($ev); + $ev->call(); $class = $ev->getPlayerClass(); /** diff --git a/src/pocketmine/network/rcon/RCON.php b/src/pocketmine/network/rcon/RCON.php index 624045789..a4d022c2e 100644 --- a/src/pocketmine/network/rcon/RCON.php +++ b/src/pocketmine/network/rcon/RCON.php @@ -97,7 +97,8 @@ class RCON{ $response = new RemoteConsoleCommandSender(); $command = $this->instance->cmd; - $this->server->getPluginManager()->callEvent($ev = new RemoteServerCommandEvent($response, $command)); + $ev = new RemoteServerCommandEvent($response, $command); + $ev->call(); if(!$ev->isCancelled()){ $this->server->dispatchCommand($ev->getSender(), $ev->getCommand());