Inheritance: extends EntityEvent, implements pocketmine\event\Cancellable
コード例 #1
0
ファイル: EventListener.php プロジェクト: kdani1/PEPlot
 public function onExplosion(EntityExplodeEvent $event)
 {
     $levelName = $event->getEntity()->getLevel()->getName();
     if ($this->plugin->isLevelLoaded($levelName)) {
         $event->setCancelled(true);
     }
     /* Allow explosions but only break blocks inside the plot the tnt is in.
              * Disabled due to tnt cannons not being stopped
     
             $levelName = $event->getEntity()->getLevel()->getName();
             if (!$this->plugin->isLevelLoaded($levelName)) {
                 return;
             }
             $plot = $this->plugin->getPlotByPosition($event->getPosition());
             if ($plot === null) {
                 $event->setCancelled(true);
                 return;
             }
             $beginPos = $this->plugin->getPlotPosition($plot);
             $endPos = clone $beginPos;
             $plotSize = $this->plugin->getLevelSettings($levelName)->plotSize;
             $endPos->x += $plotSize;
             $endPos->z += $plotSize;
             $blocks = array_filter($event->getBlockList(), function($block) use($beginPos, $endPos) {
                 if ($block->x >= $beginPos->x and $block->z >= $beginPos->z and $block->x < $endPos->x and $block->z < $endPos->z) {
                     return true;
                 }
                 return false;
             });
             $event->setBlockList($blocks);
             */
 }
コード例 #2
0
 public function onExplode(EntityExplodeEvent $ev)
 {
     if ($ev->isCancelled()) {
         return;
     }
     $et = $ev->getEntity();
     $sp = $et->getLevel()->getSpawnLocation();
     $dist = $sp->distance($et);
     if ($dist > $this->owner->getServer()->getSpawnRadius()) {
         return;
     }
     $ev->setCancelled();
 }
コード例 #3
0
 public function onExplode(EntityExplodeEvent $ev)
 {
     //echo __METHOD__.",".__LINE__."\n";
     if ($ev->isCancelled()) {
         return;
     }
     $et = $ev->getEntity();
     $world = $et->getLevel()->getName();
     if (!isset($this->wcfg[$world])) {
         return;
     }
     if ($this->wcfg[$world] == "spawn") {
         $sp = $et->getLevel()->getSpawnLocation();
         $dist = $sp->distance($et);
         if ($dist > $this->owner->getServer()->getSpawnRadius()) {
             return;
         }
     }
     $ev->setCancelled();
     $this->owner->getLogger()->notice(TextFormat::RED . mc::_("Explosion was stopped in %1%", $world));
 }
コード例 #4
0
ファイル: EventListener.php プロジェクト: Adam1609/MyPlot
 public function onExplosion(EntityExplodeEvent $event)
 {
     $levelName = $event->getEntity()->getLevel()->getName();
     if (!$this->plugin->isLevelLoaded($levelName)) {
         return;
     }
     $plot = $this->plugin->getPlotByPosition($event->getPosition());
     if ($plot === null) {
         $event->setCancelled(true);
         return;
     }
     $beginPos = $this->plugin->getPlotPosition($plot);
     $endPos = clone $beginPos;
     $plotSize = $this->plugin->getLevelSettings($levelName)->plotSize;
     $endPos->x += $plotSize;
     $endPos->z += $plotSize;
     $blocks = array_filter($event->getBlockList(), function ($block) use($beginPos, $endPos) {
         if ($block->x >= $beginPos->x and $block->z >= $beginPos->z and $block->x < $endPos->x and $block->z < $endPos->z) {
             return true;
         }
         return false;
     });
     $event->setBlockList($blocks);
 }
