상속: implements pocketmine\level\ChunkManager, implements pocketmine\metadata\Metadatable
예제 #1
1
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     if ($this->meta === Item::AIR) {
         if ($target instanceof Liquid) {
             $level->setBlock($target, new Air(), true);
             if (($player->gamemode & 0x1) === 0) {
                 $this->meta = $target instanceof Water ? Item::WATER : Item::LAVA;
             }
             return true;
         }
     } elseif ($this->meta === Item::WATER) {
         //Support Make Non-Support Water to Support Water
         if ($block->getID() === self::AIR || $block instanceof Water && ($block->getDamage() & 0x7) != 0x0) {
             $water = new Water();
             $level->setBlock($block, $water, true);
             $water->place(clone $this, $block, $target, $face, $fx, $fy, $fz, $player);
             if (($player->gamemode & 0x1) === 0) {
                 $this->meta = 0;
             }
             return true;
         }
     } elseif ($this->meta === Item::LAVA) {
         if ($block->getID() === self::AIR) {
             $level->setBlock($block, new Lava(), true);
             if (($player->gamemode & 0x1) === 0) {
                 $this->meta = 0;
             }
             return true;
         }
     }
     return false;
 }
예제 #2
1
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     $entity = null;
     $chunk = $level->getChunk($block->getX() >> 4, $block->getZ() >> 4);
     if (!$chunk instanceof FullChunk) {
         return false;
     }
     $nbt = new Compound("", ["Pos" => new Enum("Pos", [new Double("", $block->getX() + 0.5), new Double("", $block->getY()), new Double("", $block->getZ() + 0.5)]), "Motion" => new Enum("Motion", [new Double("", 0), new Double("", 0), new Double("", 0)]), "Rotation" => new Enum("Rotation", [new Float("", lcg_value() * 360), new Float("", 0)])]);
     $entity = Entity::createEntity($this->meta, $chunk, $nbt);
     if ($entity instanceof Entity) {
         if ($player->isSurvival()) {
             --$this->count;
         }
         $entity->spawnToAll();
         return true;
     }
     return false;
 }
예제 #3
0
 private function setBlock(Vector3 $p, Level $lvl, ItemBlock $b, $meta)
 {
     $block = $b->getBlock();
     $block->setDamage($meta);
     $lvl->setBlock($p, $b);
     return true;
 }
예제 #4
0
 public function isLevelCorrect(Level $level)
 {
     if ($this->world === "*") {
         return true;
     }
     return strtolower($level->getName()) === $this->world;
 }
예제 #5
0
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     if ($target->getId() == Block::MONSTER_SPAWNER) {
         return true;
     } else {
         $entity = null;
         $chunk = $level->getChunk($block->getX() >> 4, $block->getZ() >> 4);
         if (!$chunk instanceof FullChunk) {
             return false;
         }
         $nbt = new CompoundTag("", ["Pos" => new EnumTag("Pos", [new DoubleTag("", $block->getX() + 0.5), new DoubleTag("", $block->getY()), new DoubleTag("", $block->getZ() + 0.5)]), "Motion" => new EnumTag("Motion", [new DoubleTag("", 0), new DoubleTag("", 0), new DoubleTag("", 0)]), "Rotation" => new EnumTag("Rotation", [new FloatTag("", lcg_value() * 360), new FloatTag("", 0)])]);
         if ($this->hasCustomName()) {
             $nbt->CustomName = new StringTag("CustomName", $this->getCustomName());
         }
         $entity = Entity::createEntity($this->meta, $chunk, $nbt);
         if ($entity instanceof Entity) {
             if ($player->isSurvival()) {
                 --$this->count;
             }
             $entity->spawnToAll();
             return true;
         }
     }
     return false;
 }
