getLevel() public method

public getLevel ( ) : Level
return Level
 /**
  * Really starts the duel after countdown
  */
 public function startDuel()
 {
     Server::getInstance()->getScheduler()->cancelTask($this->countdownTaskHandler->getTaskId());
     $player1 = $this->players[0];
     $player2 = $this->players[1];
     $pos_player1 = Position::fromObject($this->position, $this->position->getLevel());
     $pos_player1->x += self::PLAYER_1_OFFSET_X;
     $pos_player2 = Position::fromObject($this->position, $this->position->getLevel());
     $pos_player2->x += self::PLAYER_2_OFFSET_X;
     $player1->teleport($pos_player1, 90, 0);
     $player2->teleport($pos_player2, -90, 0);
     // Fix start time
     $this->startTime = new DateTime('now');
     $player1->sendTip(TextFormat::RED . "You are strarting a duel !");
     $player1->sendMessage(" ");
     $player1->sendMessage(TextFormat::RED . TextFormat::BOLD . "++++++++=++++++++");
     $player1->sendMessage(TextFormat::AQUA . ">" . TextFormat::RESET . " You're starting a duel against : " . $player2->getName() . " !");
     $player1->sendMessage(TextFormat::AQUA . ">" . TextFormat::RESET . " You have 3min !");
     $player1->sendMessage(TextFormat::AQUA . ">" . TextFormat::RESET . " Good luck :) !");
     $player1->sendMessage(TextFormat::RED . TextFormat::BOLD . "++++++++=++++++++");
     $player1->sendMessage(" ");
     $player1->sendTip(TextFormat::RED . "You are strarting a duel !");
     $player2->sendMessage(" ");
     $player2->sendMessage(TextFormat::RED . TextFormat::BOLD . "++++++++=++++++++");
     $player2->sendMessage(TextFormat::AQUA . ">" . TextFormat::RESET . " You're starting a duel against : " . $player1->getName() . " !");
     $player2->sendMessage(TextFormat::AQUA . ">" . TextFormat::RESET . " You have 3min !");
     $player2->sendMessage(TextFormat::AQUA . ">" . TextFormat::RESET . " Good luck :) !");
     $player2->sendMessage(TextFormat::RED . TextFormat::BOLD . "++++++++=++++++++");
     $player2->sendMessage(" ");
     // Launch the end round task
     $task = new RoundCheckTask(OneVsOne::getInstance());
     $task->arena = $this;
     $this->taskHandler = Server::getInstance()->getScheduler()->scheduleDelayedTask($task, self::ROUND_DURATION * 20);
 }
Esempio n. 2
0
 /**
  * Really starts the duel after countdown
  */
 public function startDuel()
 {
     Server::getInstance()->getScheduler()->cancelTask($this->countdownTaskHandler->getTaskId());
     $player1 = $this->players[0];
     $player2 = $this->players[1];
     $pos_player1 = Position::fromObject($this->position, $this->position->getLevel());
     $pos_player1->x += self::PLAYER_1_OFFSET_X;
     $pos_player2 = Position::fromObject($this->position, $this->position->getLevel());
     $pos_player2->x += self::PLAYER_2_OFFSET_X;
     $player1->teleport($pos_player1, 90, 0);
     $player2->teleport($pos_player2, -90, 0);
     $this->sparyParticle($player1);
     $this->sparyParticle($player2);
     $player1->setGamemode(0);
     $player2->setGamemode(0);
     // Give kit
     foreach ($this->players as $player) {
         $this->giveKit($player);
     }
     // Fix start time
     $this->startTime = new DateTime('now');
     $player1->sendTip(OneVsOne::getMessage("duel_tip"));
     $player1->sendMessage(OneVsOne::getMessage("duel_start"));
     $player2->sendTip(OneVsOne::getMessage("duel_tip"));
     $player2->sendMessage(OneVsOne::getMessage("duel_start"));
     // Launch the end round task
     $task = new RoundCheckTask(OneVsOne::getInstance());
     $task->arena = $this;
     $this->taskHandler = Server::getInstance()->getScheduler()->scheduleDelayedTask($task, self::ROUND_DURATION * 20);
 }
