public function addShop(Location $loc, $col) { $hash = Level::chunkHash($loc->getFloorX() >> 4, $loc->getFloorZ() >> 4); if (!isset($this->shopLocs[$hash])) { $this->shopLocs[$hash] = []; } $this->shopLocs[$hash][$col] = $loc; }
public function build() { $materialMaxKey = count($this->floorMaterials) - 1; $level = $this->playerPrepLoc->getLevel(); // $level->getServer()->getLogger()->debug("Start rebuilding of spleef $this->name"); for ($floor = 0; $floor < $this->floors; $floor++) { $y = $this->lowestY + $floor * $this->floorHeight; for ($x = $this->fromx; $x <= $this->tox; $x++) { for ($z = $this->fromz; $z <= $this->toz; $z++) { $level->setBlock(new Vector3($x, $y, $z), $this->floorMaterials[mt_rand(0, $materialMaxKey)], false, false); } } } // $level->getServer()->getLogger()->debug("Finished rebuilding of spleef $this->name"); }
public function __construct(Location $loc, $name, $skin, $skinName, Item $item, $message = "") { parent::__construct($loc->x, $loc->y, $loc->z, $loc->yaw, $loc->pitch, $loc->level); $this->eid = Entity::$entityCount++; $this->skin = $skin; $this->skinName = $skinName; $this->name = $name; $this->item = $item; $this->message = $message; $this->uuid = UUID::fromRandom(); }
public function __construct(Main $plugin, Location $loc, $name, $skin, $skinId, Item $item, $message = "", $command = null) { parent::__construct($loc->x, $loc->y, $loc->z, $loc->yaw, $loc->pitch, $loc->level); $this->plugin = $plugin; $this->eid = Entity::$entityCount++; $this->skin = $skin; $this->skinId = $skinId; $this->name = $name; $this->item = $item; $this->message = $message; $this->command = $command; $this->uuid = UUID::fromRandom(); }
/** * @param number $slowness * @return Location|null */ public function tick($slowness) { if (($length = $this->length * $slowness) < 1.0E-7) { return null; } if (($progress = $this->current++ / $length) > 1) { return null; } return new Location($this->getOrigin()->getX() + $this->distance->getX() * $progress, 1.62 + $this->getOrigin()->getY() + $this->distance->getY() * $progress, $this->getOrigin()->getZ() + $this->distance->getZ() * $progress, $this->getOrigin()->getYaw() + $this->distance->getYaw() * $progress, $this->getOrigin()->getPitch() + $this->distance->getPitch() * $progress); }
/** * @param CommandSender $sender * @param string $alias * @param array $args * @return bool */ public function execute(CommandSender $sender, $alias, array $args) { if (!$this->testPermission($sender)) { return false; } if (!isset($args[0]) && !$sender instanceof Player || count($args) > 1) { $this->sendUsage($sender, $alias); return false; } $player = $sender; if (isset($args[0])) { if (!$sender->hasPermission("essentials.spawn.other")) { $sender->sendMessage(TextFormat::RED . "[Error] You can't teleport other players to spawn"); return false; } elseif (!($player = $this->getAPI()->getPlayer($args[0]))) { $sender->sendMessage(TextFormat::RED . "[Error] Player not found"); return false; } } $player->teleport(Location::fromObject($this->getAPI()->getServer()->getDefaultLevel()->getSpawnLocation(), $this->getAPI()->getServer()->getDefaultLevel())); $player->sendMessage(TextFormat::GREEN . "Teleporting..."); return true; }
protected function processMovement($tickDiff) { if (!$this->isAlive() or !$this->spawned or $this->newPosition === null or $this->teleportPosition !== null) { return; } $newPos = $this->newPosition; $distanceSquared = $newPos->distanceSquared($this); $revert = false; if ($distanceSquared / $tickDiff ** 2 > 100) { $revert = true; } else { if ($this->chunk === null or !$this->chunk->isGenerated()) { $chunk = $this->level->getChunk($newPos->x >> 4, $newPos->z >> 4, false); if ($chunk === null or !$chunk->isGenerated()) { $revert = true; $this->nextChunkOrderRun = 0; } else { if ($this->chunk !== null) { $this->chunk->removeEntity($this); } $this->chunk = $chunk; } } } if (!$revert and $distanceSquared != 0) { $dx = $newPos->x - $this->x; $dy = $newPos->y - $this->y; $dz = $newPos->z - $this->z; $this->move($dx, $dy, $dz); $diffX = $this->x - $newPos->x; $diffY = $this->y - $newPos->y; $diffZ = $this->z - $newPos->z; $yS = 0.5 + $this->ySize; if ($diffY >= -$yS or $diffY <= $yS) { $diffY = 0; } $diff = ($diffX ** 2 + $diffY ** 2 + $diffZ ** 2) / $tickDiff ** 2; if ($this->isSurvival()) { if (!$revert and !$this->isSleeping()) { if ($diff > 0.0625) { $revert = true; $this->server->getLogger()->warning($this->getServer()->getLanguage()->translateString("pocketmine.player.invalidMove", [$this->getName()])); } } } if ($diff > 0) { $this->x = $newPos->x; $this->y = $newPos->y; $this->z = $newPos->z; $radius = $this->width / 2; $this->boundingBox->setBounds($this->x - $radius, $this->y, $this->z - $radius, $this->x + $radius, $this->y + $this->height, $this->z + $radius); } } $from = new Location($this->lastX, $this->lastY, $this->lastZ, $this->lastYaw, $this->lastPitch, $this->level); $to = $this->getLocation(); $delta = pow($this->lastX - $to->x, 2) + pow($this->lastY - $to->y, 2) + pow($this->lastZ - $to->z, 2); $deltaAngle = abs($this->lastYaw - $to->yaw) + abs($this->lastPitch - $to->pitch); if (!$revert and ($delta > 1 / 16 or $deltaAngle > 10)) { $isFirst = ($this->lastX === null or $this->lastY === null or $this->lastZ === null); $this->lastX = $to->x; $this->lastY = $to->y; $this->lastZ = $to->z; $this->lastYaw = $to->yaw; $this->lastPitch = $to->pitch; if (!$isFirst) { $ev = new PlayerMoveEvent($this, $from, $to); $this->server->getPluginManager()->callEvent($ev); if (!($revert = $ev->isCancelled())) { //Yes, this is intended if ($to->distanceSquared($ev->getTo()) > 0.01) { //If plugins modify the destination $this->teleport($ev->getTo()); } else { $this->level->addEntityMovement($this->x >> 4, $this->z >> 4, $this->getId(), $this->x, $this->y + $this->getEyeHeight(), $this->z, $this->yaw, $this->pitch, $this->yaw); } } } if (!$this->isSpectator()) { $this->checkNearEntities($tickDiff); } $this->speed = $from->subtract($to); } elseif ($distanceSquared == 0) { $this->speed = new Vector3(0, 0, 0); } if ($revert) { $this->lastX = $from->x; $this->lastY = $from->y; $this->lastZ = $from->z; $this->lastYaw = $from->yaw; $this->lastPitch = $from->pitch; $this->sendPosition($from, $from->yaw, $from->pitch, 1); $this->forceMovement = new Vector3($from->x, $from->y, $from->z); } else { $this->forceMovement = null; if ($distanceSquared != 0 and $this->nextChunkOrderRun > 20) { $this->nextChunkOrderRun = 20; } } $this->newPosition = null; }
protected function processMovement($tickDiff) { if (!$this->isAlive() or !$this->spawned or $this->newPosition === null or $this->teleportPosition !== null) { return; $this->setMoving(false); } $newPos = $this->newPosition; $distanceSquared = $newPos->distanceSquared($this); $revert = false; if ($distanceSquared / $tickDiff ** 2 > 200) { $revert = true; } else { if ($this->chunk === null or !$this->chunk->isGenerated()) { $chunk = $this->level->getChunk($newPos->x >> 4, $newPos->z >> 4, false); if ($chunk === null or !$chunk->isGenerated()) { $revert = true; $this->nextChunkOrderRun = 0; } else { if ($this->chunk !== null) { $this->chunk->removeEntity($this); } $this->chunk = $chunk; } } } if (!$revert and $distanceSquared != 0) { $dx = $newPos->x - $this->x; $dy = $newPos->y - $this->y; $dz = $newPos->z - $this->z; $this->move($dx, $dy, $dz); $diffX = $this->x - $newPos->x; $diffY = $this->y - $newPos->y; $diffZ = $this->z - $newPos->z; $yS = 0.5 + $this->ySize; if ($diffY >= -$yS or $diffY <= $yS) { $diffY = 0; } $diff = ($diffX ** 2 + $diffY ** 2 + $diffZ ** 2) / $tickDiff ** 2; /*if($this->isSurvival()){ if(!$revert and !$this->isSleeping()){ if($diff > 0.0625){ $revert = true; $this->server->getLogger()->warning($this->getServer()->getLanguage()->translateString("pocketmine.player.invalidMove", [$this->getName()])); } } } if($diff > 0){ $this->x = $newPos->x; $this->y = $newPos->y; $this->z = $newPos->z; $radius = $this->width / 2; $this->boundingBox->setBounds($this->x - $radius, $this->y, $this->z - $radius, $this->x + $radius, $this->y + $this->height, $this->z + $radius); }*/ } $from = new Location($this->lastX, $this->lastY, $this->lastZ, $this->lastYaw, $this->lastPitch, $this->level); $to = $this->getLocation(); $delta = pow($this->lastX - $to->x, 2) + pow($this->lastY - $to->y, 2) + pow($this->lastZ - $to->z, 2); $deltaAngle = abs($this->lastYaw - $to->yaw) + abs($this->lastPitch - $to->pitch); if (!$revert and ($delta > 1 / 16 or $deltaAngle > 10)) { $isFirst = ($this->lastX === null or $this->lastY === null or $this->lastZ === null); $this->lastX = $to->x; $this->lastY = $to->y; $this->lastZ = $to->z; $this->lastYaw = $to->yaw; $this->lastPitch = $to->pitch; if (!$isFirst) { $ev = new PlayerMoveEvent($this, $from, $to); $this->setMoving(true); $this->server->getPluginManager()->callEvent($ev); if (!($revert = $ev->isCancelled())) { //Yes, this is intended //$teleported = false; if ($this->server->netherEnabled) { if ($this->isInsideOfPortal()) { if ($this->portalTime == 0) { $this->portalTime = $this->server->getTick(); } } else { $this->portalTime = 0; } } //if($this->server->redstoneEnabled) $this->getLevel()->updateAround($ev->getTo()->round()); // if(!$teleported){ if ($to->distanceSquared($ev->getTo()) > 0.2) { //If plugins modify the destination $this->teleport($ev->getTo()); } else { $this->level->addEntityMovement($this->x >> 4, $this->z >> 4, $this->getId(), $this->x, $this->y + $this->getEyeHeight(), $this->z, $this->yaw, $this->pitch, $this->yaw); } if ($this->fishingHook instanceof FishingHook) { if ($this->distance($this->fishingHook) > 20 or $this->inventory->getItemInHand()->getId() !== Item::FISHING_ROD) { $this->fishingHook->close(); $this->fishingHook = null; } } // } /*if($this->server->expEnabled){ /** @var \pocketmine\entity\ExperienceOrb $e * foreach($this->level->getNearbyExperienceOrb(new AxisAlignedBB($this->x - 1, $this->y - 1, $this->z - 1, $this->x + 1, $this->y + 2, $this->z + 1)) as $e){ if($e->getExperience() > 0){ $e->close(); $this->addExperience($e->getExperience()); } } }*/ } } if (!$this->isSpectator()) { $this->checkNearEntities($tickDiff); } $this->speed = $from->subtract($to); } elseif ($distanceSquared == 0) { $this->speed = new Vector3(0, 0, 0); $this->setMoving(false); } if ($revert) { $this->lastX = $from->x; $this->lastY = $from->y; $this->lastZ = $from->z; $this->lastYaw = $from->yaw; $this->lastPitch = $from->pitch; $this->sendPosition($from, $from->yaw, $from->pitch, 1); $this->forceMovement = new Vector3($from->x, $from->y, $from->z); } else { $this->forceMovement = null; if ($distanceSquared != 0 and $this->nextChunkOrderRun > 20) { $this->nextChunkOrderRun = 20; } } $this->newPosition = null; }
protected function processMovement($currentTick) { if ($this->dead or !$this->spawned or !$this->newPosition instanceof Vector3) { $diff = $currentTick - $this->lastSpeedTick; if ($diff >= 10) { $this->speed = new Vector3(0, 0, 0); } elseif ($diff > 5 and $this->speedTicks < 20) { ++$this->speedTicks; } return; } $distanceSquared = $this->newPosition->distanceSquared($this); $revert = false; if ($distanceSquared > 100) { $revert = true; } else { if ($this->chunk === null or !$this->chunk->isGenerated()) { $chunk = $this->level->getChunk($this->newPosition->x >> 4, $this->newPosition->z >> 4); if (!$chunk instanceof FullChunk or !$chunk->isGenerated()) { $revert = true; $this->nextChunkOrderRun = 0; } else { if ($this->chunk instanceof FullChunk) { $this->chunk->removeEntity($this); } $this->chunk = $chunk; } } } if (!$revert and $distanceSquared != 0) { $dx = $this->newPosition->x - $this->x; $dy = $this->newPosition->y - $this->y; $dz = $this->newPosition->z - $this->z; $this->fastMove($dx, $dy, $dz); $diffX = $this->x - $this->newPosition->x; $diffY = $this->y - $this->newPosition->y; $diffZ = $this->z - $this->newPosition->z; $yS = 0.5 + $this->ySize; if ($diffY > -0.5 or $diffY < 0.5) { $diffY = 0; } $diff = $diffX ** 2 + $diffY ** 2 + $diffZ ** 2; if ($this->isSurvival()) { if (!$revert and !$this->isSleeping()) { if ($diff > 0.0625 and $this->checkMovement) { $revert = true; $this->server->getLogger()->warning($this->getName() . " moved wrongly!"); } elseif ($diff > 0 or !$this->checkMovement) { $this->x = $this->newPosition->x; $this->y = $this->newPosition->y; $this->z = $this->newPosition->z; $radius = $this->width / 2; $this->boundingBox->setBounds($this->x - $radius, $this->y, $this->z - $radius, $this->x + $radius, $this->y + $this->height, $this->z + $radius); } } } elseif ($diff > 0) { $this->x = $this->newPosition->x; $this->y = $this->newPosition->y; $this->z = $this->newPosition->z; $radius = $this->width / 2; $this->boundingBox->setBounds($this->x - $radius, $this->y + $this->ySize, $this->z - $radius, $this->x + $radius, $this->y + $this->height + $this->ySize, $this->z + $radius); } } $from = new Location($this->lastX, $this->lastY, $this->lastZ, $this->lastYaw, $this->lastPitch, $this->level); $to = $this->getLocation(); $delta = pow($this->lastX - $to->x, 2) + pow($this->lastY - $to->y, 2) + pow($this->lastZ - $to->z, 2); $deltaAngle = abs($this->lastYaw - $to->yaw) + abs($this->lastPitch - $to->pitch); if (!$revert and ($delta > 1 / 16 or $deltaAngle > 10)) { $isFirst = ($this->lastX === null or $this->lastY === null or $this->lastZ === null); $this->lastX = $to->x; $this->lastY = $to->y; $this->lastZ = $to->z; $this->lastYaw = $to->yaw; $this->lastPitch = $to->pitch; if (!$isFirst) { $ev = new PlayerMoveEvent($this, $from, $to); $this->server->getPluginManager()->callEvent($ev); if (!($revert = $ev->isCancelled())) { //Yes, this is intended if ($to->distanceSquared($ev->getTo()) > 0.01) { //If plugins modify the destination $this->teleport($ev->getTo()); } else { foreach ($this->hasSpawned as $player) { $player->addEntityMovement($this->id, $this->x, $this->y + $this->getEyeHeight(), $this->z, $this->yaw, $this->pitch, $this->yaw); } } } } $ticks = min(20, $currentTick - $this->lastSpeedTick + 0.5); if ($this->speedTicks > 0) { $ticks += $this->speedTicks; } $this->speed = $from->subtract($to)->divide($ticks); $this->lastSpeedTick = $currentTick; } elseif ($distanceSquared == 0) { $this->speed = new Vector3(0, 0, 0); $this->lastSpeedTick = $currentTick; } if ($this->speedTicks > 0) { --$this->speedTicks; } if ($revert) { $this->lastX = $from->x; $this->lastY = $from->y; $this->lastZ = $from->z; $this->lastYaw = $from->yaw; $this->lastPitch = $from->pitch; $pk = new MoveEntityPacket(); $pk->eid = 0; $pk->x = $from->x; $pk->y = $from->y + $this->getEyeHeight(); $pk->z = $from->z; $pk->bodyYaw = $from->yaw; $pk->pitch = $from->pitch; $pk->yaw = $from->yaw; $pk->teleport = true; $this->directDataPacket($pk); $this->forceMovement = new Vector3($from->x, $from->y, $from->z); } else { $this->forceMovement = null; if ($distanceSquared != 0 and $this->nextChunkOrderRun > 20) { $this->nextChunkOrderRun = 20; } } $this->newPosition = null; }
public function onCommand(CommandSender $sender, Command $cmd, $label, array $args) { if ($cmd->getName() != "mobster") { return false; } if (isset($args[0]) && strtolower($args[0]) == "spawn") { array_shift($args); } if (!$sender->hasPermission("mobsters.cmd.spawn")) { $sender->sendMessage("You are not allowed to do that!"); return true; } if (count($args) != 2) { return false; } $mob = strtolower(array_shift($args)); if (($class = $this->mobClass($mob)) === null) { $sender->sendMessage("Unknown mob class: {$mob}"); return true; } $location = explode(":", array_shift($args), 2); if (count($location) < 2) { if ($sender instanceof Player) { $level = $sender->getLevel(); } else { $level = $this->getServer()->getDefaultLevel(); } } else { $level = $this->getServer()->getLevelByName($location[1]); if ($level === null) { $sender->sendMessage("Unknown level: " . $location[1]); return true; } } $location = array_map("floatval", explode(",", $location[0], 5)); if (count($location) < 3) { $sender->sendMessage("Invalid location specified"); return false; } $location = new Location(...$location); $location->setLevel($level); $this->spawnMob($class, $location); $sender->sendMessage("Spawned {$mob}"); return true; }
/** * Create a warp or override its position * * @param string $warp * @param Position $pos * @param int $yaw * @param int $pitch * @return bool */ public function setWarp($warp, Position $pos, $yaw = 0, $pitch = 0) { if (!$this->validateName($warp, false)) { return false; } $this->warps[$warp] = $pos instanceof BaseLocation ? $pos : BaseLocation::fromPosition($warp, $pos instanceof Location ? $pos : Location::fromObject($pos, $pos->getLevel(), $yaw, $pitch)); return true; }
public static function fromPosition($name, Location $pos) { return new BaseLocation($name, $pos->getX(), $pos->getY(), $pos->getZ(), $pos->getLevel(), $pos->getYaw(), $pos->getPitch()); }
/** * @param string $name * @param int $x * @param int $y * @param int $z * @param Level $level * @param float $yaw * @param float $pitch */ public function __construct($name, $x, $y, $z, Level $level, $yaw, $pitch) { parent::__construct($x, $y, $z, $yaw, $pitch, $level); $this->name = $name; }
public function createTouchEffect(Location $position, $entityHeight, Location $damagerPosition, $damagerHeight) { if (isset($this->config["NU_EFFECT"]) && !$this->config["NU_EFFECT"]) { $position->getLevel()->addSound(new DoorSound($position)); for ($i = 0; $i < 50; $i++) { $position->getLevel()->addParticle(new HeartParticle($position->add(mt_rand(-1, 1), mt_rand(-1, 1) + $entityHeight, mt_rand(-1, 1)))); } for ($i = 0; $i < 50; $i++) { $damagerPosition->getLevel()->addParticle(new HeartParticle($damagerPosition->add(mt_rand(-1, 1), mt_rand(-1, 1) + $damagerHeight, mt_rand(-1, 1)))); } } else { $position->getLevel()->addSound(new DoorSound($position)); for ($i = 0; $i < 50; $i++) { $position->getLevel()->addParticle(new DustParticle($position->add(mt_rand(-1, 1) / 2, mt_rand(-1, 1) / 2 + $entityHeight, mt_rand(-1, 1) / 2), 153, 51, 255)); } for ($i = 0; $i < 50; $i++) { $damagerPosition->getLevel()->addParticle(new DustParticle($damagerPosition->add(mt_rand(-1, 1) / 2, mt_rand(-1, 1) / 2 + $damagerHeight, mt_rand(-1, 1) / 2), 153, 51, 255)); } } }
/** * @param $home * @param Location $pos * @return bool */ public function setHome($home, Location $pos) { if (!$this->getPlugin()->validateName($home, false)) { return false; } $this->homes[$home] = new BaseLocation($home, $pos->getX(), $pos->getY(), $pos->getZ(), $pos->getLevel(), $pos->getYaw(), $pos->getPitch()); return true; }