예제 #6
0
 public function __construct(Level $level)
 {
     $name = $level->getFolderName() . " - ";
     $this->mobSpawn = new TimingsHandler("** " . $name . "mobSpawn");
     $this->doChunkUnload = new TimingsHandler("** " . $name . "doChunkUnload");
     $this->doTickPending = new TimingsHandler("** " . $name . "doTickPending");
     $this->doTickTiles = new TimingsHandler("** " . $name . "doTickTiles");
     $this->doVillages = new TimingsHandler("** " . $name . "doVillages");
     $this->doChunkMap = new TimingsHandler("** " . $name . "doChunkMap");
     $this->doSounds = new TimingsHandler("** " . $name . "doSounds");
     $this->doChunkGC = new TimingsHandler("** " . $name . "doChunkGC");
     $this->doPortalForcer = new TimingsHandler("** " . $name . "doPortalForcer");
     $this->entityTick = new TimingsHandler("** " . $name . "entityTick");
     $this->tileEntityTick = new TimingsHandler("** " . $name . "tileEntityTick");
     $this->tileEntityPending = new TimingsHandler("** " . $name . "tileEntityPending");
     $this->syncChunkSendTimer = new TimingsHandler("** " . $name . "syncChunkSend");
     $this->syncChunkSendPrepareTimer = new TimingsHandler("** " . $name . "syncChunkSendPrepare");
     $this->syncChunkLoadTimer = new TimingsHandler("** " . $name . "syncChunkLoad");
     $this->syncChunkLoadDataTimer = new TimingsHandler("** " . $name . "syncChunkLoad - Data");
     $this->syncChunkLoadStructuresTimer = new TimingsHandler("** " . $name . "syncChunkLoad - Structures");
     $this->syncChunkLoadEntitiesTimer = new TimingsHandler("** " . $name . "syncChunkLoad - Entities");
     $this->syncChunkLoadTileEntitiesTimer = new TimingsHandler("** " . $name . "syncChunkLoad - TileEntities");
     $this->syncChunkLoadTileTicksTimer = new TimingsHandler("** " . $name . "syncChunkLoad - TileTicks");
     $this->syncChunkLoadPostTimer = new TimingsHandler("** " . $name . "syncChunkLoad - Post");
     $this->tracker = new TimingsHandler($name . "tracker");
     $this->doTick = new TimingsHandler($name . "doTick");
     $this->tickEntities = new TimingsHandler($name . "tickEntities");
 }
예제 #7
0
 public function __construct(Level $level, FullChunk $chunk)
 {
     $this->state = true;
     $this->levelId = $level->getId();
     $this->chunk = $chunk->toFastBinary();
     $this->chunkClass = get_class($chunk);
 }
 /**
  * @param Level $level
  * @return Shield|null
  */
 public function getShield(Level $level)
 {
     if (isset($this->shields[strtolower($level->getName())])) {
         return $this->shields[strtolower($level->getName())];
     }
     return null;
 }
예제 #9
0
 public function __construct(Level $level, Generator $generator)
 {
     $this->generator = get_class($generator);
     $this->settings = $generator->getSettings();
     $this->seed = $level->getSeed();
     $this->levelId = $level->getId();
 }
예제 #10
0
 public static function isRegistered(Level $level)
 {
     if (isset(self::$registeredLevel[$level->getName()])) {
         return true;
     }
     return false;
 }
예제 #11
0
 public function __construct(Level $level, Generator $generator)
 {
     $this->generator = get_class($generator);
     $this->waterHeight = $generator->getWaterHeight();
     $this->settings = serialize($generator->getSettings());
     $this->seed = $level->getSeed();
     $this->levelId = $level->getId();
 }
 public function __construct(Level $level, $duration = 1200)
 {
     $this->level = $level;
     $this->weatherNow = self::SUNNY;
     $this->duration = $duration;
     $this->lastUpdate = $level->getServer()->getTick();
     $this->temporalVector = new Vector3(0, 0, 0);
 }
예제 #13
0
 public function getWorldLoadedData(Level $level)
 {
     $temp_config = $this->getUserData();
     if (!isset($temp_config["worlds"][$level->getName()])) {
         $temp_config["worlds"][$level->getName()] = array("group" => $this->plugin->getDefaultGroup()->getName(), "permissions" => array());
         $this->setUserData($temp_config);
     }
     return $this->getUserData();
 }
