From 07a0001ab4d0f3eb1f6c386904c1801bfc32be37 Mon Sep 17 00:00:00 2001
From: FlorianMichael <60033407+FlorianMichael@users.noreply.github.com>
Date: Thu, 2 Nov 2023 08:46:06 +0100
Subject: [PATCH] Delete integration package, inline methods
---
.../MixinCCAuthenticationResponse.java | 12 +++-
.../integration/Classic4JImpl.java | 57 -------------------
.../ViaFabricPlusClassicMPPassProvider.java | 17 ++++--
.../classicube/ClassiCubeMFAScreen.java | 4 +-
.../settings}/ModMenuImpl.java | 3 +-
src/main/resources/fabric.mod.json | 2 +-
6 files changed, 26 insertions(+), 69 deletions(-)
delete mode 100644 src/main/java/de/florianmichael/viafabricplus/integration/Classic4JImpl.java
rename src/main/java/de/florianmichael/viafabricplus/{integration => screen/settings}/ModMenuImpl.java (90%)
diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/classic4j/MixinCCAuthenticationResponse.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/classic4j/MixinCCAuthenticationResponse.java
index fe40ace4..0026386d 100644
--- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/classic4j/MixinCCAuthenticationResponse.java
+++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/classic4j/MixinCCAuthenticationResponse.java
@@ -19,7 +19,7 @@ package de.florianmichael.viafabricplus.injection.mixin.classic4j;
import de.florianmichael.classic4j.model.classicube.CCAuthenticationResponse;
import de.florianmichael.classic4j.model.classicube.CCError;
-import de.florianmichael.viafabricplus.integration.Classic4JImpl;
+import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@@ -29,6 +29,14 @@ public class MixinCCAuthenticationResponse {
@Redirect(method = "getErrorDisplay", at = @At(value = "FIELD", target = "Lde/florianmichael/classic4j/model/classicube/CCError;description:Ljava/lang/String;"))
public String mapTranslations(CCError instance) {
- return Classic4JImpl.fromError(instance).getString();
+ switch (instance) {
+ case TOKEN -> Text.translatable("classicube.viafabricplus.error.token").getString();
+ case USERNAME -> Text.translatable("classicube.viafabricplus.error.username").getString();
+ case PASSWORD -> Text.translatable("classicube.viafabricplus.error.password").getString();
+ case VERIFICATION -> Text.translatable("classicube.viafabricplus.error.verification").getString();
+ case LOGIN_CODE -> Text.translatable("classicube.viafabricplus.error.logincode").getString();
+ }
+
+ return instance.description;
}
}
diff --git a/src/main/java/de/florianmichael/viafabricplus/integration/Classic4JImpl.java b/src/main/java/de/florianmichael/viafabricplus/integration/Classic4JImpl.java
deleted file mode 100644
index 877bf409..00000000
--- a/src/main/java/de/florianmichael/viafabricplus/integration/Classic4JImpl.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
- * Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-package de.florianmichael.viafabricplus.integration;
-
-import com.mojang.authlib.exceptions.AuthenticationException;
-import de.florianmichael.classic4j.api.JoinServerInterface;
-import de.florianmichael.classic4j.model.classicube.CCError;
-import net.minecraft.client.MinecraftClient;
-import net.minecraft.text.Text;
-
-public class Classic4JImpl {
- public final static JoinServerInterface JOIN_SERVER_CALL = serverId -> {
- final MinecraftClient mc = MinecraftClient.getInstance();
-
- try {
- mc.getSessionService().joinServer(mc.getSession().getUuidOrNull(), mc.getSession().getAccessToken(), serverId);
- } catch (AuthenticationException e) {
- e.printStackTrace();
- }
- };
-
- public static Text fromError(final CCError error) {
- switch (error) {
- case TOKEN -> {
- return Text.translatable("classicube.viafabricplus.error.token");
- }
- case USERNAME -> {
- return Text.translatable("classicube.viafabricplus.error.username");
- }
- case PASSWORD -> {
- return Text.translatable("classicube.viafabricplus.error.password");
- }
- case VERIFICATION -> {
- return Text.translatable("classicube.viafabricplus.error.verification");
- }
- case LOGIN_CODE -> {
- return Text.translatable("classicube.viafabricplus.error.logincode");
- }
- }
- return Text.empty();
- }
-}
diff --git a/src/main/java/de/florianmichael/viafabricplus/protocolhack/provider/vialegacy/ViaFabricPlusClassicMPPassProvider.java b/src/main/java/de/florianmichael/viafabricplus/protocolhack/provider/vialegacy/ViaFabricPlusClassicMPPassProvider.java
index 678e0f6f..4046bbc3 100644
--- a/src/main/java/de/florianmichael/viafabricplus/protocolhack/provider/vialegacy/ViaFabricPlusClassicMPPassProvider.java
+++ b/src/main/java/de/florianmichael/viafabricplus/protocolhack/provider/vialegacy/ViaFabricPlusClassicMPPassProvider.java
@@ -17,11 +17,12 @@
*/
package de.florianmichael.viafabricplus.protocolhack.provider.vialegacy;
+import com.mojang.authlib.exceptions.AuthenticationException;
import com.viaversion.viaversion.api.connection.UserConnection;
import de.florianmichael.classic4j.BetaCraftHandler;
import de.florianmichael.viafabricplus.ViaFabricPlus;
-import de.florianmichael.viafabricplus.integration.Classic4JImpl;
import de.florianmichael.viafabricplus.settings.impl.AuthenticationSettings;
+import net.minecraft.client.MinecraftClient;
import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.providers.ClassicMPPassProvider;
import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.storage.HandshakeStorage;
@@ -35,12 +36,20 @@ public class ViaFabricPlusClassicMPPassProvider extends ClassicMPPassProvider {
}
if (AuthenticationSettings.INSTANCE.useBetaCraftAuthentication.getValue()) {
- final HandshakeStorage handshakeStorage = user.get(HandshakeStorage.class);
+ final var handshakeStorage = user.get(HandshakeStorage.class);
if (handshakeStorage == null) {
return super.getMpPass(user);
}
- return BetaCraftHandler.requestMPPass(user.getProtocolInfo().getUsername(), handshakeStorage.getHostname(), handshakeStorage.getPort(), Classic4JImpl.JOIN_SERVER_CALL, throwable ->
- ViaFabricPlus.LOGGER.error("Error occurred while requesting the MP-Pass to verify session", throwable));
+
+ return BetaCraftHandler.requestMPPass(user.getProtocolInfo().getUsername(), handshakeStorage.getHostname(), handshakeStorage.getPort(), serverId -> {
+ final var mc = MinecraftClient.getInstance();
+
+ try {
+ mc.getSessionService().joinServer(mc.getSession().getUuidOrNull(), mc.getSession().getAccessToken(), serverId);
+ } catch (AuthenticationException e) {
+ ViaFabricPlus.LOGGER.error("Error occurred while verifying session", e);
+ }
+ }, throwable -> ViaFabricPlus.LOGGER.error("Error occurred while requesting the MP-Pass to verify session", throwable));
} else {
return super.getMpPass(user);
}
diff --git a/src/main/java/de/florianmichael/viafabricplus/screen/classic4j/classicube/ClassiCubeMFAScreen.java b/src/main/java/de/florianmichael/viafabricplus/screen/classic4j/classicube/ClassiCubeMFAScreen.java
index 6c7f3323..91d084e6 100644
--- a/src/main/java/de/florianmichael/viafabricplus/screen/classic4j/classicube/ClassiCubeMFAScreen.java
+++ b/src/main/java/de/florianmichael/viafabricplus/screen/classic4j/classicube/ClassiCubeMFAScreen.java
@@ -20,11 +20,9 @@ package de.florianmichael.viafabricplus.screen.classic4j.classicube;
import com.mojang.blaze3d.systems.RenderSystem;
import de.florianmichael.classic4j.ClassiCubeHandler;
import de.florianmichael.classic4j.api.LoginProcessHandler;
-import de.florianmichael.classic4j.model.classicube.CCError;
import de.florianmichael.classic4j.model.classicube.account.CCAccount;
import de.florianmichael.viafabricplus.screen.VFPScreen;
import de.florianmichael.viafabricplus.definition.account.ClassiCubeAccountHandler;
-import de.florianmichael.viafabricplus.integration.Classic4JImpl;
import de.florianmichael.viafabricplus.screen.common.ProtocolSelectionScreen;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
@@ -41,7 +39,7 @@ public class ClassiCubeMFAScreen extends VFPScreen {
@Override
public void open(Screen prevScreen) {
- this.setupSubtitle(Classic4JImpl.fromError(CCError.LOGIN_CODE));
+ this.setupSubtitle(Text.translatable("classicube.viafabricplus.error.logincode"));
super.open(prevScreen);
}
diff --git a/src/main/java/de/florianmichael/viafabricplus/integration/ModMenuImpl.java b/src/main/java/de/florianmichael/viafabricplus/screen/settings/ModMenuImpl.java
similarity index 90%
rename from src/main/java/de/florianmichael/viafabricplus/integration/ModMenuImpl.java
rename to src/main/java/de/florianmichael/viafabricplus/screen/settings/ModMenuImpl.java
index b1cba204..53685daf 100644
--- a/src/main/java/de/florianmichael/viafabricplus/integration/ModMenuImpl.java
+++ b/src/main/java/de/florianmichael/viafabricplus/screen/settings/ModMenuImpl.java
@@ -15,11 +15,10 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-package de.florianmichael.viafabricplus.integration;
+package de.florianmichael.viafabricplus.screen.settings;
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
import com.terraformersmc.modmenu.api.ModMenuApi;
-import de.florianmichael.viafabricplus.screen.settings.SettingsScreen;
public class ModMenuImpl implements ModMenuApi {
diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json
index aa1b9ef6..e8f2c140 100644
--- a/src/main/resources/fabric.mod.json
+++ b/src/main/resources/fabric.mod.json
@@ -25,7 +25,7 @@
"environment": "client",
"entrypoints": {
"modmenu": [
- "de.florianmichael.viafabricplus.integration.ModMenuImpl"
+ "de.florianmichael.viafabricplus.screen.settings.ModMenuImpl"
]
},
"mixins": [