/** * 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); }
/** * 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); }
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(); } } }
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 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 __construct($axis, $radius, Position $base, $height) { $this->base = Position::fromObject($base->floor(), $base->getLevel()); $this->height = $height; $this->radius = $radius; $this->axis = $axis % 3; if ($this->axis === self::Y) { $y = [$this->base->getY(), $this->base->getY() + $height]; $maxY = max($y); $minY = min($y); } else { $y = [$this->base->getY() + $radius, $this->base->getY() - $radius]; $maxY = max($y); $minY = min($y); } $maxHeight = 127; if (defined($path = "pemapmodder\\worldeditart\\MAX_WORLD_HEIGHT")) { $maxHeight = constant($path); } if ($maxY > $maxHeight or $minY < 0) { throw new SelectionExceedWorldException("CylinderSpace"); } parent::__construct(); }
/** * @param Vector3|Position|Location $pos * @param float $yaw * @param float $pitch * * @return bool */ public function teleport(Vector3 $pos, $yaw = \null, $pitch = \null) { if ($pos instanceof Location) { $yaw = $yaw === \null ? $pos->yaw : $yaw; $pitch = $pitch === \null ? $pos->pitch : $pitch; } $from = Position::fromObject($this, $this->level); $to = Position::fromObject($pos, $pos instanceof Position ? $pos->getLevel() : $this->level); $this->server->getPluginManager()->callEvent($ev = new EntityTeleportEvent($this, $from, $to)); if ($ev->isCancelled()) { return \false; } $this->ySize = 0; $pos = $ev->getTo(); $this->setMotion(new Vector3(0, 0, 0)); if ($this->setPositionAndRotation($pos, $yaw === \null ? $this->yaw : $yaw, $pitch === \null ? $this->pitch : $pitch, \true) !== \false) { $this->resetFallDistance(); $this->onGround = \true; $this->lastX = $this->x; $this->lastY = $this->y; $this->lastZ = $this->z; $this->lastYaw = $this->yaw; $this->lastPitch = $this->pitch; foreach ($this->hasSpawned as $player) { $player->addEntityMovement($this->getId(), $this->x, $this->y + $this->getEyeHeight(), $this->z, $this->yaw, $this->pitch, $this->yaw); } return \true; } return \false; }
/** * Returns a side Vector * * @param int $side * @param int $step * * @return Position * * @throws LevelException */ public function getSide($side, $step = 1) { assert($this->isValid()); return Position::fromObject(parent::getSide($side, $step), $this->level); }
public function onUpdate($type) { return false; $newId = $this->id; $level = $this->meta & 0x7; if ($type !== Level::BLOCK_UPDATE_NORMAL) { return false; } $this->checkLava(); $falling = $this->meta >> 3; $down = $this->getSide(0); $from = $this->getFrom(); //Has Source or Its Source if ($from !== null || $level == 0x0) { if ($level !== 0x7) { if ($down instanceof Air || $down instanceof Water) { $this->getLevel()->setBlock($down, new Water(0x1), false, false, true); //Server::getInstance()->api->block->scheduleBlockUpdate(Position::fromObject($down, $this->level), 10, Level::BLOCK_UPDATE_NORMAL); } else { for ($side = 2; $side <= 5; ++$side) { $b = $this->getSide($side); if ($b instanceof Water) { if ($this->getSourceCount() >= 2 && $level != 0x0) { $this->getLevel()->setBlock($this, new Water(0), false, false, true); } } elseif ($b->isFlowable === true) { $this->getLevel()->setBlock($b, new Water($level + 1), false, false, true); //Server::getInstance()->api->block->scheduleBlockUpdate(Position::fromObject($b, $this->level), 10, Level::BLOCK_UPDATE_NORMAL); } } } } } else { //Extend Remove for Left Waters for ($side = 2; $side <= 5; ++$side) { $sb = $this->getSide($side); if ($sb instanceof Water) { $tlevel = $sb->meta & 0x7; if ($tlevel != 0x0) { for ($s = 0; $s <= 5; $s++) { $ssb = $sb->getSide($s); Server::getInstance()->api->block->scheduleBlockUpdate(Position::fromObject($ssb, $this->level), 10, Level::BLOCK_UPDATE_NORMAL); } $this->getLevel()->setBlock($sb, new Air(), false, false, true); } } $b = $this->getSide(0)->getSide($side); if ($b instanceof Water) { $tlevel = $b->meta & 0x7; if ($tlevel != 0x0) { for ($s = 0; $s <= 5; $s++) { $ssb = $sb->getSide($s); Server::getInstance()->api->block->scheduleBlockUpdate(Position::fromObject($ssb, $this->level), 10, Level::BLOCK_UPDATE_NORMAL); } $this->getLevel()->setBlock($b, new Air(), false, false, true); } } //Server::getInstance()->api->block->scheduleBlockUpdate(Position::fromObject($b, $this->level), 10, Level::BLOCK_UPDATE_NORMAL); } $this->getLevel()->setBlock($this, new Air(), false, false, true); } return false; }
/** * Returns a Position pointing to the spawn * * @return Position */ public function getSpawnLocation() { return Position::fromObject($this->provider->getSpawn(), $this); }
public function onRun(array $args, Player $player) { $flag = 0; // 0 for me, 1 for anchor, 2 for crosshair if (isset($args[0])) { $arg = array_shift($args); switch ($arg) { case "a": case "anchor": $flag = 1; break; case "c": case "crosshair": $flag = 2; break; } } $selected = $player->getPosition(); if ($flag === 1) { $selected = $this->getMain()->getAnchor($player); if (!$selected instanceof Position) { return self::NO_ANCHOR; } } if ($flag === 2) { $selected = WorldEditArt::getCrosshairTarget($player); if (!$selected instanceof Position) { return "The block is too far/in the void/in the sky."; } } if ($selected->y < 0 or $selected->y > (defined($path = "pemapmodder\\worldeditart\\MAX_WORLD_HEIGHT") ? constant($path) : 127)) { return "The selected point is too high/too low."; } $selected->getLevel()->loadChunk($selected->x >> 4, $selected->z >> 4); $selected = Position::fromObject($selected->floor(), $selected->getLevel()); $space = $this->getMain()->getSelection($player); if ($space instanceof CuboidSpace and $space->getLevel() === $selected->getLevel()) { if ($this->is2) { $space->set1($selected); } else { $space->set0($selected); } goto end; } $temp = $this->getMain()->getTempPos($player); if (is_array($temp) and $temp["#"] !== $this->is2) { /** @var Position $pos */ $pos = $temp["position"]; if ($pos->getLevel() === $selected->getLevel()) { if ($this->is2) { $this->getMain()->setSelection($player, new CuboidSpace($pos, $selected)); } else { $this->getMain()->setSelection($player, new CuboidSpace($selected, $pos)); } goto end; } } $this->getMain()->unsetSelection($player); $this->getMain()->setTempPos($player, $selected, $this->is2); end: $space = $this->getMain()->getSelection($player); if ($space instanceof Space) { $cnt = count($space); } return ($this->is2 ? "Second" : "First") . " position set to " . "({$selected->x}, {$selected->y}, {$selected->z})." . (isset($cnt) ? "\n (Cuboid selected with {$cnt} blocks)" : ""); }
/** * Adds a player to an arena * @param Player $player */ public function spawnPlayerToArena(Player $player) { if ($this->getPlayerArena($player) == null) { foreach ($this->arenas as $arena) { if (!$arena->inUse) { if (count($arena->players) != $arena->capacity && count($arena->spawnpoints) >= count($arena->players)) { foreach ($arena->spawnpoints as $spawn) { //What the heck is this if (!in_array($spawn, $arena->usedSpawnpoints)) { $spawnString = json_encode($spawn); $spawnArray = json_decode($spawnString, true); $vector = new Vector3($spawnArray['x'], $spawnArray['y'], $spawnArray['z']); $pos = Position::fromObject($vector, Server::getInstance()->getLevelByName($spawnArray['level'])); $player->teleport($pos); $player->setGamemode(0); array_push($arena->players, $player); $arena->playerSpawns[$player->getName()] = $pos; $arena->usedSpawnpoints[] = $spawn; break 2; } } } } } } }
public function teleport(Vector3 $pos, $yaw = null, $pitch = null) { $from = Position::fromObject($this, $this->getLevel()); $to = Position::fromObject($pos, $pos instanceof Position ? $pos->getLevel() : $this->getLevel()); $this->server->getPluginManager()->callEvent($ev = new EntityTeleportEvent($this, $from, $to)); if ($ev->isCancelled()) { return false; } $this->ySize = 0; $pos = $ev->getTo(); $this->setMotion(new Vector3(0, 0, 0)); if ($this->setPositionAndRotation($pos, $yaw === null ? $this->yaw : $yaw, $pitch === null ? $this->pitch : $pitch, true) !== false) { $this->fallDistance = 0; $this->onGround = true; return true; } return false; }
/** * @param string $name * @param Position $pos */ public function setHome($name = "default", Position $pos) { $this->homes[$name] = Position::fromObject($pos, $pos->getLevel()); $db = $this->getMain()->getFList()->getDb(); $op = $db->prepare("INSERT OR REPLACE INTO factions_homes (x, y, z, name, fid) VALUES (:x, :y, :z, :name, :id);"); $op->bindValue(":x", $pos->getX()); $op->bindValue(":y", $pos->getY()); $op->bindValue(":z", $pos->getZ()); $op->bindValue(":name", $name); $op->bindValue(":id", $this->id); $op->execute(); }
/** * Returns the Block on the side $side, works like Vector3::side() * * @param int $side * @param int $step * * @return Block */ public function getSide($side, $step = 1) { if ($this->isValid()) { return $this->getLevel()->getBlock(Vector3::getSide($side, $step)); } return Block::get(Item::AIR, 0, Position::fromObject(Vector3::getSide($side, $step))); }
/** * Returns a side Vector * * @param int $side * @param int $step * * @return Position * * @throws LevelException */ public function getSide($side, $step = 1) { if (!$this->isValid()) { throw new LevelException("Undefined Level reference"); } return Position::fromObject(parent::getSide($side, $step), $this->level); }
/** * @param CommandSender $sender * @param Command $command * @param string $label * @param array $args * * @return bool */ public function onCommand(CommandSender $sender, Command $command, $label, array $args) { if ($command->getName() != "izone" || !$sender instanceof Player) { return false; } switch (strtolower(array_shift($args))) { case "pos1": $this->positions1[spl_object_hash($sender)] = Position::fromObject($sender, $sender->getLevel()); $sender->sendMessage("[iZone] Registered Position #1"); return true; break; case "pos2": $this->positions2[spl_object_hash($sender)] = Position::fromObject($sender, $sender->getLevel()); $sender->sendMessage("[iZone] Registered Position #2"); return true; break; case "create": if (!$sender->isOp() && !$this->getConfig()->get("non-op-create", false)) { $sender->sendMessage("[iZone] You don't have the right to create a private zone"); return true; } $name = array_shift($args); if ($name == null || empty($name) || isset($this->zones[$name])) { $sender->sendMessage("[iZone] The zone already exist or name cannot be empty"); return true; } if (!isset($this->positions1[spl_object_hash($sender)]) || !isset($this->positions2[spl_object_hash($sender)])) { $sender->sendMessage("[iZone] Set two positions with /izone pos1 and /izone pos2"); return true; } $pos1 = $this->positions1[spl_object_hash($sender)]; $pos2 = $this->positions2[spl_object_hash($sender)]; if (strtolower(array_shift($args)) == "noheight") { $pos1->y = 0; $pos2->y = 256; } if (!$sender->isOp()) { if (abs($pos1->getX() - $pos2->getX()) > $this->getConfig()->get("maximum-x", 30)) { $sender->sendMessage("[iZone] The area has exceeded the maximum x-length!"); return true; } else { if (abs($pos1->getY() - $pos2->getY()) > $this->getConfig()->get("maximum-y", 30)) { $sender->sendMessage("[iZone] The area has exceeded the maximum y-height!"); return true; } else { if (abs($pos1->getZ() - $pos2->getZ()) > $this->getConfig()->get("maximum-z", 30)) { $sender->sendMessage("[iZone] The area has exceeded the maximum z-width!"); return true; } } } } $zone = new Zone($this, $name, $sender, $pos1, $pos2); foreach ($this->zones as $z) { if ($z->intersectsWith($zone)) { $sender->sendMessage("[iZone] You can not interfere with other zones"); return true; } } $this->getServer()->getPluginManager()->callEvent($ev = new ZoneCreatedEvent($this, $zone)); if ($ev->isCancelled()) { return false; } $this->zones[$name] = $zone; $this->dataProvider->addZone($zone); $sender->sendMessage("[iZone] The zone {$name} have been have successfully created"); unset($this->positions1[spl_object_hash($sender)]); unset($this->positions2[spl_object_hash($sender)]); return true; break; case "remove": $name = array_shift($args); if ($name == null || empty($name) || !isset($this->zones[$name])) { $sender->sendMessage("[iZone] The zone doesn't exist"); return true; } if ($sender->isOp() || $sender->hasPermission($name . OWNER)) { $this->getServer()->getPluginManager()->callEvent($ev = new ZoneRemovedEvent($this, $this->zones[$name], $sender)); if ($ev->isCancelled()) { return false; } $this->dataProvider->removeZone($this->zones[$name]); $owner = $this->zones[$name]->getOwner(); unset($this->zones[$name]); $owner = $this->getServer()->getPlayer($owner); if ($owner == null) { $sender->sendMessage("[iZone] The zone {$name} have been removed"); return true; } $owner->sendMessage("[iZone] The zone {$name} have been removed."); if ($owner->getName() !== $sender->getName()) { $sender->sendMessage("[iZone] The zone {$name} have been removed"); } return true; } $sender->sendMessage("[iZone] You don't have the right to do that"); return true; break; case "addmember": $name = array_shift($args); $user = array_shift($args); $as = array_shift($args); if (empty($name) || $name == null || !isset($this->zones[$name])) { $sender->sendMessage("[iZone] The zone doesn't exist"); return true; } if ($sender->isOp() || $sender->hasPermission($name . OWNER)) { if (empty($user) || $user == null || ($user = $this->getServer()->getPlayer($user)) == null) { $sender->sendMessage("[iZone] The player doesn't exist or is offline!"); return true; } if ($user->hasPermission($name . MEMBER)) { //Force them to remove the member mannually $sender->sendMessage("[iZone] The player is already member of this zone!"); return true; } $perm = $as == "owner" ? $name . OWNER : $name . MEMBER; $this->getServer()->getPluginManager()->callEvent($ev = new ZoneSetPermissionEvent($this, $this->zones[$name], $user, $perm)); if ($ev->isCancelled()) { return false; } $this->addPermission($user, $perm); $this->dataProvider->setPermission($user, $perm); $sender->sendMessage("[iZone] The player has been added!"); return true; } $sender->sendMessage("[iZone] You don't have right to do that"); return true; break; case "removemember": $name = array_shift($args); $user = array_shift($args); if ($name == null || empty($name) || !isset($this->zones[$name])) { $sender->sendMessage("[iZone] The zone doesn't exist"); return true; } if ($sender->isOp() || $sender->hasPermission($name . OWNER)) { if ($user == null || empty($user) || ($user = $this->getServer()->getPlayer($user)) == null) { $sender->sendMessage("[iZone] The player doesn't exist or not is offline!"); return true; } if (!$user->hasPermission($name . MEMBER)) { $sender->sendMessage("[iZone] The player is not a member of this zone!"); return true; } $ownerName = $this->zones[$name]->getOwner(); if ($user->getName() == $ownerName) { $sender->sendMessage("[iZone] The owner couldn't be removed from the zone!"); return true; } $isOwner = $user->hasPermission($name . OWNER); if ($isOwner && $sender->getName() != $ownerName) { $sender->sendMessage("[iZone] You can't remove an owner!"); return true; } $permission = $isOwner ? $name . OWNER : $name . MEMBER; $this->getServer()->getPluginManager()->callEvent($ev = new ZoneRemovePermissionEvent($this, $this->zones[$name], $user, $permission)); if ($ev->isCancelled()) { return false; } $this->removePermission($user, $permission); $this->dataProvider->unsetPermission($user, $this->zones[$name]); $sender->sendMessage("[iZone] The player has been removed!"); return true; } $sender->sendMessage("[iZone] You don't have permission to do that"); return true; break; case "leave": $name = array_shift($args); if ($name == null || empty($name) || !isset($this->zones[$name])) { $sender->sendMessage("[iZone] The zone doesn't exist"); return true; } if ($sender->hasPermission($name . MEMBER)) { if ($this->zones[$name]->getOwner() == $sender->getName()) { $sender->sendMessage("[iZone] You can't leave your own zone!"); return true; } $permission = $sender->hasPermission($name . OWNER) ? $name . OWNER : $name . MEMBER; $this->getServer()->getPluginManager()->callEvent($ev = new ZoneRemovePermissionEvent($this, $this->zones[$name], $sender, $permission)); if ($ev->isCancelled()) { return false; } $this->removePermission($sender, $permission); $this->dataProvider->unsetPermission($sender, $this->zones[$name]); $sender->sendMessage("[iZone] You have left the zone!"); return true; } $sender->sendMessage("[iZone] You are not a member of this zone!"); return true; break; case "setpvp": $name = array_shift($args); $state = array_shift($args); if (!$sender->isOp() && !$sender->hasPermission($name . OWNER)) { $sender->sendMessage("[iZone] You don't have right to do that"); return true; } if (strtolower($state) == "on" || $state == "1") { if (isset($this->zones[$name])) { $this->zones[$name]->pvpAvailable = true; $sender->sendMessage("[iZone] Enabled PVP in {$name}"); return true; } $sender->sendMessage("[iZone] The zone {$name} does not exist!"); return true; } else { if (strtolower($state == "off") || $state == "0") { if (isset($this->zones[$name])) { $this->zones[$name]->pvpAvailable = false; $sender->sendMessage("[iZone] Disabled PVP in {$name}"); return true; } $sender->sendMessage("[iZone] The zone {$name} does not exist!"); return true; } } $sender->sendMessage("[iZone] Unable to identify the command"); return true; break; case "coord": $sender->sendMessage("[iZone] Coordinates: X: {$sender->x} Y: {$sender->y} Z: {$sender->z}"); return true; break; case "help": default: $sender->sendMessage("Usage: /izone <command> [parameters] {optional}"); $sender->sendMessage("Usage: /izone create [name] {noheight}"); $sender->sendMessage("Usage: /izone remove [name]"); $sender->sendMessage("Usage: /izone addmember [zone] [player] {owner}"); $sender->sendMessage("Usage: /izone removemember [zone] [player]"); $sender->sendMessage("Usage: /izone leave [zone]"); $sender->sendMessage("Usage: /izone setpvp [zone] [on/off]"); $sender->sendMessage("Usage: /izone coord"); return true; break; } return false; }
/** * @param Vector3|Position|Location $pos * @param float $yaw * @param float $pitch * * @return bool */ public function teleport(Vector3 $pos, $yaw = null, $pitch = null) { if ($pos instanceof Location) { $yaw = $yaw === null ? $pos->yaw : $yaw; $pitch = $pitch === null ? $pos->pitch : $pitch; } $from = Position::fromObject($this, $this->level); $to = Position::fromObject($pos, $pos instanceof Position ? $pos->getLevel() : $this->level); $this->server->getPluginManager()->callEvent($ev = new EntityTeleportEvent($this, $from, $to)); if ($ev->isCancelled()) { return false; } $this->ySize = 0; $pos = $ev->getTo(); $this->setMotion(new Vector3(0, 0, 0)); if ($this->setPositionAndRotation($pos, $yaw === null ? $this->yaw : $yaw, $pitch === null ? $this->pitch : $pitch, true) !== false) { $this->resetFallDistance(); $this->onGround = true; $this->lastX = $this->x; $this->lastY = $this->y; $this->lastZ = $this->z; $this->lastYaw = $this->yaw; $this->lastPitch = $this->pitch; $this->updateMovement(); return true; } return false; }
public function onGrowRun(array $args, Player $player) { if (!isset($args[2])) { return self::WRONG_USE; } $reverse = false; if ($args[0] === "r" or $args[0] === "reverse") { $reverse = true; array_shift($args); } foreach ($args as $arg) { if (!is_numeric($arg)) { return self::WRONG_USE; } } $xp = (int) array_shift($args); $yp = (int) array_shift($args); $zp = (int) array_shift($args); $xm = $xp; $ym = $yp; $zm = $zp; if (isset($args[0])) { $xm = (int) array_shift($args); } if (isset($args[0])) { $ym = (int) array_shift($args); } if (isset($args[0])) { $zm = (int) array_shift($args); } $from = new Vector3($xm, $ym, $zm); $to = new Vector3($xp, $yp, $zp); $level = $player->getLevel(); if ($reverse) { $space = new CuboidSpace(Position::fromObject($to, $level), $from); } else { $space = new CuboidSpace(Position::fromObject($from, $level), $to); } $this->getMain()->setSelection($player, $space); return "Cuboid selection set: {$space}"; }