コード例 #5
0
 public function explodeB()
 {
     $send = [];
     $updateBlocks = [];
     $source = (new Vector3($this->source->x, $this->source->y, $this->source->z))->floor();
     $yield = 1 / $this->size * 100;
     if ($this->what instanceof Entity) {
         $this->level->getServer()->getPluginManager()->callEvent($ev = new EntityExplodeEvent($this->what, $this->source, $this->affectedBlocks, $yield));
         if ($ev->isCancelled()) {
             return \false;
         } else {
             $yield = $ev->getYield();
             $this->affectedBlocks = $ev->getBlockList();
         }
     }
     $explosionSize = $this->size * 2;
     $minX = Math::floorFloat($this->source->x - $explosionSize - 1);
     $maxX = Math::ceilFloat($this->source->x + $explosionSize + 1);
     $minY = Math::floorFloat($this->source->y - $explosionSize - 1);
     $maxY = Math::ceilFloat($this->source->y + $explosionSize + 1);
     $minZ = Math::floorFloat($this->source->z - $explosionSize - 1);
     $maxZ = Math::ceilFloat($this->source->z + $explosionSize + 1);
     $explosionBB = new AxisAlignedBB($minX, $minY, $minZ, $maxX, $maxY, $maxZ);
     $list = $this->level->getNearbyEntities($explosionBB, $this->what instanceof Entity ? $this->what : \null);
     foreach ($list as $entity) {
         $distance = $entity->distance($this->source) / $explosionSize;
         if ($distance <= 1) {
             $motion = $entity->subtract($this->source)->normalize();
             $impact = (1 - $distance) * ($exposure = 1);
             $damage = (int) (($impact * $impact + $impact) / 2 * 8 * $explosionSize + 1);
             if ($this->what instanceof Entity) {
                 $ev = new EntityDamageByEntityEvent($this->what, $entity, EntityDamageEvent::CAUSE_ENTITY_EXPLOSION, $damage);
             } elseif ($this->what instanceof Block) {
                 $ev = new EntityDamageByBlockEvent($this->what, $entity, EntityDamageEvent::CAUSE_BLOCK_EXPLOSION, $damage);
             } else {
                 $ev = new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_BLOCK_EXPLOSION, $damage);
             }
             $entity->attack($ev->getFinalDamage(), $ev);
             $entity->setMotion($motion->multiply($impact));
         }
     }
     $air = Item::get(Item::AIR);
     foreach ($this->affectedBlocks as $block) {
         if ($block->getId() === Block::TNT) {
             $mot = (new Random())->nextSignedFloat() * M_PI * 2;
             $tnt = Entity::createEntity("PrimedTNT", $this->level->getChunk($block->x >> 4, $block->z >> 4), new Compound("", ["Pos" => new Enum("Pos", [new Double("", $block->x + 0.5), new Double("", $block->y), new Double("", $block->z + 0.5)]), "Motion" => new Enum("Motion", [new Double("", -\sin($mot) * 0.02), new Double("", 0.2), new Double("", -\cos($mot) * 0.02)]), "Rotation" => new Enum("Rotation", [new Float("", 0), new Float("", 0)]), "Fuse" => new Byte("Fuse", \mt_rand(10, 30))]));
             $tnt->spawnToAll();
         } elseif (\mt_rand(0, 100) < $yield) {
             foreach ($block->getDrops($air) as $drop) {
                 $this->level->dropItem($block->add(0.5, 0.5, 0.5), Item::get(...$drop));
             }
         }
         $this->level->setBlockIdAt($block->x, $block->y, $block->z, 0);
         $pos = new Vector3($block->x, $block->y, $block->z);
         for ($side = 0; $side < 5; $side++) {
             $sideBlock = $pos->getSide($side);
             if (!isset($this->affectedBlocks[$index = ($sideBlock->x & 0xfffffff) << 35 | ($sideBlock->y & 0x7f) << 28 | $sideBlock->z & 0xfffffff]) and !isset($updateBlocks[$index])) {
                 $this->level->getServer()->getPluginManager()->callEvent($ev = new BlockUpdateEvent($this->level->getBlock($sideBlock)));
                 if (!$ev->isCancelled()) {
                     $ev->getBlock()->onUpdate(Level::BLOCK_UPDATE_NORMAL);
                 }
                 $updateBlocks[$index] = \true;
             }
         }
         $send[] = new Vector3($block->x - $source->x, $block->y - $source->y, $block->z - $source->z);
     }
     $pk = new ExplodePacket();
     $pk->x = $this->source->x;
     $pk->y = $this->source->y;
     $pk->z = $this->source->z;
     $pk->radius = $this->size;
     $pk->records = $send;
     $this->level->addChunkPacket($source->x >> 4, $source->z >> 4, $pk);
     return \true;
 }
コード例 #6
0
 /**
  * @param EntityExplodeEvent $event
  */
 public function onTNTExplode(EntityExplodeEvent $event)
 {
     if ($event->getEntity()->namedtag->getName() === "EssNuke") {
         $event->setBlockList([]);
     }
 }
コード例 #7
0
 /**
  * @param EntityExplodeEvent $event
  * @priority HIGHEST
  * @ignoreCancelled true
  */
 public function onEntityExplode(EntityExplodeEvent $event)
 {
     if (!$this->plugin->getStorage()->getShield($event->getEntity()->getLevel())->isAllowed(Shield::EXPLODING)) {
         $event->setCancelled(true);
     }
 }
コード例 #8
0
 public function onEntityExplode(EntityExplodeEvent $event)
 {
     $Entity = $event->getEntity();
     $Level = $Entity->getLevel();
     if (!$this->plugin->game || $this->plugin->game->level_name != $Level->getFolderName()) {
         return;
     }
     $Blocks = $event->getBlockList();
     $Blocks2 = [];
     foreach ($Blocks as $Block) {
         foreach ($this->plugin->game->BlocksPlaced as $Block2) {
             if ($Block->getX() == $Block2->getX() && $Block->getY() == $Block2->getY() && $Block->getZ() == $Block2->getZ()) {
                 $Blocks2[] = $Block;
                 continue;
             }
         }
     }
     $event->setBlockList($Blocks2);
 }
