Move block and network namespaces away from PluginManager->callEvent()

the original step that wasn't supposed to cause conflicts, caused messy conflicts... so I might as well do this part too
This commit is contained in:
Dylan K. Taylor 2018-10-05 18:22:49 +01:00
parent 620784e4e7
commit 495fdbd19f
15 changed files with 39 additions and 34 deletions

View File

@ -31,7 +31,6 @@ use pocketmine\item\Item;
use pocketmine\math\AxisAlignedBB; use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\Server;
class Cactus extends Transparent{ class Cactus extends Transparent{
@ -95,7 +94,8 @@ class Cactus extends Transparent{
for($y = 1; $y < 3; ++$y){ for($y = 1; $y < 3; ++$y){
$b = $this->getLevel()->getBlockAt($this->x, $this->y + $y, $this->z); $b = $this->getLevel()->getBlockAt($this->x, $this->y + $y, $this->z);
if($b->getId() === self::AIR){ 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()){ if(!$ev->isCancelled()){
$this->getLevel()->setBlock($b, $ev->getNewState(), true); $this->getLevel()->setBlock($b, $ev->getNewState(), true);
} }

View File

@ -27,7 +27,6 @@ use pocketmine\event\block\BlockGrowEvent;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\Server;
abstract class Crops extends Flowable{ abstract class Crops extends Flowable{
@ -50,8 +49,8 @@ abstract class Crops extends Flowable{
$block->meta = 7; $block->meta = 7;
} }
Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($this, $block)); $ev = new BlockGrowEvent($this, $block);
$ev->call();
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$this->getLevel()->setBlock($this, $ev->getNewState(), true, true); $this->getLevel()->setBlock($this, $ev->getNewState(), true, true);
} }
@ -79,8 +78,8 @@ abstract class Crops extends Flowable{
if($this->meta < 0x07){ if($this->meta < 0x07){
$block = clone $this; $block = clone $this;
++$block->meta; ++$block->meta;
Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($this, $block)); $ev = new BlockGrowEvent($this, $block);
$ev->call();
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$this->getLevel()->setBlock($this, $ev->getNewState(), true, true); $this->getLevel()->setBlock($this, $ev->getNewState(), true, true);
} }

View File

@ -31,7 +31,6 @@ use pocketmine\event\entity\EntityDamageByBlockEvent;
use pocketmine\event\entity\EntityDamageEvent; use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Server;
class Fire extends Flowable{ class Fire extends Flowable{
@ -69,7 +68,7 @@ class Fire extends Flowable{
if($entity instanceof Arrow){ if($entity instanceof Arrow){
$ev->setCancelled(); $ev->setCancelled();
} }
Server::getInstance()->getPluginManager()->callEvent($ev); $ev->call();
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$entity->setOnFire($ev->getDuration()); $entity->setOnFire($ev->getDuration());
} }
@ -153,7 +152,8 @@ class Fire extends Flowable{
private function burnBlock(Block $block, int $chanceBound) : void{ private function burnBlock(Block $block, int $chanceBound) : void{
if(mt_rand(0, $chanceBound) < $block->getFlammability()){ 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()){ if(!$ev->isCancelled()){
$block->onIncinerate(); $block->onIncinerate();

View File

@ -67,7 +67,8 @@ class Grass extends Solid{
$lightAbove = $this->level->getFullLightAt($this->x, $this->y + 1, $this->z); $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 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 //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()){ if(!$ev->isCancelled()){
$this->level->setBlock($this, $ev->getNewState(), false, false); $this->level->setBlock($this, $ev->getNewState(), false, false);
} }
@ -86,7 +87,8 @@ class Grass extends Solid{
continue; 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()){ if(!$ev->isCancelled()){
$this->level->setBlock($b, $ev->getNewState(), false, false); $this->level->setBlock($b, $ev->getNewState(), false, false);
} }

View File

@ -31,7 +31,6 @@ use pocketmine\item\Item;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\Server;
class Lava extends Liquid{ class Lava extends Liquid{
@ -107,7 +106,7 @@ class Lava extends Liquid{
$entity->attack($ev); $entity->attack($ev);
$ev = new EntityCombustByBlockEvent($this, $entity, 15); $ev = new EntityCombustByBlockEvent($this, $entity, 15);
Server::getInstance()->getPluginManager()->callEvent($ev); $ev->call();
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$entity->setOnFire($ev->getDuration()); $entity->setOnFire($ev->getDuration());
} }

View File

@ -147,8 +147,8 @@ class Leaves extends Transparent{
$this->meta &= 0x03; $this->meta &= 0x03;
$visited = []; $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)){ if($ev->isCancelled() or $this->findLog($this, $visited, 0)){
$this->getLevel()->setBlock($this, $this, false, false); $this->getLevel()->setBlock($this, $this, false, false);
}else{ }else{

View File

@ -27,7 +27,6 @@ use pocketmine\event\block\BlockGrowEvent;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory; use pocketmine\item\ItemFactory;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Server;
class MelonStem extends Crops{ class MelonStem extends Crops{
@ -46,7 +45,8 @@ class MelonStem extends Crops{
if($this->meta < 0x07){ if($this->meta < 0x07){
$block = clone $this; $block = clone $this;
++$block->meta; ++$block->meta;
Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($this, $block)); $ev = new BlockGrowEvent($this, $block);
$ev->call();
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$this->getLevel()->setBlock($this, $ev->getNewState(), true); $this->getLevel()->setBlock($this, $ev->getNewState(), true);
} }
@ -60,7 +60,8 @@ class MelonStem extends Crops{
$side = $this->getSide(mt_rand(2, 5)); $side = $this->getSide(mt_rand(2, 5));
$d = $side->getSide(Vector3::SIDE_DOWN); $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)){ 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()){ if(!$ev->isCancelled()){
$this->getLevel()->setBlock($side, $ev->getNewState(), true); $this->getLevel()->setBlock($side, $ev->getNewState(), true);
} }

View File

@ -27,7 +27,6 @@ use pocketmine\event\block\BlockSpreadEvent;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory; use pocketmine\item\ItemFactory;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Server;
class Mycelium extends Solid{ class Mycelium extends Solid{
@ -67,7 +66,8 @@ class Mycelium extends Solid{
$block = $this->getLevel()->getBlockAt($x, $y, $z); $block = $this->getLevel()->getBlockAt($x, $y, $z);
if($block->getId() === Block::DIRT){ if($block->getId() === Block::DIRT){
if($block->getSide(Vector3::SIDE_UP) instanceof Transparent){ 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()){ if(!$ev->isCancelled()){
$this->getLevel()->setBlock($block, $ev->getNewState()); $this->getLevel()->setBlock($block, $ev->getNewState());
} }

View File

@ -68,8 +68,8 @@ class NetherWartPlant extends Flowable{
if($this->meta < 3 and mt_rand(0, 10) === 0){ //Still growing if($this->meta < 3 and mt_rand(0, 10) === 0){ //Still growing
$block = clone $this; $block = clone $this;
$block->meta++; $block->meta++;
$this->getLevel()->getServer()->getPluginManager()->callEvent($ev = new BlockGrowEvent($this, $block)); $ev = new BlockGrowEvent($this, $block);
$ev->call();
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$this->getLevel()->setBlock($this, $ev->getNewState(), false, true); $this->getLevel()->setBlock($this, $ev->getNewState(), false, true);
} }

View File

@ -27,7 +27,6 @@ use pocketmine\event\block\BlockGrowEvent;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory; use pocketmine\item\ItemFactory;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Server;
class PumpkinStem extends Crops{ class PumpkinStem extends Crops{
@ -46,7 +45,8 @@ class PumpkinStem extends Crops{
if($this->meta < 0x07){ if($this->meta < 0x07){
$block = clone $this; $block = clone $this;
++$block->meta; ++$block->meta;
Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($this, $block)); $ev = new BlockGrowEvent($this, $block);
$ev->call();
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$this->getLevel()->setBlock($this, $ev->getNewState(), true); $this->getLevel()->setBlock($this, $ev->getNewState(), true);
} }
@ -60,7 +60,8 @@ class PumpkinStem extends Crops{
$side = $this->getSide(mt_rand(2, 5)); $side = $this->getSide(mt_rand(2, 5));
$d = $side->getSide(Vector3::SIDE_DOWN); $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)){ 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()){ if(!$ev->isCancelled()){
$this->getLevel()->setBlock($side, $ev->getNewState(), true); $this->getLevel()->setBlock($side, $ev->getNewState(), true);
} }

View File

@ -27,7 +27,6 @@ use pocketmine\event\block\BlockGrowEvent;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\Server;
class Sugarcane extends Flowable{ class Sugarcane extends Flowable{
@ -49,7 +48,8 @@ class Sugarcane extends Flowable{
for($y = 1; $y < 3; ++$y){ for($y = 1; $y < 3; ++$y){
$b = $this->getLevel()->getBlockAt($this->x, $this->y + $y, $this->z); $b = $this->getLevel()->getBlockAt($this->x, $this->y + $y, $this->z);
if($b->getId() === self::AIR){ 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()){ if(!$ev->isCancelled()){
$this->getLevel()->setBlock($b, $ev->getNewState(), true); $this->getLevel()->setBlock($b, $ev->getNewState(), true);
} }

View File

@ -98,7 +98,7 @@ class Network{
$logger->logException($e); $logger->logException($e);
} }
$this->server->getPluginManager()->callEvent(new NetworkInterfaceCrashEvent($interface, $e)); (new NetworkInterfaceCrashEvent($interface, $e))->call();
$interface->emergencyShutdown(); $interface->emergencyShutdown();
$this->unregisterInterface($interface); $this->unregisterInterface($interface);
@ -110,7 +110,8 @@ class Network{
* @param SourceInterface $interface * @param SourceInterface $interface
*/ */
public function registerInterface(SourceInterface $interface){ public function registerInterface(SourceInterface $interface){
$this->server->getPluginManager()->callEvent($ev = new NetworkInterfaceRegisterEvent($interface)); $ev = new NetworkInterfaceRegisterEvent($interface);
$ev->call();
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$interface->start(); $interface->start();
$this->interfaces[$hash = spl_object_hash($interface)] = $interface; $this->interfaces[$hash = spl_object_hash($interface)] = $interface;
@ -126,7 +127,7 @@ class Network{
* @param SourceInterface $interface * @param SourceInterface $interface
*/ */
public function unregisterInterface(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]); unset($this->interfaces[$hash = spl_object_hash($interface)], $this->advancedInterfaces[$hash]);
} }

View File

@ -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->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)){ if(!$ev->isCancelled() and !$packet->handle($this)){
$this->server->getLogger()->debug("Unhandled " . $packet->getName() . " received from " . $this->player->getName() . ": 0x" . bin2hex($packet->buffer)); $this->server->getLogger()->debug("Unhandled " . $packet->getName() . " received from " . $this->player->getName() . ": 0x" . bin2hex($packet->buffer));
} }

View File

@ -137,7 +137,7 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{
public function openSession(string $identifier, string $address, int $port, int $clientID) : void{ public function openSession(string $identifier, string $address, int $port, int $clientID) : void{
$ev = new PlayerCreationEvent($this, Player::class, Player::class, $address, $port); $ev = new PlayerCreationEvent($this, Player::class, Player::class, $address, $port);
$this->server->getPluginManager()->callEvent($ev); $ev->call();
$class = $ev->getPlayerClass(); $class = $ev->getPlayerClass();
/** /**

View File

@ -97,7 +97,8 @@ class RCON{
$response = new RemoteConsoleCommandSender(); $response = new RemoteConsoleCommandSender();
$command = $this->instance->cmd; $command = $this->instance->cmd;
$this->server->getPluginManager()->callEvent($ev = new RemoteServerCommandEvent($response, $command)); $ev = new RemoteServerCommandEvent($response, $command);
$ev->call();
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$this->server->dispatchCommand($ev->getSender(), $ev->getCommand()); $this->server->dispatchCommand($ev->getSender(), $ev->getCommand());