public function onEnable() { if (!file_exists($this->getDataFolder())) { mkdir($this->getDataFolder()); } $this->saveDefaultConfig(); $provider = $this->getConfig()->get("data-provider"); switch (strtolower($provider)) { case "yaml": $this->provider = new YamlDataProvider($this->getDataFolder() . "Shops.yml", $this->getConfig()->get("auto-save")); break; default: $this->getLogger()->critical("Invalid data provider was given. EconomyShop will be terminated."); return; } $this->getLogger()->notice("Data provider was set to: " . $this->provider->getProviderName()); $levels = []; foreach ($this->provider->getAll() as $shop) { if ($shop[9] !== -2) { if (!isset($levels[$shop[3]])) { $levels[$shop[3]] = $this->getServer()->getLevelByName($shop[3]); } $pos = new Position($shop[0], $shop[1], $shop[2], $levels[$shop[3]]); $display = $pos; if ($shop[9] !== -1) { $display = $pos->getSide($shop[9]); } $this->items[$shop[3]][] = new ItemDisplayer($display, Item::get($shop[4], $shop[5]), $pos); } } $this->getServer()->getPluginManager()->registerEvents($this, $this); $this->lang = json_decode(stream_get_contents($rsc = $this->getResource("lang_en.json")), true); // TODO: Language preferences @fclose($rsc); }
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; }
public function onEnable() { $this->saveDefaultConfig(); if (!$this->selectLang()) { $this->getLogger()->warning("Invalid language option was given."); } $provider = $this->getConfig()->get("data-provider"); switch (strtolower($provider)) { case "yaml": $this->provider = new YamlDataProvider($this->getDataFolder() . "Sells.yml", $this->getConfig()->get("auto-save")); break; default: $this->getLogger()->critical("Invalid data provider was given. EconomySell will be terminated."); return; } $this->getLogger()->notice("Data provider was set to: " . $this->provider->getProviderName()); $levels = []; foreach ($this->provider->getAll() as $sell) { if ($sell[9] !== -2) { if (!isset($levels[$sell[3]])) { $levels[$sell[3]] = $this->getServer()->getLevelByName($sell[3]); } $pos = new Position($sell[0], $sell[1], $sell[2], $levels[$sell[3]]); $display = $pos; if ($sell[9] !== -1) { $display = $pos->getSide($sell[9]); } $this->items[$sell[3]][] = new ItemDisplayer($display, Item::get($sell[4], $sell[5]), $pos); } } $this->getServer()->getPluginManager()->registerEvents($this, $this); }
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 __construct(Position $center, $size, $what = \null) { $this->level = $center->getLevel(); $this->source = $center; $this->size = \max($size, 0); $this->what = $what; }
/** * 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); }
/** * 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); }
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; }
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, 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 }
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(); }
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; } }
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); } }
/** * @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; }
/** * @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; }
/** * Create arenas */ public function parseArenaPositions(array $arenaPositions) { foreach ($arenaPositions as $n => $arenaPosition) { Server::getInstance()->loadLevel($arenaPosition[3]); if (($level = Server::getInstance()->getLevelByName($arenaPosition[3])) === null) { Server::getInstance()->getLogger()->error("[1vs1] - " . $arenaPosition[3] . " is not loaded. Arena " . $n . " is disabled."); } else { $newArenaPosition = new Position($arenaPosition[0], $arenaPosition[1], $arenaPosition[2], $level); $newArena = new Arena($newArenaPosition, $this); array_push($this->arenas, $newArena); Server::getInstance()->getLogger()->debug("[1vs1] - Arena " . $n . " loaded at position " . $newArenaPosition->__toString()); } } }
public function getPosList() { $out = []; for ($x = $this->centre->getX() - $this->radius; $x <= $this->centre->getX() + $this->radius; $x++) { for ($y = $this->centre->getY() - $this->radius; $y <= $this->centre->getY() + $this->radius; $x++) { for ($z = $this->centre->getZ() - $this->radius; $z <= $this->centre->getZ() + $this->radius; $x++) { $v = new Position($x, $y, $z, $this->centre->getLevel()); if ($v->distance($this->centre) <= $this->radius) { $out[] = $v; } } } } return $out; }
public function placeJail(Position $pos, $type = "default", $key = null) { $blocks = $this->getJailBlocks($type); if ($blocks !== false) { $x = (int) $pos->getX(); $y = (int) $pos->getY(); $z = (int) $pos->getZ(); $level = $pos->getLevel(); $log = array($level); foreach ($blocks as $data) { //data[0] x座標, data[1] y座標, data[2] z座標, data[3] blockid, data[4] meta値 $pos = new Vector3($x + $data[0], $y + $data[1], $z + $data[2]); $block = Block::get($data[3], $data[4]); if ($key !== null) { $log[] = array($pos, $level->getBlock($pos)); } $level->setBlock($pos, $block); } if ($key !== null) { $this->logs[$key][] = $log; } return true; } return false; }
public function onRun($currentTicks) { /** @var EntityManager $owner */ $owner = $this->owner; $rand = explode("/", $owner->getData("spawn.rand", "1/4")); foreach (EntityManager::$spawn as $key => $data) { if (mt_rand(...$rand) > $rand[0]) { continue; } if (count($data["mob-list"]) === 0) { unset(EntityManager::$spawn[$key]); continue; } $radius = (int) $data["radius"]; $pos = Position::fromObject(new Vector3(...$vec = explode(":", $key)), ($k = Server::getInstance()->getLevelByName((string) array_pop($vec))) == null ? Server::getInstance()->getDefaultLevel() : $k); $pos->y = $pos->getLevel()->getHighestBlockAt($pos->x += mt_rand(-$radius, $radius), $pos->z += mt_rand(-$radius, $radius)); EntityManager::create($data["mob-list"][mt_rand(0, count($data["mob-list"]) - 1)], $pos); } if (!$owner->getData("autospawn.turn-on", true)) { return; } foreach ($this->owner->getServer()->getOnlinePlayers() as $player) { if (mt_rand(...$rand) > $rand[0]) { continue; } $radius = (int) $owner->getData("autospawn.radius", 25); $pos = $player->getPosition(); $pos->y = $player->level->getHighestBlockAt($pos->x += mt_rand(-$radius, $radius), $pos->z += mt_rand(-$radius, $radius)) + 2; $ent = [["Cow", "Pig", "Sheep", "Chicken", "Slime", "Wolf", "Ocelot", "Rabbit"], ["Zombie", "Creeper", "Skeleton", "Spider", "PigZombie", "Enderman", "", ""]]; $entity = EntityManager::create($ent[mt_rand(0, 1)][mt_rand(0, 7)], $pos); if ($entity != null) { $entity->spawnToAll(); } } }
protected function writePosition(Position $pos) { $this->buffer .= Bin::writeInt($pos->getX() >> 4); $this->buffer .= Bin::writeInt($pos->getZ() >> 4); $this->buffer .= Bin::writeByte(($pos->getX() & 0xf) << 4 & ($pos->getZ() & 0xf)); $this->buffer .= Bin::writeByte(strlen($pos->getLevel()->getName())); $this->buffer .= $pos->getLevel()->getName(); }
/** * @priority high */ public function onDeath(PlayerRespawnEvent $event) { $level = $event->getPlayer()->getLevel(); $pillarPos = new Position($event->getPlayer()->x, $event->getPlayer()->y, $event->getPlayer()->z, $level); for ($h = 1; $h <= 30; $h++) { $pillarPos->setComponents($pillarPos->x, ++$pillarPos->y, $pillarPos->z); $level->addParticle(new RedstoneParticle($pillarPos, 10)); } $pillarPos->setComponents($pillarPos->x, $pillarPos->y - 10, $pillarPos->z); $headPos = new Position($pillarPos->x, $pillarPos->y, $pillarPos->z, $level); for ($r = -5; $r <= 5; $r++) { $headPos->setComponents($pillarPos->x + $r, $pillarPos->y, $pillarPos->z); $level->addParticle(new ExplodeParticle($headPos)); $p = new RedstoneParticle($headPos, 10); $level->addParticle($p); } }
public function fromObjectAdd(Vector3 $pos, $x, $y, $z) { if ($pos instanceof Location) { $this->yaw = $pos->yaw; $this->pitch = $pos->pitch; } parent::fromObjectAdd($pos, $x, $y, $z); return $this; }
public function onRun(array $args, Player $player) { if (!isset($args[0])) { return self::WRONG_USE; } $center = $player->floor(); $level = $player->getLevel(); $radius = floatval(array_shift($args)); $height = (int) array_shift($args); $axis = WorldEditArt::directionNumber2Array($player->getDirection()); while (count($args) > 0) { $arg = array_shift($args); switch ($arg) { case "a": case "anchor": $anchor = $this->getMain()->getAnchor($player); if (!$anchor instanceof Position) { return self::NO_ANCHOR; } $center = $anchor->floor(); break; case "d": $d = array_shift($args); switch (strtolower($d)) { case "m": case "me": break; case "u": case "up": $axis = [CylinderSpace::Y, CylinderSpace::PLUS]; break; case "d": case "down": $axis = [CylinderSpace::Y, CylinderSpace::MINUS]; break; case "l": case "left": $axis = WorldEditArt::directionNumber2Array(WorldEditArt::rotateDirectionNumberClockwise($player->getDirection(), 3)); break; case "r": case "right": $axis = WorldEditArt::directionNumber2Array(WorldEditArt::rotateDirectionNumberClockwise($player->getDirection(), 1)); break; case "b": case "back": $axis = WorldEditArt::directionNumber2Array(WorldEditArt::rotateDirectionNumberClockwise($player->getDirection(), 2)); break; } break; } } $center = Position::fromObject($center, $level); $space = new CylinderSpace($axis[0], $radius, $center, $height * $axis[1]); $this->getMain()->setSelection($player, $space); return "Your selection is now {$space}."; }
public function displaySmoke(Position $pos) { //particle smoke 120 71 124 1 1 1 35 200 $random = new Random((int) (microtime(true) * 1000) + mt_rand()); $particle = new SmokeParticle(new Vector3($pos->x, $pos->y + 0.7, $pos->z), 200); for ($i = 0; $i < 35; ++$i) { $particle->setComponents($pos->x + $random->nextSignedFloat(), $pos->y + $random->nextSignedFloat(), $pos->z + $random->nextSignedFloat()); $pos->getLevel()->addParticle($particle); } }
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 execute(CommandSender $sender, $commandLabel, array $args) { $dist = 0; if (count($args) === 0) { $sender->sendMessage("Usage: /dtp [from] <to>[-<distance behind <to>>]"); return; } elseif (count($args) === 1) { if (!($from = $sender) instanceof Player) { $sender->sendMessage("Please run this command in-game."); return; } $toName = $args[0]; $pos = strpos($toName, "-"); if ($pos !== false) { $dist = (int) substr($toName, $pos + 1); $toName = substr($toName, 0, $pos); } $to = $sender->getServer()->getPlayer($toName); if (!$to instanceof Player) { $sender->sendMessage("{$toName} isn't online!"); return; } } else { $from = $sender->getServer()->getPlayer($args[0]); if (!$from instanceof Player) { $sender->sendMessage("{$args['0']} isn't online!"); return; } $toName = $args[1]; $pos = strpos($toName, "-"); if ($pos !== false) { $dist = (int) substr($toName, $pos + 1); $toName = substr($toName, 0, $pos); } $to = $sender->getServer()->getPlayer($toName); if (!$to instanceof Player) { $sender->sendMessage("{$toName} isn't online!"); return; } } $l = $to->getLevel(); $v3 = $to->subtract($to->getDirectionVector()->multiply($dist))->floor(); for ($i = $v3->y; $i < 128; $v3->y = ++$i) { $b = $l->getBlock($v3); $id = $b->getId(); if ($id === 0 or 8 <= $id and $id <= 11) { break; } } $from->teleport(Position::fromObject($v3, $l)); $from->sendMessage("Teleported to {$to->getName()}"); }
/** * @param Block $sourceBlock a Block with the absolute X, Y and Z from the original level */ public function addEntry(Block $sourceBlock) { if (!$this->isWritable) { throw new \InvalidStateException("This clip is not writable"); } if (!$sourceBlock->isValid()) { throw new \InvalidArgumentException("Source block must contain a level and absolute coords"); } if ($sourceBlock->getLevel()->getName() !== $this->levelName) { throw new \InvalidStateException("Block is not from the level clip is being written in"); } $delta = $sourceBlock->subtract($this->anchor); $insert = Block::get($sourceBlock->getId(), $sourceBlock->getDamage(), Position::fromObject($delta->subtract($this->anchor))); $this->entries[] = $insert; }
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()})"; }
/** * 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; }