コード例 #9
0
ファイル: EventManager.php プロジェクト: Tee7even/iZone
 /**
  * @param EntityExplodeEvent $event
  *
  * @priority        HIGH
  * @ignoreCancelled true
  */
 public function onEntityExplode(EntityExplodeEvent $event)
 {
     if ($this->plugin->getConfig()->get("protect-from-explosion", true) != true) {
         return;
     }
     $radius = $this->plugin->getConfig()->get("explosion-radius", 8);
     foreach ($this->plugin->getAllZones() as $zone) {
         if ($zone->isOnRadius($event->getPosition(), $radius)) {
             $owner = $this->plugin->getServer()->getPlayer($zone->getOwner());
             if ($owner instanceof Player) {
                 $owner->sendMessage('[iZone] Something explode near zone: ' . $zone->getName());
             }
             $event->setCancelled(true);
             break;
         }
     }
     return;
 }
コード例 #10
0
ファイル: Explosion.php プロジェクト: boybook/PocketMine-MP
 public function explode()
 {
     if ($this->size < 0.1) {
         return false;
     }
     $mRays = $this->rays - 1;
     for ($i = 0; $i < $this->rays; ++$i) {
         for ($j = 0; $j < $this->rays; ++$j) {
             for ($k = 0; $k < $this->rays; ++$k) {
                 if ($i == 0 or $i == $mRays or $j == 0 or $j == $mRays or $k == 0 or $k == $mRays) {
                     $vector = new Vector3($i / $mRays * 2 - 1, $j / $mRays * 2 - 1, $k / $mRays * 2 - 1);
                     //($i / $mRays) * 2 - 1
                     $vector = $vector->normalize()->multiply($this->stepLen);
                     $pointer = clone $this->source;
                     for ($blastForce = $this->size * (mt_rand(700, 1300) / 1000); $blastForce > 0; $blastForce -= $this->stepLen * 0.75) {
                         $vBlock = $pointer->floor();
                         $blockID = $this->level->getBlockIdAt($vBlock->x, $vBlock->y, $vBlock->z);
                         if ($blockID > 0) {
                             $block = Block::get($blockID, 0);
                             $block->x = $vBlock->x;
                             $block->y = $vBlock->y;
                             $block->z = $vBlock->z;
                             $blastForce -= ($block->getHardness() / 5 + 0.3) * $this->stepLen;
                             if ($blastForce > 0) {
                                 $index = ($block->x << 15) + ($block->z << 7) + $block->y;
                                 if (!isset($this->affectedBlocks[$index])) {
                                     $this->affectedBlocks[$index] = $block;
                                 }
                             }
                         }
                         $pointer = $pointer->add($vector);
                     }
                 }
             }
         }
     }
     $send = [];
     $source = $this->source->floor();
     $radius = 2 * $this->size;
     $yield = 1 / $this->size * 100;
     if ($this->what instanceof Entity) {
         Server::getInstance()->getPluginManager()->callEvent($ev = new EntityExplodeEvent($this->what, $this->source, $this->affectedBlocks, $yield));
         if ($ev->isCancelled()) {
             return false;
         } else {
             $yield = $ev->getYield();
             $this->affectedBlocks = $ev->getBlockList();
         }
     }
     //TODO
     /*foreach($server->api->entity->getRadius($this->source, $radius) as $entity){
     			$impact = (1 - $this->source->distance($entity) / $radius) * 0.5; //placeholder, 0.7 should be exposure
     			$damage = (int) (($impact * $impact + $impact) * 8 * $this->size + 1);
     			$entity->harm($damage, "explosion");
     		}*/
     foreach ($this->affectedBlocks as $block) {
         if ($block instanceof TNT) {
             $data = ["x" => $block->x + 0.5, "y" => $block->y + 0.5, "z" => $block->z + 0.5, "power" => 4, "fuse" => mt_rand(10, 30)];
             //TODO
             //$e = $server->api->entity->add($this->level, ENTITY_OBJECT, OBJECT_PRIMEDTNT, $data);
             //$e->spawnToAll();
         } elseif (mt_rand(0, 100) < $yield) {
             if (isset(self::$specialDrops[$block->getID()])) {
                 //TODO
                 //$server->api->entity->drop(new Position($block->x + 0.5, $block->y, $block->z + 0.5, $this->level), Item::get(self::$specialDrops[$block->getID()], 0));
             } else {
                 //TODO
                 //$server->api->entity->drop(new Position($block->x + 0.5, $block->y, $block->z + 0.5, $this->level), Item::get($block->getID(), $this->level->level->getBlockDamage($block->x, $block->y, $block->z)));
             }
         }
         $this->level->setBlockIdAt($block->x, $block->y, $block->z, 0);
         $send[] = new Vector3($block->x - $source->x, $block->y - $source->y, $block->z - $source->z);
     }
     $pk = new ExplodePacket();
     $pk->x = $this->source->x;
     $pk->y = $this->source->y;
     $pk->z = $this->source->z;
     $pk->radius = $this->size;
     $pk->records = $send;
     Server::broadcastPacket($this->level->getPlayers(), $pk);
 }
コード例 #11
0
ファイル: FirstBase.php プロジェクト: sJimin/PHPTEST
 public function onExplode(EntityExplodeEvent $event)
 {
     $event->setCancelled(true);
 }