예제 #14
0
 public function getWorldLoadedData(Level $level)
 {
     $temp_config = $this->plugin->getGroupsData();
     if (!isset($temp_config[$this->groupName]["worlds"][$level->getName()])) {
         $this->plugin->getLogger()->warning("Permissions not set in " . $this->groupName . " in level: " . $level->getName() . ".");
         $temp_config[$this->groupName]["worlds"][$level->getName()] = array("permissions" => array());
         $this->plugin->setGroupsData($temp_config);
     }
     return $this->plugin->getGroupsData();
 }
 public function onUnload(ChunkUnloadEvent $event)
 {
     if ($event->getLevel() === $this->level) {
         foreach ($this->locs[Level::chunkHash($event->getChunk()->getX(), $event->getChunk()->getZ())] as $id => $spawn) {
             if (isset($this->spawns[$spawn->getId()])) {
                 $this->level->removeEntity($this->spawns[$spawn->getId()]);
             }
         }
     }
 }
예제 #16
0
 public function setMetadata($block, $metadataKey, MetadataValue $newMetadatavalue)
 {
     if (!$block instanceof Block) {
         throw new \InvalidArgumentException("Object must be a Block");
     }
     if ($block->getLevel() === $this->owningLevel) {
         parent::setMetadata($block, $metadataKey, $newMetadatavalue);
     } else {
         throw new \InvalidStateException("Block does not belong to world " . $this->owningLevel->getName());
     }
 }
예제 #17
0
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     if (($player->gamemode & 0x1) === 0 and $this->useOn($block) and $this->getDamage() >= $this->getMaxDurability()) {
         $player->getInventory()->setItemInHand(new Item(Item::AIR, 0, 0));
     }
     if ($block->getId() === self::AIR and $target instanceof Solid) {
         $level->setBlock($block, new Fire(), \true);
         return \true;
     }
     return \false;
 }
예제 #18
0
 public function sideCheck($x, $y, $z, Level $level, $name)
 {
     if ($level->getBlockIdAt($x, $y, $z) == Block::CHEST) {
         if (isset($this->configData["{$x}:{$y}:{$z}"])) {
             if ($this->configData["{$x}:{$y}:{$z}"] != $name) {
                 return true;
             }
         }
     }
     return false;
 }
예제 #19
0
 public static function addParticles(Level $level, $name, Position $pos1, $count = 5)
 {
     $xd = (double) 280;
     $yd = (double) 260;
     $zd = (double) 280;
     $particle1 = self::getParticle($name, $pos1, $xd, $yd, $zd, 0);
     $random = new Random((int) (\microtime(\true) * 1000) + \mt_rand());
     for ($i = 0; $i < $count; ++$i) {
         $particle1->setComponents($pos1->x + $random->nextSignedFloat() * $xd, $pos1->y + $random->nextSignedFloat() * $yd, $pos1->z + $random->nextSignedFloat() * $zd);
         $level->addParticle($particle1);
     }
 }
예제 #20
0
 public function delHome(IPlayer $player, Level $level)
 {
     $n = strtolower($player->getName());
     $l = "l-" . strtolower($level->getName());
     if (!isset($this->homes[$l]) || !isset($this->homes[$l][$n])) {
         return;
     }
     unset($this->homes[$l][$n]);
     if (count($this->homes[$l]) == 0) {
         unset($this->homes[$l]);
     }
     $this->saveHomes();
 }
예제 #21
0
 public function __construct(Level $level, FullChunk $chunk)
 {
     $this->state = true;
     $this->levelId = $level->getId();
     $this->chunk = $chunk->toFastBinary();
     $this->chunkClass = get_class($chunk);
     $this->chunk00 = $level->getChunk($chunk->getX() - 1, $chunk->getZ() - 1, true)->toFastBinary();
     $this->chunk01 = $level->getChunk($chunk->getX() - 1, $chunk->getZ(), true)->toFastBinary();
     $this->chunk02 = $level->getChunk($chunk->getX() - 1, $chunk->getZ() + 1, true)->toFastBinary();
     $this->chunk10 = $level->getChunk($chunk->getX(), $chunk->getZ() - 1, true)->toFastBinary();
     $this->chunk12 = $level->getChunk($chunk->getX(), $chunk->getZ() + 1, true)->toFastBinary();
     $this->chunk20 = $level->getChunk($chunk->getX() + 1, $chunk->getZ() - 1, true)->toFastBinary();
     $this->chunk21 = $level->getChunk($chunk->getX() + 1, $chunk->getZ(), true)->toFastBinary();
     $this->chunk22 = $level->getChunk($chunk->getX() + 1, $chunk->getZ() + 1, true)->toFastBinary();
 }
