/** * @param array $keyPair * @return Player|null */ public function getPlayer($keyPair = []) { $pairs = array_merge(['name' => null, 'uuid' => null, 'unknown' => null], $keyPair); foreach ($pairs as $key => $val) { if ($key == 'uuid') { $val = str_replace("-", "", $val); } if ($val != null && $val != '') { $filename = $this->options['cache_folder_player'] . DIRECTORY_SEPARATOR . $key . DIRECTORY_SEPARATOR . $this->getCacheFileName($val) . '.json'; if ($key == 'uuid') { if (!strlen($val) == 32) { continue; } $content = $this->getCache($filename); if ($content != null) { $timestamp = array_key_exists('timestamp', $content) ? $content['timestamp'] : 0; if (time() - $this->getCacheTime() < $timestamp) { return new Player($content, $this); } } $response = $this->fetch('player', $key, $val); if ($response['success'] == true) { $PLAYER = new Player(['record' => $response['player'], 'extra' => $content['extra']], $this); $PLAYER->setExtra(['filename' => $filename]); $this->setCache($filename, $PLAYER); return $PLAYER; } } else { if ($key == 'name') { if (file_exists($filename) || $this->hasPaid($val)) { $uuid = $this->getUUID($val); return $this->getPlayer(['uuid' => $uuid]); } } else { if ($key == 'unknown') { $this->debug('Determining type.', false); $type = InputType::getType($val); if ($type == InputType::USERNAME) { $this->debug('Input is username, fetching UUID.', false); $uuid = $this->getUUID($val); } else { if ($type == InputType::UUID) { $uuid = $val; } else { return null; } } return $this->getPlayer(['uuid' => $uuid]); } } } } } if ($this->getCacheTime() < self::MAX_CACHE_TIME) { $this->setCacheTime(self::MAX_CACHE_TIME); return $this->getPlayer($pairs); } return null; }
/** * @param $value * * @return bool|null|string */ public function getUUIDFromVar($value) { $uuid = null; $type = InputType::getType($value); if ($type !== null) { if ($type == InputType::USERNAME) { $this->debug('Input is username, fetching UUID.', false); $uuid = $this->getUUID((string) $value); } else { if ($type == InputType::UUID) { $this->debug('Input is UUID.', false); $uuid = $value; } else { if ($type == InputType::PLAYER_OBJECT) { $this->debug('Input is Player Object.', false); /** @var Player $value */ $uuid = $value->getUUID(); } } } if ($uuid === false) { return null; } } return $uuid; }