Delete integration package, inline methods

This commit is contained in:
FlorianMichael 2023-11-02 08:46:06 +01:00
parent adddcca7ce
commit 07a0001ab4
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
6 changed files with 26 additions and 69 deletions

View File

@ -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;
}
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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();
}
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -15,11 +15,10 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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 {

View File

@ -25,7 +25,7 @@
"environment": "client",
"entrypoints": {
"modmenu": [
"de.florianmichael.viafabricplus.integration.ModMenuImpl"
"de.florianmichael.viafabricplus.screen.settings.ModMenuImpl"
]
},
"mixins": [