예제 #22
0
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     if (!$target instanceof Fence) {
         return false;
     }
     foreach ($level->getChunkEntities($target->x >> 4, $target->z >> 4) as $entity) {
         if ($entity->isLeashed()) {
             if ($entity->leadHolder === $player->getId()) {
                 $nbt = new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $block->getX() + 0.5), new DoubleTag("", $block->getY()), new DoubleTag("", $block->getZ() + 0.5)]), "Motion" => new ListTag("Motion", [new DoubleTag("", 0), new DoubleTag("", 0), new DoubleTag("", 0)]), "Rotation" => new ListTag("Rotation", [new FloatTag("", lcg_value() * 360), new FloatTag("", 0)])]);
                 $level->addEntity($knot = new LeashKnot($level->getChunkAt($target->x >> 4, $target->z >> 4), $nbt));
                 $entity->setLeashHolder($knot);
             }
         }
     }
 }
예제 #23
0
 public function __construct(Level $level, FullChunk $chunk)
 {
     $this->state = \true;
     $this->levelId = $level->getId();
     $this->chunk = $chunk->toFastBinary();
     $this->chunkClass = \get_class($chunk);
     for ($i = 0; $i < 9; ++$i) {
         if ($i === 4) {
             continue;
         }
         $xx = -1 + $i % 3;
         $zz = -1 + (int) ($i / 3);
         $ck = $level->getChunk($chunk->getX() + $xx, $chunk->getZ() + $zz, \false);
         $this->{"chunk{$i}"} = $ck !== \null ? $ck->toFastBinary() : \null;
     }
 }
예제 #24
0
 public function onUnloadChunk(ChunkUnloadEvent $event)
 {
     if ($event->getLevel()->getName() !== "world_pvp") {
         return;
     }
     $chunk = $event->getChunk();
     $hash = Level::chunkHash($chunk->getX(), $chunk->getZ());
     if (isset($this->modelLocs[$hash])) {
         foreach ($this->modelLocs[$hash] as $id => $model) {
             if (isset($this->models[$id])) {
                 $this->models[$id]->_kill();
                 unset($this->models[$id]);
             }
         }
     }
     if (isset($this->shopLocs[$hash])) {
         foreach ($this->shopLocs[$hash] as $col => $loc) {
             if (isset($this->shops[$col])) {
                 $this->shops[$col]->_kill();
                 unset($this->shops[$col]);
             }
         }
     }
     if ($hash === $this->bowHash) {
         $this->bow->_kill();
         $this->bow = null;
     }
 }
예제 #25
0
 public function __construct(Level $level, Chunk $chunk)
 {
     $this->levelId = $level->getId();
     $this->chunk = $chunk->toFastBinary();
     $this->chunkX = $chunk->getX();
     $this->chunkZ = $chunk->getZ();
     $tiles = "";
     $nbt = new NBT(NBT::LITTLE_ENDIAN);
     foreach ($chunk->getTiles() as $tile) {
         if ($tile instanceof Spawnable) {
             $nbt->setData($tile->getSpawnCompound());
             $tiles .= $nbt->write();
         }
     }
     $this->tiles = $tiles;
 }
예제 #26
0
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     $entity = null;
     $chunk = $level->getChunkAt($block->getX() >> 4, $block->getZ() >> 4);
     if (!$chunk instanceof FullChunk) {
         return false;
     }
     $nbt = new Compound("", ["Pos" => new Enum("Pos", [new Double("", $block->getX()), new Double("", $block->getY()), new Double("", $block->getZ())]), "Motion" => new Enum("Motion", [new Double("", 0), new Double("", 0), new Double("", 0)]), "Rotation" => new Enum("Rotation", [new Float("", lcg_value() * 360), new Float("", 0)])]);
     switch ($this->meta) {
         case Villager::NETWORK_ID:
             $nbt->Health = new Short("Health", 20);
             $entity = new Villager($chunk, $nbt);
             break;
         case Zombie::NETWORK_ID:
             $nbt->Health = new Short("Health", 20);
             $entity = new Zombie($chunk, $nbt);
             break;
             /*
             			//TODO: use entity constants
             			case 10:
             			case 11:
             			case 12:
             			case 13:
             				$data = array(
             					"x" => $block->x + 0.5,
             					"y" => $block->y,
             					"z" => $block->z + 0.5,
             				);
             				//$e = Server::getInstance()->api->entity->add($block->level, ENTITY_MOB, $this->meta, $data);
             				//Server::getInstance()->api->entity->spawnToAll($e);
             				if(($player->gamemode & 0x01) === 0){
             					--$this->count;
             				}
             
             				return true;*/
     }
     if ($entity instanceof Entity) {
         if (($player->gamemode & 0x1) === 0) {
             --$this->count;
         }
         $entity->spawnToAll();
         return true;
     }
     return false;
 }
