예제 #1
31
 /**
  * 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;
 }
예제 #2
0
 private function internal_onQuit(Player $player)
 {
     if (isset($this->sessions[$player->getId()])) {
         $this->sessions[$player->getId()]->close();
         unset($this->sessions[$player->getId()]);
     }
 }
예제 #3
0
 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());
 }
예제 #6
0
 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));
 }
예제 #7
0
 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);
             }
         }
     }
 }
예제 #8
0
 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);
 }
예제 #11
0
 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()];
 }
예제 #13
0
 public function hidePlayer(Player $player)
 {
     $player->despawnFromAll();
     $pk = new RemoveEntityPacket();
     $pk->eid = $player->getId();
     foreach ($player->getLevel()->getPlayers() as $p) {
         $p->dataPacket($pk);
     }
 }
예제 #14
0
 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;
 }
예제 #15
0
 public function getUserByPlayer(Player $player)
 {
     $id = $player->getId();
     return $this->users[$id] ?? null;
 }
예제 #16
0
 /**
  * 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);
 }
예제 #17
0
 /**
  * @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;
 }
예제 #19
0
파일: Door.php 프로젝트: rryy/PocketMine-MP
 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;
 }
예제 #20
0
 /**
  * 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);
 }
예제 #21
0
 /**
  * @param Player $player
  *
  * @return Gamer|null
  */
 public function getGamerForPlayer(Player $player)
 {
     return $this->gamers[$player->getId()] ?? null;
 }
예제 #22
0
 public function addOnlinePlayer(Player $player)
 {
     $this->playerList[$player->getRawUniqueId()] = $player;
     $this->updatePlayerListData($player->getUniqueId(), $player->getId(), $player->getDisplayName(), $player->isSkinSlim(), $player->getSkinFlag(), $player->getSkinData());
 }
예제 #23
0
파일: Level.php 프로젝트: xHFx/Steadfast2
 /**
  * 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);
 }
예제 #24
0
 /**
  * @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()]);
     }
 }
예제 #25
0
 /**
  * @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)]);
     }
 }