/** * Tries to break a block using a item, including Player time checks if available * It'll try to lower the durability if Item is a tool, and set it to Air if broken. * * @param Vector3 $vector * @param Item &$item (if null, can break anything) * @param Player $player * * @return boolean */ public function useBreakOn(Vector3 $vector, Item &$item = null, Player $player = null) { $target = $this->getBlock($vector); //TODO: Adventure mode checks if ($item === null) { $item = Item::get(Item::AIR, 0, 0); } if ($player instanceof Player) { $ev = new BlockBreakEvent($player, $target, $item, ($player->getGamemode() & 0x1) === 1 ? true : false); if ($player->isSurvival() and $item instanceof Item and !$target->isBreakable($item)) { $ev->setCancelled(); } if (!$player->isOp() and ($distance = $this->server->getSpawnRadius()) > -1) { $t = new Vector2($target->x, $target->z); $s = new Vector2($this->getSpawnLocation()->x, $this->getSpawnLocation()->z); if (count($this->server->getOps()->getAll()) > 0 and $t->distance($s) <= $distance) { //set it to cancelled so plugins can bypass this $ev->setCancelled(); } } $this->server->getPluginManager()->callEvent($ev); if ($ev->isCancelled()) { return false; } $breakTime = $player->isCreative() ? 0.15 : $target->getBreakTime($item); if ($player->hasEffect(Effect::SWIFTNESS)) { $breakTime *= pow(0.8, $player->getEffect(Effect::SWIFTNESS)->getAmplifier() + 1); } if (!$ev->getInstaBreak() and $player->lastBreak + $breakTime >= microtime(true)) { return false; } $player->lastBreak = PHP_INT_MAX; } elseif ($item instanceof Item and !$target->isBreakable($item)) { return false; } $level = $target->getLevel(); if ($level instanceof Level) { $above = $level->getBlock(new Vector3($target->x, $target->y + 1, $target->z)); if ($above instanceof Block) { if ($above->getId() === Item::FIRE) { $level->setBlock($above, new Air(), true); } } } $drops = $target->getDrops($item); //Fixes tile entities being deleted before getting drops $players = $this->getUsingChunk($target->x >> 4, $target->z >> 4); if ($player !== null) { unset($players[$player->getId()]); $this->addParticle(new DestroyBlockParticle($target->add(0.5, 0.5, 0.5), $target), $players); } $target->onBreak($item); $tile = $this->getTile($target); if ($tile instanceof Tile) { if ($tile instanceof InventoryHolder) { if ($tile instanceof Chest) { $tile->unpair(); } foreach ($tile->getInventory()->getContents() as $chestItem) { $this->dropItem($target, $chestItem); } } $tile->close(); } if ($item instanceof Item) { $item->useOn($target); if ($item->isTool() and $item->getDamage() >= $item->getMaxDurability()) { $item = Item::get(Item::AIR, 0, 0); } } if (!$player instanceof Player or $player->isSurvival()) { foreach ($drops as $drop) { if ($drop[2] > 0) { $this->dropItem($vector->add(0.5, 0.5, 0.5), Item::get(...$drop)); } } } return true; }
private function internal_onQuit(Player $player) { if (isset($this->sessions[$player->getId()])) { $this->sessions[$player->getId()]->close(); unset($this->sessions[$player->getId()]); } }
public function __construct(FullChunk $chunk, CompoundTag $nbt, Player $owner = null) { if ($owner == null) { $this->close(); return; } parent::__construct($chunk, $nbt); $this->owner = $owner; $this->setDataProperty(self::DATA_NO_AI, self::DATA_TYPE_BYTE, 1); $this->setDataProperty(self::DATA_SOURCE_UUID, self::DATA_TYPE_LONG, $this->owner->getId()); $this->setDataProperty(self::DATA_TARGET_UUID, self::DATA_TYPE_LONG, $this->getId()); }
public function setMute(Player $player, $muted) { $sub = $this->playerSubs[$player->getId()]; $original = $sub->muted; $sub->muted = $muted; return $original; }
private function private_onLogin(Player $player) { /** @var string|LoginDataQuery $LoginQuery */ $LoginQuery = $this->main->getLoginQueryImpl(); /** @noinspection PhpDeprecationInspection */ new $LoginQuery($this->main, $player->getId(), $player->getName(), $player->getAddress(), $player->getClientId()); }
public function setFlaming(Player $target) { $flags = (int) $target->getDataProperty(Player::DATA_FLAGS); $flags ^= 1 << Player::DATA_FLAG_ONFIRE; $dataProperty = [Player::DATA_FLAGS => [Player::DATA_TYPE_BYTE, $flags]]; $pk = new SetEntityDataPacket(); $pk->eid = $target->getId(); $pk->metadata = $dataProperty; Server::broadcastPacket($this->getPlayer()->getLevel()->getPlayers(), $pk->setChannel(Network::CHANNEL_WORLD_EVENTS)); }
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); } } } }
public function __construct(HereAuth $main, Player $player, AccountInfo $info) { $this->loadTime = microtime(true); $this->main = $main; $this->player = $player; $this->accountInfo = $info; if (!$info->passwordHash) { $main->getDataBase()->passesLimit($player->getAddress(), $main->getConfig()->getNested("Registration.RateLimit.Accounts", 3), $main->getConfig()->getNested("Registration.RateLimit.Days", 30) * 86400, $player->getId()); if (!$main->getConfig()->getNested("ForceRegister.Enabled", true)) { // no registration involved $this->onAuth(); $reminder = $main->getConfig()->getNested("ForceRegister.Reminder", ""); if (strlen($reminder) > 0) { $player->sendMessage($reminder); } return; } $this->startRegistration(); $this->initAppearance(); return; } if (!$this->checkMultiFactor()) { throw new \Exception("MFA failure"); } if ($info->passwordHash[0] !== "{") { if ($info->opts->autoSecret and $player->getClientSecret() === $info->lastSecret and $this->callLogin(HereAuthLoginEvent::METHOD_CLIENT_SECRET)) { $this->main->getAuditLogger()->logLogin(strtolower($player->getName()), $player->getAddress(), "secret"); $this->onAuth(); return; } if ($info->opts->autoIp and $player->getAddress() === $info->lastIp and $this->callLogin(HereAuthLoginEvent::METHOD_IP)) { $this->main->getAuditLogger()->logLogin(strtolower($player->getName()), $player->getAddress(), "ip"); $this->onAuth(); return; } if ($info->opts->autoUuid and $player->getUniqueId()->toBinary() === $info->lastUuid and $this->callLogin(HereAuthLoginEvent::METHOD_UUID)) { $this->main->getAuditLogger()->logLogin(strtolower($player->getName()), $player->getAddress(), "uuid"); $this->onAuth(); return; } } $this->state = self::STATE_PENDING_LOGIN; $this->player->sendMessage($main->getMessages()->getNested("Login.Query", "Please login")); $this->initAppearance(); }
public function endSession(Player $player) { if (isset($this->playerQueues[$player->getId()])) { unset($this->playerQueues[$player->getId()]); } if (isset($this->sessions[$player->getId()])) { $this->sessions[$player->getId()]->onQuit(); unset($this->sessions[$player->getId()]); } }
public function __construct(BasePlugin $plugin, Player $player) { $this->sesId = $player->getId(); parent::__construct($plugin, self::USER); }
public function getUserByPlayer(Player $player) { $id = $player->getId(); return isset($this->users[$id]) ? $this->users[$id] : null; }
public function getSession(Player $player) { return $this->sessions[$player->getId()]; }
public function hidePlayer(Player $player) { $player->despawnFromAll(); $pk = new RemoveEntityPacket(); $pk->eid = $player->getId(); foreach ($player->getLevel()->getPlayers() as $p) { $p->dataPacket($pk); } }
public function onActivate(Item $item, Player $player = null) { if (($this->getDamage() & 0x8) === 0x8) { //Top $down = $this->getSide(0); if ($down->getId() === $this->getId()) { $meta = $down->getDamage() ^ 0x4; $this->getLevel()->setBlock($down, Block::get($this->getId(), $meta), true); $players = $this->getLevel()->getUsingChunk($this->x >> 4, $this->z >> 4); if ($player instanceof Player) { unset($players[$player->getId()]); } $this->level->addSound(new DoorSound($this)); return true; } return false; } else { $this->meta ^= 0x4; $this->getLevel()->setBlock($this, $this, true); $players = $this->getLevel()->getUsingChunk($this->x >> 4, $this->z >> 4); if ($player instanceof Player) { unset($players[$player->getId()]); } $this->level->addSound(new DoorSound($this)); } return true; }
public function getUserByPlayer(Player $player) { $id = $player->getId(); return $this->users[$id] ?? null; }
/** * WARNING: Do not use this, it's only for internal use. * Changes to this function won't be recorded on the version. * * @param int $X * @param int $Z * @param Player $player */ public function freeChunk($X, $Z, Player $player) { unset($this->usedChunks[$index = PHP_INT_SIZE === 8 ? ($X & 4294967295.0) << 32 | $Z & 4294967295.0 : $X . ":" . $Z][$player->getId()]); $this->unloadChunkRequest($X, $Z, true); }
/** * @param Player $player */ public function despawnFrom(Player $player) { if (isset($this->hasSpawned[$player->getId()])) { $pk = new RemoveEntityPacket(); $pk->eid = $this->id; $player->dataPacket($pk->setChannel(Network::CHANNEL_ENTITY_SPAWNING)); unset($this->hasSpawned[$player->getId()]); } }
public function getSession(Player $player) { return isset($this->sessions[$id = $player->getId()]) ? $this->sessions[$id] : null; }
public function onActivate(Item $item, Player $player = null) { if (($this->meta & 0x8) === 0x8) { //Top $down = $this->getSide(0); if ($down->getId() === $this->id) { $meta = $down->getDamage() ^ 0x4; $this->getLevel()->setBlock($down, Block::get($this->id, $meta), true); $players = $this->getLevel()->getUsingChunk($this->x >> 4, $this->z >> 4); if ($player instanceof Player) { unset($players[$player->getId()]); } $pk = new LevelEventPacket(); $pk->x = $this->x; $pk->y = $this->y; $pk->z = $this->z; $pk->evid = 1003; $pk->data = 0; Server::broadcastPacket($players, $pk); return true; } return false; } else { $this->meta ^= 0x4; $this->getLevel()->setBlock($this, $this, true); $players = $this->getLevel()->getUsingChunk($this->x >> 4, $this->z >> 4); if ($player instanceof Player) { unset($players[$player->getId()]); } $pk = new LevelEventPacket(); $pk->x = $this->x; $pk->y = $this->y; $pk->z = $this->z; $pk->evid = 1003; $pk->data = 0; Server::broadcastPacket($players, $pk); } return true; }
/** * WARNING: Do not use this, it's only for internal use. * Changes to this function won't be recorded on the version. * * @param int $X * @param int $Z * @param Player $player */ public function freeChunk($X, $Z, Player $player) { unset($this->usedChunks[$index = Level::chunkHash($X, $Z)][$player->getId()]); $this->unloadChunkRequest($X, $Z, true); }
/** * @param Player $player * * @return Gamer|null */ public function getGamerForPlayer(Player $player) { return $this->gamers[$player->getId()] ?? null; }
public function addOnlinePlayer(Player $player) { $this->playerList[$player->getRawUniqueId()] = $player; $this->updatePlayerListData($player->getUniqueId(), $player->getId(), $player->getDisplayName(), $player->isSkinSlim(), $player->getSkinFlag(), $player->getSkinData()); }
/** * WARNING: Do not use this, it's only for internal use. * Changes to this function won't be recorded on the version. * * @param int $X * @param int $Z * @param Player $player */ public function freeChunk($X, $Z, Player $player) { unset($this->usedChunks[$index = \PHP_INT_SIZE === 8 ? ($X & 0xffffffff) << 32 | $Z & 0xffffffff : $X . ":" . $Z][$player->getId()]); $this->unloadChunkRequest($X, $Z, \true); }
/** * @param Player $player */ public function despawnFrom(Player $player) { if (isset($this->hasSpawned[$player->getId()])) { $pk = new RemoveEntityPacket(); $pk->eid = $this->getId(); $player->dataPacket($pk); unset($this->hasSpawned[$player->getId()]); } }
/** * @param Player $player */ public function despawnBlockMan(Player $player) { $player->despawnFromAll(); $pk = new RemoveEntityPacket(); $pk->eid = $player->getId(); if (isset($this->blockMans[spl_object_hash($player)])) { foreach ($this->blockMans[spl_object_hash($player)] as $p) { /** @var $p Player */ $p->dataPacket($pk); } unset($this->blockMans[spl_object_hash($player)]); } }