예제 #27
0
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     $blockTemp = $level->getBlock($block->add(0, -1, 0));
     //if($blockTemp->getId() != self::RAIL and $blockTemp->getId() != self::POWERED_RAIL) return;
     $minecart = new MinecartEntity($player->getLevel()->getChunk($block->getX() >> 4, $block->getZ() >> 4), new CompoundTag("", ["Pos" => new EnumTag("Pos", [new DoubleTag("", $block->getX()), new DoubleTag("", $block->getY() + 1), new DoubleTag("", $block->getZ())]), "Motion" => new EnumTag("Motion", [new DoubleTag("", 0), new DoubleTag("", 0), new DoubleTag("", 0)]), "Rotation" => new EnumTag("Rotation", [new FloatTag("", 0), new FloatTag("", 0)])]));
     $minecart->spawnToAll();
     if ($player->isSurvival()) {
         $item = $player->getInventory()->getItemInHand();
         $count = $item->getCount();
         if (--$count <= 0) {
             $player->getInventory()->setItemInHand(Item::get(Item::AIR));
             return;
         }
         $item->setCount($count);
         $player->getInventory()->setItemInHand($item);
     }
     return true;
 }
예제 #28
0
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     $blockTemp = $level->getBlock($block->add(0, -1, 0));
     //if(!$block instanceof RailBlock || !$block instanceof Rail) return false; in previuos version IM
     //if($blockTemp->getId() != self::RAIL and $blockTemp->getId() != self::POWERED_RAIL) return; in previuos version Genisys
     $minecart = new MinecartEntity($player->getLevel()->getChunk($block->getX() >> 4, $block->getZ() >> 4), new Compound("", array("Pos" => new Enum("Pos", array(new Double("", $block->getX()), new Double("", $block->getY() + 1), new Double("", $block->getZ()))), "Motion" => new Enum("Motion", array(new Double("", 0), new Double("", 0), new Double("", 0))), "Rotation" => new Enum("Rotation", array(new Float("", 0), new Float("", 0))))));
     $minecart->spawnToAll();
     if ($player->isSurvival()) {
         $item = $player->getInventory()->getItemInHand();
         $count = $item->getCount();
         if (--$count <= 0) {
             $player->getInventory()->setItemInHand(Item::get(Item::AIR));
             return;
         }
         $item->setCount($count);
         $player->getInventory()->setItemInHand($item);
     }
     return true;
 }
예제 #29
0
 public function __construct(Level $level, Vector3 $pos)
 {
     if (!($pos instanceof Vector3 && $level instanceof Level)) {
         echo "this is not Floor!\n";
     }
     $this->vector = $pos;
     $this->x = $pos->getX();
     $this->y = $pos->getY();
     $this->z = $pos->getZ();
     $this->level = $level;
     $this->block = $level->getBlock($pos);
     $this->id = $this->block->getId();
     $this->data = $this->block->getDamage();
     $this->height = 128;
     //$this->level->getHeightMap($this->x, $this->z);
     echo "max height: {$this->height}\n";
     if (!($this->isElevatorBlock($this->block) || $this->isExtensionFloorBlock($this->block))) {
         echo "THIS IS NOT FLOOR!\n";
     }
 }
예제 #30
0
 public function startGame()
 {
     $this->game = 2;
     $msg = Messages::getMsg("started", ["%NAME", $this->name]);
     $sound = new AnvilUseSound(new Vector3());
     foreach ($this->players as $p) {
         /** @var Player $pl */
         $pl = $p["ins"];
         $pl->sendMessage($msg);
         $sound->setComponents($pl->x, $pl->y, $pl->z);
         $this->level->addSound($sound, [$pl]);
     }
 }