Esempio n. 3
0
 public function execute(CommandSender $sender, $commandLabel, array $args)
 {
     if (!$this->testPermission($sender)) {
         return true;
     }
     if (!$sender instanceof Player and count($args) < 4) {
         $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
         return false;
     }
     if ($sender instanceof Player and count($args) < 4) {
         $pos = $sender->getPosition();
     } else {
         $level = $sender->getServer()->getLevelByName($args[3]);
         if (!$level instanceof Level) {
             $sender->sendMessage(TextFormat::RED . "Invalid level name");
             return false;
         }
         $pos = new Position((int) $args[0], (int) $args[1], (int) $args[2], $level);
     }
     if (!isset($args[4]) or $args[0] != "regenerate") {
         $chunk = $pos->getLevel()->getChunk($pos->x >> 4, $pos->z >> 4);
         McRegion::getRegionIndex($chunk->getX(), $chunk->getZ(), $x, $z);
         $sender->sendMessage("Region X: {$x} Region Z: {$z}");
     } elseif ($args[4] == "regenerate") {
         foreach ($sender->getServer()->getOnlinePlayers() as $p) {
             if ($p->getLevel() == $pos->getLevel()) {
                 $p->kick(TextFormat::AQUA . "A chunk of this chunk is regenerating, please re-login.", false);
             }
         }
         $pos->getLevel()->regenerateChunk($pos->x >> 4, $pos->z >> 4);
     }
     return true;
 }
Esempio n. 4
0
 public function getChest()
 {
     if ($this->hasPattern()) {
         return $this->pattern->getChestTile();
     }
     $tile = $this->position->getLevel()->getTile($this->position);
     if ($tile instanceof \pocketmine\tile\Chest) {
         return $tile;
     } else {
         return false;
     }
 }
Esempio n. 5
0
 public function spawnTo(Player $player)
 {
     if ($player->getLevel() === $this->pos->getLevel()) {
         $pk = new AddItemEntityPacket();
         $pk->eid = $this->eid;
         $pk->item = $this->item;
         $pk->x = $this->pos->x + 0.5;
         $pk->y = $this->pos->y;
         $pk->z = $this->pos->z + 0.5;
         $pk->speedX = $pk->speedY = $pk->speedZ = 0;
         $player->dataPacket($pk);
     }
 }
 public function __construct(Position $a, Vector3 $b)
 {
     $this->raw0 = $a;
     if (!$b instanceof Position) {
         $b = new Position($b->getX(), $b->getY(), $b->getZ(), $a->getLevel());
     }
     $this->raw1 = $b;
     if ($a->getLevel()->getName() !== $b->getLevel()->getName()) {
         trigger_error("Positions of different levels (\"" . $a->getLevel()->getName() . "\" and \"" . $b->getLevel()->getName() . "\" passed to constructor of " . get_class($this), E_USER_WARNING);
     }
     $this->bake();
     parent::__construct();
     // call this at the last because it has to bake before acquiring
 }
Esempio n. 7
0
 public function putPosition(Position $position)
 {
     $this->putLong($position->x);
     $this->putShort($position->y);
     $this->putLong($position->z);
     $this->putString($position->isValid() ? $position->getLevel()->getName() : "");
 }
 public function setHome(IPlayer $player, Position $pos)
 {
     $n = strtolower($player->getName());
     $l = "l-" . strtolower($pos->getLevel()->getName());
     $this->homes[$l][$n] = [$pos->getX(), $pos->getY(), $pos->getZ()];
     $this->saveHomes();
 }
 public function __construct(Position $center, $size, $what = \null)
 {
     $this->level = $center->getLevel();
     $this->source = $center;
     $this->size = \max($size, 0);
     $this->what = $what;
 }
Esempio n. 10
0
 public static function runNoteBlockSound(Position $pos, $pitch, $type = NoteBlock::PIANO_OR_HARP, $players = null)
 {
     if (!is_array($players)) {
         if ($players instanceof Player) {
             $players = [$players];
         } elseif ($players == null) {
             $players = $pos->getLevel()->getChunkPlayers($pos->x >> 4, $pos->z >> 4);
         } else {
             return false;
         }
     }
     $soundPk = new BlockEventPacket();
     $soundPk->x = $pos->x;
     $soundPk->y = $pos->y;
     $soundPk->z = $pos->z;
     $soundPk->case1 = $type;
     $soundPk->case2 = $pitch;
     $setNoteBlockPk = new UpdateBlockPacket();
     $setNoteBlockPk->records[] = [$pos->x, $pos->z, $pos->y, 25, 0, UpdateBlockPacket::FLAG_NONE];
     $realBlock = $pos->getLevel()->getBlock($pos);
     $setRealBlockPk = new UpdateBlockPacket();
     $setRealBlockPk->records[] = [$pos->x, $pos->z, $pos->y, $realBlock->getID(), $realBlock->getDamage(), UpdateBlockPacket::FLAG_NONE];
     Server::getInstance()->batchPackets($players, [$setNoteBlockPk, $soundPk, $setRealBlockPk], false);
     return true;
 }
