From ba214f3adf812d920e2076bce9df6d3bc4123fa4 Mon Sep 17 00:00:00 2001 From: js6pak Date: Fri, 8 Apr 2022 20:56:06 +0200 Subject: [PATCH] Make session service static --- .../client/skinfix/provider/MojangProfileProvider.java | 4 +--- .../mixin/client/auth/ClientNetworkHandlerMixin.java | 2 +- .../js6pak/mojangfix/mixin/client/auth/SessionMixin.java | 7 ------- .../pl/js6pak/mojangfix/mixinterface/SessionAccessor.java | 2 +- 4 files changed, 3 insertions(+), 12 deletions(-) diff --git a/src/main/java/pl/js6pak/mojangfix/client/skinfix/provider/MojangProfileProvider.java b/src/main/java/pl/js6pak/mojangfix/client/skinfix/provider/MojangProfileProvider.java index 23f4005..8699b1d 100644 --- a/src/main/java/pl/js6pak/mojangfix/client/skinfix/provider/MojangProfileProvider.java +++ b/src/main/java/pl/js6pak/mojangfix/client/skinfix/provider/MojangProfileProvider.java @@ -19,7 +19,6 @@ import com.github.steveice10.mc.auth.exception.profile.ProfileException; import com.github.steveice10.mc.auth.service.ProfileService; import com.github.steveice10.mc.auth.service.SessionService; -import pl.js6pak.mojangfix.mixin.client.MinecraftAccessor; import pl.js6pak.mojangfix.mixinterface.SessionAccessor; import java.util.concurrent.CompletableFuture; @@ -32,10 +31,9 @@ public class MojangProfileProvider implements ProfileProvider { public Future get(String username) { CompletableFuture future = new CompletableFuture<>(); - final SessionAccessor session = (SessionAccessor) MinecraftAccessor.getInstance().session; profileService.findProfilesByName(new String[]{username}, new ProfileService.ProfileLookupCallback() { public void onProfileLookupSucceeded(GameProfile profile) { - SessionService sessionService = session.getSessionService(); + SessionService sessionService = SessionAccessor.SESSION_SERVICE; try { sessionService.fillProfileProperties(profile); diff --git a/src/main/java/pl/js6pak/mojangfix/mixin/client/auth/ClientNetworkHandlerMixin.java b/src/main/java/pl/js6pak/mojangfix/mixin/client/auth/ClientNetworkHandlerMixin.java index 9ec1398..1b8aba0 100644 --- a/src/main/java/pl/js6pak/mojangfix/mixin/client/auth/ClientNetworkHandlerMixin.java +++ b/src/main/java/pl/js6pak/mojangfix/mixin/client/auth/ClientNetworkHandlerMixin.java @@ -55,7 +55,7 @@ private void onJoinServer(HandshakePacket packet, CallbackInfo ci) { this.connection.disconnect("disconnect.loginFailedInfo", "Invalid access token!"); } - session.getSessionService().joinServer(session.getGameProfile(), session.getAccessToken(), packet.name); + SessionAccessor.SESSION_SERVICE.joinServer(session.getGameProfile(), session.getAccessToken(), packet.name); this.sendPacket(new LoginHelloPacket(this.minecraft.session.username, 14)); } catch (RequestException e) { this.connection.disconnect("disconnect.loginFailedInfo", e.getClass().getSimpleName() + "\n" + e.getMessage()); diff --git a/src/main/java/pl/js6pak/mojangfix/mixin/client/auth/SessionMixin.java b/src/main/java/pl/js6pak/mojangfix/mixin/client/auth/SessionMixin.java index bc40759..3d3100a 100644 --- a/src/main/java/pl/js6pak/mojangfix/mixin/client/auth/SessionMixin.java +++ b/src/main/java/pl/js6pak/mojangfix/mixin/client/auth/SessionMixin.java @@ -16,7 +16,6 @@ package pl.js6pak.mojangfix.mixin.client.auth; import com.github.steveice10.mc.auth.data.GameProfile; -import com.github.steveice10.mc.auth.service.SessionService; import lombok.Getter; import net.minecraft.client.util.Session; import org.spongepowered.asm.mixin.Mixin; @@ -41,17 +40,11 @@ public class SessionMixin implements SessionAccessor { @Getter private String accessToken; - @Unique - @Getter - private SessionService sessionService; - @Unique private static final Pattern UUID_PATTERN = Pattern.compile("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})"); @Inject(method = "", at = @At("RETURN")) private void onInit(String username, String sessionId, CallbackInfo ci) { - this.sessionService = new SessionService(); - String[] split = sessionId.split(":"); if (split.length == 3 && split[0].equalsIgnoreCase("token")) { accessToken = split[1]; diff --git a/src/main/java/pl/js6pak/mojangfix/mixinterface/SessionAccessor.java b/src/main/java/pl/js6pak/mojangfix/mixinterface/SessionAccessor.java index 597cada..d9ab53d 100644 --- a/src/main/java/pl/js6pak/mojangfix/mixinterface/SessionAccessor.java +++ b/src/main/java/pl/js6pak/mojangfix/mixinterface/SessionAccessor.java @@ -23,5 +23,5 @@ public interface SessionAccessor { String getAccessToken(); - SessionService getSessionService(); + SessionService SESSION_SERVICE = new SessionService(); }