Skip to content

Commit

Permalink
done
Browse files Browse the repository at this point in the history
  • Loading branch information
xxAROX committed Feb 13, 2024
1 parent e790864 commit 6a46f70
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 24 deletions.
Binary file modified Presence-Man.phar
Binary file not shown.
24 changes: 3 additions & 21 deletions src/xxAROX/PresenceMan/EventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class EventListener implements Listener{
public function PlayerLoginEvent(PlayerLoginEvent $event): void{
if (Utils::isFromSameHost($event->getPlayer()->getNetworkSession()->getIp())) return;
if (!PresenceMan::$ENABLE_DEFAULT) return;
if (!PresenceMan::$UPDATE_SKIN) PresenceMan::save_head($event->getPlayer(), $event->getPlayer()->getSkin());
if (!PresenceMan::$UPDATE_SKIN) PresenceMan::save_skin($event->getPlayer(), $event->getPlayer()->getSkin());
PresenceMan::setActivity($event->getPlayer(), ApiActivity::default_activity());
}

Expand All @@ -43,17 +43,7 @@ public function PlayerLoginEvent(PlayerLoginEvent $event): void{
*/
public function PlayerChangeSkinEvent(PlayerChangeSkinEvent $event): void{
if (Utils::isFromSameHost($event->getPlayer()->getNetworkSession()->getIp())) return;
if (!$event->isCancelled()) {
try {
$class = new ReflectionClass(PresenceMan::class);
$method = $class->getMethod("save_skin");
$method->setAccessible(true);
/** @see PresenceMan::save_skin */
$method->invokeArgs(null, [$event->getPlayer(), $event->getNewSkin()]);
} catch (ReflectionException $e) {
throw new ErrorException("Method does not exist");
}
}
if (!$event->isCancelled()) PresenceMan::save_skin($event->getPlayer(), $event->getPlayer()->getSkin());
}

/**
Expand All @@ -64,14 +54,6 @@ public function PlayerChangeSkinEvent(PlayerChangeSkinEvent $event): void{
public function PlayerQuitEvent(PlayerQuitEvent $event): void{
if (Utils::isFromSameHost($event->getPlayer()->getNetworkSession()->getIp())) return;
unset(PresenceMan::$presences[$event->getPlayer()->getXuid()]);
try {
$class = new ReflectionClass(PresenceMan::class);
$method = $class->getMethod("offline");
$method->setAccessible(true);
/** @see PresenceMan::offline */
$method->invokeArgs(null, [$event->getPlayer()]);
} catch (ReflectionException $e) {
throw new ErrorException("Method does not exist");
}
PresenceMan::offline($event->getPlayer());
}
}
5 changes: 2 additions & 3 deletions src/xxAROX/PresenceMan/PresenceMan.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ public static function setActivity(Player $player, ?ApiActivity $activity = null
Server::getInstance()->getAsyncPool()->submitTask(new BackendRequest(
$request->serialize(),
function (array $response) use ($player, $activity): void{
var_dump($response);
if (isset($response["status"]) == 200) self::$presences[$player->getXuid()] = $activity;
else PresenceMan::getInstance()->getLogger()->error("Failed to update presence for " . $player->getName() . ": " . $response["message"] ?? "n/a");
}
Expand All @@ -143,7 +142,7 @@ function (array $response) use ($player, $activity): void{
* @return void
* @internal
*/
private static function save_skin(Player $player, Skin $skin): void{
public static function save_skin(Player $player, Skin $skin): void{
if (Utils::isFromSameHost($player->getNetworkSession()->getIp())) return;
if (!Server::getInstance()->isRunning()) return;
if (empty($player->getXuid())) return;
Expand Down Expand Up @@ -173,7 +172,7 @@ private static function save_skin(Player $player, Skin $skin): void{
* @return void
* @internal
*/
private static function offline(Player $player): void{
public static function offline(Player $player): void{
if (Utils::isFromSameHost($player->getNetworkSession()->getIp())) return;
$request = new ApiRequest(ApiRequest::$URI_UPDATE_OFFLINE, [
"ip" => $player->getNetworkSession()->getIp(),
Expand Down

0 comments on commit 6a46f70

Please sign in to comment.