Esempio n. 11
0
 public function __construct(Position $center, $size, $what = null, bool $dropItem = true)
 {
     $this->level = $center->getLevel();
     $this->source = $center;
     $this->size = max($size, 0);
     $this->what = $what;
     $this->dropItem = $dropItem;
 }
 public function operate(Position $anchor)
 {
     if (is_int($this->delta)) {
         throw new \BadMethodCallException("MacroOperation is of type TRUE (wait) not FALSE (operate) thus cannot be operated");
     }
     $anchor->getLevel()->setBlock($anchor->add($this->delta), $this->block, false, true);
     // update
 }
Esempio n. 13
0
 public static function dropExpOrb__api200(Position $source, $exp = 1, Vector3 $motion = \null, $delay = 40)
 {
     $motion = $motion === \null ? new Vector3(\lcg_value() * 0.2 - 0.1, 0.4, \lcg_value() * 0.2 - 0.1) : $motion;
     $entity = Entity::createEntity("ExperienceOrb", $source->getLevel()->getChunk($source->getX() >> 4, $source->getZ() >> 4, \true), new \pocketmine\nbt\tag\CompoundTag("", ["Pos" => new \pocketmine\nbt\tag\ListTag("Pos", [new \pocketmine\nbt\tag\DoubleTag("", $source->getX()), new \pocketmine\nbt\tag\DoubleTag("", $source->getY()), new \pocketmine\nbt\tag\DoubleTag("", $source->getZ())]), "Motion" => new \pocketmine\nbt\tag\ListTag("Motion", [new \pocketmine\nbt\tag\DoubleTag("", $motion->x), new \pocketmine\nbt\tag\DoubleTag("", $motion->y), new \pocketmine\nbt\tag\DoubleTag("", $motion->z)]), "Rotation" => new \pocketmine\nbt\tag\ListTag("Rotation", [new \pocketmine\nbt\tag\FloatTag("", \lcg_value() * 360), new \pocketmine\nbt\tag\FloatTag("", 0)]), "Health" => new \pocketmine\nbt\tag\ShortTag("Health", 20), "PickupDelay" => new \pocketmine\nbt\tag\ShortTag("PickupDelay", $delay)]));
     if ($entity instanceof ExperienceOrb) {
         $entity->setExp($exp);
     }
     $entity->spawnToAll();
 }
 public function savePosition(Position $pos, $pitch = 0, $yaw = 0)
 {
     $this->data["x"] = $pos->x;
     $this->data["y"] = $pos->y;
     $this->data["z"] = $pos->z;
     $this->data["pitch"] = $pitch;
     $this->data["yaw"] = $yaw;
     $this->data["levelName"] = $pos->getLevel()->getFolderName();
 }
Esempio n. 15
0
 public function checkMove(Position $p)
 {
     if (!$this->cfg["mines"]) {
         return false;
     }
     $bl = [];
     for ($i = 1; $i < 4; $i++) {
         $bl[$i] = $p->getLevel()->getBlockIdAt($p->getX(), $p->getY() - $i, $p->getZ());
     }
     for ($i = 1; $i < 3; $i++) {
         if ($bl[$i] == $this->mine["block1"]) {
             if (isset($this->mine["block2"]) && $this->mine["block2"] != $bl[$i + 1]) {
                 continue;
             }
             // explode!
             $p->getLevel()->setBlockIdAt($p->getX(), $p->getY() - $i, $p->getZ(), 0);
             $this->scorchit(new Position($p->getX() + 0.5, $p->getY() - $i + 0.5, $p->getZ() + 0.5, $p->getLevel()), new Vector3(0, 0, 0), 1);
             return false;
         }
     }
     return false;
 }
Esempio n. 16
0
 /**
  * @param Position $pos
  * @return Area|null
  */
 public function searchAreaByPosition(Position $pos)
 {
     foreach ($this->getAreas() as $area) {
         $l = $area->getShape()->getLevelName();
         if ($l !== $pos->getLevel()->getName()) {
             continue;
         }
         if ($area->getShape()->isInside($pos)) {
             return $area;
         }
     }
     return null;
 }
Esempio n. 17
0
 /**
  * @param Position $position
  * @param $radius
  *
  * @return bool
  */
 public function isOnRadius(Position $position, $radius)
 {
     if ($this->minX - $radius <= $position->x && $position->x <= $this->maxX + $radius) {
         if ($this->minY - $radius <= $position->y && $position->y <= $this->maxY + $radius) {
             if ($this->minZ - $radius <= $position->z && $position->z <= $this->maxZ + $radius) {
                 if ($position->getLevel()->getName() === $this->levelName) {
                     return true;
                 }
             }
         }
     }
     return false;
 }
Esempio n. 18
0
 /**
  * Teleport a player near a location
  * @param Player $player - player to be teleported
  * @param Position $target - location to teleport nearby
  * @param int $rand - how far to randomize positions
  * @param int|null $dist - if not null it will make sure that new location is upto $dist
  * @return bool - true on success, false on failure
  */
 public static function tpNearBy(Player $player, Position $target, $rand = 3, $dist = null)
 {
     $mv = new Vector3($target->getX() + mt_rand(-$rand, $rand), $target->getY(), $target->getZ() + mt_rand(-$rand, $rand));
     $pos = $target->getLevel()->getSafeSpawn($mv);
     if ($dist !== null) {
         $newdist = $pos->distance($target);
         if ($newdist > $dist) {
             return false;
         }
         // Will not get close enough!
     }
     $player->teleport($pos);
     return true;
 }
Esempio n. 19
0
 public function toString()
 {
     if ($this->isInternal()) {
         if ($this->position instanceof WeakPosition) {
             $levelName = $this->position->levelName;
         } else {
             $levelName = $this->position->getLevel()->getName();
         }
         if ($this->getApi()->getConfigItem("display-exact-coordinates")) {
             return "(X: {$this->getPosition()->x}, Y: {$this->getPosition()->y}, Z: {$this->getPosition()->z}, LEVEL: {$levelName}) ";
         } else {
             return "(X: {$this->getPosition()->getFloorX()}, Y: {$this->getPosition()->getFloorY()}, Z: {$this->getPosition()->getFloorZ()}, LEVEL: " . $levelName . ")";
         }
     }
     return "(IP: {$this->getAddress()}, PORT: {$this->getPort()})";
 }
 public function setWarp($name, Position $pos)
 {
     $n = strtolower($name);
     if ($n == "version") {
         return false;
     }
     $this->warps[$n] = [$pos->getX(), $pos->getY(), $pos->getZ(), $pos->getLevel()->getName()];
     return $this->saveWarps();
 }
Esempio n. 21
0
 /**
  *
  * @param Position $p1        	
  * @param Position $p2        	
  * @param unknown $block        	
  * @param string $output        	
  * @return boolean
  */
 public function setGate(Position $p1, Position $p2, $block, &$output = null)
 {
     $send = false;
     $level = $p1->getLevel();
     $bcnt = 1;
     $startX = min($p1->x, $p2->x);
     $endX = max($p1->x, $p2->x);
     $startY = min($p1->y, $p2->y);
     $endY = max($p1->y, $p2->y);
     $startZ = min($p1->z, $p2->z);
     $endZ = max($p1->z, $p2->z);
     $count = 0;
     for ($x = $startX; $x <= $endX; ++$x) {
         for ($y = $startY; $y <= $endY; ++$y) {
             for ($z = $startZ; $z <= $endZ; ++$z) {
                 $level->setBlock(new Position($x, $y, $z), $block, false, true);
                 $count++;
             }
         }
     }
     $output .= "{$count} block(s) have been updated.\n";
     return true;
 }
Esempio n. 22
0
 public function getLocByBlock(Position $block)
 {
     return $block->getFloorX() . ";" . $block->getFloorY() . ";" . $block->getFloorZ() . ";" . $block->getLevel()->getFolderName();
 }
Esempio n. 23
0
 public function getLocationByPosition(Position $pos)
 {
     return $pos->getLevel()->getFolderName() . ";" . $pos->getX() . ";" . $pos->getY() . ";" . $pos->getZ();
 }
Esempio n. 24
0
 public function snowShoot(Position $pos)
 {
     $player = Entity::Human;
     $nbt = new Compound("", [new Enum("Pos", [new Double("", $pos->getX()), new Double("", $pos->getY()), new Double("", $pos->getZ())]), new Enum("Motion", [new Double("", 0.0), new Double("", 1.0), new Double("", 0.0)])]);
     $snow = Entity::createEntity('Snowball', $pos->getLevel()->getChunk($pos->getX() >> 4, $pos->getY() >> 4, $pos->getZ() >> 4, $nbt));
     $snow->spawnToAll();
     $snow->canCollideWith($player);
     return $snow->getId();
 }
Esempio n. 25
0
 public function setSpawnPoint(Position $pos)
 {
     $this->plugin->warDB["spawn"]["red-team"]["pos"] = (int) $pos->getX() . "." . (int) $pos->getY() . "." . (int) $pos->getZ();
     $this->plugin->warDB["spawn"]["red-team"]["level"] = $pos->getLevel()->getName();
 }
Esempio n. 26
0
 private function W_remove($clipboard, Position $pos)
 {
     if (count($clipboard) !== 2) {
         return;
     }
     $clipboard[0][0] += $pos->x - 0.5;
     $clipboard[0][1] += $pos->y;
     $clipboard[0][2] += $pos->z - 0.5;
     $offset = array_map("round", $clipboard[0]);
     $count = 0;
     $l = $pos->getLevel();
     foreach ($clipboard[1] as $x => $i) {
         foreach ($i as $y => $j) {
             foreach ($j as $z => $block) {
                 $pk = new UpdateBlockPacket();
                 $pk->x = $x + $offset[0];
                 $pk->y = $y + $offset[1];
                 $pk->z = $z + $offset[2];
                 $pk->block = $l->getBlockIdAt($pk->x, $pk->y, $pk->z);
                 $pk->meta = $l->getBlockDataAt($pk->x, $pk->y, $pk->z);
                 Server::broadcastPacket($l->getUsingChunk($pk->x >> 4, $pk->z >> 4), $pk);
             }
         }
     }
 }
Esempio n. 27
0
 /**
  * @param Position $pos
  * @return int
  * 获取某坐标(位置)的亮度
  */
 public function getLight(Position $pos)
 {
     $chunk = $pos->getLevel()->getChunk($pos->x >> 4, $pos->z >> 4, false);
     $l = 0;
     if ($chunk instanceof FullChunk) {
         $l = $chunk->getBlockSkyLight($pos->x & 0xf, $pos->y & 0x7f, $pos->z & 0xf);
         if ($l < 15) {
             //$l = \max($chunk->getBlockLight($pos->x & 0x0f, $pos->y & 0x7f, $pos->z & 0x0f));
             $l = $chunk->getBlockLight($pos->x & 0xf, $pos->y & 0x7f, $pos->z & 0xf);
         }
     }
     return $l;
 }
Esempio n. 28
0
 public function onBreak(BlockBreakEvent $event)
 {
     if ($this->active == false and isset($this->players[$event->getPlayer()->getName()])) {
         $event->setCancelled();
     }
     if (isset($this->players[$event->getPlayer()->getName()])) {
         if ($event->getBlock()->getID() != $this->plugin->getConfig()->get("surface")) {
             $event->setCancelled();
         } else {
             if ($this->active == true) {
                 $block = $event->getBlock();
                 $event->setInstaBreak(true);
                 $block = new Position($block->getX(), $block->getY(), $block->getZ(), $block->getLevel());
                 $this->broken[] = $block;
             }
         }
     }
 }
Esempio n. 29
0
 /**
  * Handles player data saving
  */
 public function save($async = false)
 {
     if ($this->closed) {
         throw new \InvalidStateException("Tried to save closed player");
     }
     parent::saveNBT();
     if ($this->level instanceof Level) {
         $this->namedtag->Level = new String("Level", $this->level->getName());
         if ($this->spawnPosition instanceof Position and $this->spawnPosition->getLevel() instanceof Level) {
             $this->namedtag["SpawnLevel"] = $this->spawnPosition->getLevel()->getName();
             $this->namedtag["SpawnX"] = (int) $this->spawnPosition->x;
             $this->namedtag["SpawnY"] = (int) $this->spawnPosition->y;
             $this->namedtag["SpawnZ"] = (int) $this->spawnPosition->z;
         }
         foreach ($this->achievements as $achievement => $status) {
             $this->namedtag->Achievements[$achievement] = new Byte($achievement, $status === true ? 1 : 0);
         }
         $this->namedtag["playerGameType"] = $this->gamemode;
         $this->namedtag["lastPlayed"] = new Long("lastPlayed", floor(microtime(true) * 1000));
         if ($this->username != "" and $this->namedtag instanceof Compound) {
             $this->server->saveOfflinePlayerData($this->username, $this->namedtag, $async);
         }
     }
 }
Esempio n. 30
0
 public function destructSnowLayer(Position $pos)
 {
     $this->cooltime--;
     if ($pos == null) {
         return;
     }
     if ($pos->getLevel()->getBlockIdAt($pos->x, $pos->y, $pos->z) == Block::SNOW_LAYER) {
         $pos->getLevel()->setBlock($pos, Block::get(Block::AIR), 0, false);
     }
 }