diff --git a/src/main/java/de/florianmichael/viafabricplus/screen/VFPScreen.java b/src/main/java/de/florianmichael/viafabricplus/screen/VFPScreen.java index 62a76b83..95a2d1ec 100644 --- a/src/main/java/de/florianmichael/viafabricplus/screen/VFPScreen.java +++ b/src/main/java/de/florianmichael/viafabricplus/screen/VFPScreen.java @@ -169,18 +169,13 @@ public class VFPScreen extends Screen { * * @param title The title of the error screen * @param throwable The throwable which should be thrown + * @param next The screen which should be opened after the error screen is closed */ - public static void showErrorScreen(final String title, final Throwable throwable, final Screen parent) { - final MinecraftClient client = MinecraftClient.getInstance(); - - client.execute(() -> client.setScreen(new NoticeScreen( - () -> client.setScreen(parent), - Text.of(title), - Text.translatable("base.viafabricplus.something_went_wrong").append("\n" + throwable.getMessage()), Text.translatable("base.viafabricplus.cancel"), - false) - )); - + public static void showErrorScreen(final String title, final Throwable throwable, final Screen next) { ViaFabricPlus.global().getLogger().error("Something went wrong!", throwable); + + final MinecraftClient client = MinecraftClient.getInstance(); + client.execute(() -> client.setScreen(new NoticeScreen(() -> client.setScreen(next), Text.of(title), Text.translatable("base.viafabricplus.something_went_wrong").append("\n" + throwable.getMessage()), Text.translatable("base.viafabricplus.cancel"), false))); } } diff --git a/src/main/java/de/florianmichael/viafabricplus/settings/impl/AuthenticationSettings.java b/src/main/java/de/florianmichael/viafabricplus/settings/impl/AuthenticationSettings.java index 23e76231..4fdf5a4d 100644 --- a/src/main/java/de/florianmichael/viafabricplus/settings/impl/AuthenticationSettings.java +++ b/src/main/java/de/florianmichael/viafabricplus/settings/impl/AuthenticationSettings.java @@ -25,7 +25,7 @@ import net.minecraft.text.Text; public class AuthenticationSettings extends SettingGroup { - private static final AuthenticationSettings instance = new AuthenticationSettings(); + private static final AuthenticationSettings INSTANCE = new AuthenticationSettings(); public final BooleanSetting useBetaCraftAuthentication = new BooleanSetting(this, Text.translatable("authentication_settings.viafabricplus.use_beta_craft_authentication"), true); public final BooleanSetting verifySessionForOnlineModeServers = new BooleanSetting(this, Text.translatable("authentication_settings.viafabricplus.verify_session_for_online_mode"), true); @@ -37,7 +37,7 @@ public class AuthenticationSettings extends SettingGroup { } public static AuthenticationSettings global() { - return instance; + return INSTANCE; } } diff --git a/src/main/java/de/florianmichael/viafabricplus/settings/impl/BedrockSettings.java b/src/main/java/de/florianmichael/viafabricplus/settings/impl/BedrockSettings.java index d4e92e75..c8cf776e 100644 --- a/src/main/java/de/florianmichael/viafabricplus/settings/impl/BedrockSettings.java +++ b/src/main/java/de/florianmichael/viafabricplus/settings/impl/BedrockSettings.java @@ -27,6 +27,7 @@ import de.florianmichael.viafabricplus.settings.base.ButtonSetting; import de.florianmichael.viafabricplus.settings.base.SettingGroup; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.NoticeScreen; +import net.minecraft.client.gui.screen.Screen; import net.minecraft.text.MutableText; import net.minecraft.text.Text; import net.minecraft.util.Util; @@ -39,16 +40,18 @@ import java.util.concurrent.CompletableFuture; public class BedrockSettings extends SettingGroup { - private static final BedrockSettings instance = new BedrockSettings(); + private static final BedrockSettings INSTANCE = new BedrockSettings(); - public final ButtonSetting _1 = new ButtonSetting(this, Text.translatable("bedrock_settings.viafabricplus.click_to_set_bedrock_account"), () -> CompletableFuture.runAsync(this::openBedrockAccountLogin)) { + private final ButtonSetting ignored = new ButtonSetting(this, Text.translatable("bedrock_settings.viafabricplus.click_to_set_bedrock_account"), () -> CompletableFuture.runAsync(this::openBedrockAccountLogin)) { @Override public MutableText displayValue() { final var account = ViaFabricPlus.global().getSaveManager().getAccountsSave().getBedrockAccount(); - if (account == null) return super.displayValue(); - - return Text.literal("Bedrock account: " + account.getMcChain().getDisplayName()); + if (account != null) { + return Text.literal("Bedrock account: " + account.getMcChain().getDisplayName()); + } else { + return super.displayValue(); + } } }; public final BooleanSetting openPromptGUIToConfirmTransfer = new BooleanSetting(this, Text.translatable("bedrock_settings.viafabricplus.confirm_transfer_server_prompt"), true); @@ -58,11 +61,12 @@ public class BedrockSettings extends SettingGroup { } private void openBedrockAccountLogin() { - final var prevScreen = MinecraftClient.getInstance().currentScreen; + final MinecraftClient client = MinecraftClient.getInstance(); + final Screen prevScreen = client.currentScreen; try { ViaFabricPlus.global().getSaveManager().getAccountsSave().setBedrockAccount(MinecraftAuth.BEDROCK_DEVICE_CODE_LOGIN.getFromInput(MinecraftAuth.createHttpClient(), new StepMsaDeviceCode.MsaDeviceCodeCallback(msaDeviceCode -> { - MinecraftClient.getInstance().execute(() -> MinecraftClient.getInstance().setScreen(new NoticeScreen(() -> { - MinecraftClient.getInstance().setScreen(prevScreen); + client.execute(() -> client.setScreen(new NoticeScreen(() -> { + client.setScreen(prevScreen); Thread.currentThread().interrupt(); }, Text.literal("Microsoft Bedrock login"), Text.translatable("bedrock.viafabricplus.login"), Text.translatable("base.viafabricplus.cancel"), true))); try { @@ -73,7 +77,7 @@ public class BedrockSettings extends SettingGroup { } }))); - RenderSystem.recordRenderCall(() -> MinecraftClient.getInstance().setScreen(prevScreen)); + RenderSystem.recordRenderCall(() -> client.setScreen(prevScreen)); } catch (Throwable e) { Thread.currentThread().interrupt(); VFPScreen.showErrorScreen("Microsoft Bedrock Login", e, prevScreen); @@ -81,7 +85,7 @@ public class BedrockSettings extends SettingGroup { } public static BedrockSettings global() { - return instance; + return INSTANCE; } } diff --git a/src/main/java/de/florianmichael/viafabricplus/settings/impl/DebugSettings.java b/src/main/java/de/florianmichael/viafabricplus/settings/impl/DebugSettings.java index 85e27ff5..0aec046f 100644 --- a/src/main/java/de/florianmichael/viafabricplus/settings/impl/DebugSettings.java +++ b/src/main/java/de/florianmichael/viafabricplus/settings/impl/DebugSettings.java @@ -28,7 +28,7 @@ import net.raphimc.vialoader.util.VersionRange; public class DebugSettings extends SettingGroup { - private static final DebugSettings instance = new DebugSettings(); + private static final DebugSettings INSTANCE = new DebugSettings(); public final BooleanSetting queueConfigPackets = new BooleanSetting(this, Text.translatable("debug_settings.viafabricplus.queue_config_packets"), true); @@ -63,7 +63,7 @@ public class DebugSettings extends SettingGroup { } public static DebugSettings global() { - return instance; + return INSTANCE; } } diff --git a/src/main/java/de/florianmichael/viafabricplus/settings/impl/GeneralSettings.java b/src/main/java/de/florianmichael/viafabricplus/settings/impl/GeneralSettings.java index 3265d677..3b7b05c7 100644 --- a/src/main/java/de/florianmichael/viafabricplus/settings/impl/GeneralSettings.java +++ b/src/main/java/de/florianmichael/viafabricplus/settings/impl/GeneralSettings.java @@ -27,7 +27,7 @@ import net.minecraft.text.Text; public class GeneralSettings extends SettingGroup { - private static final GeneralSettings instance = new GeneralSettings(); + private static final GeneralSettings INSTANCE = new GeneralSettings(); public final ModeSetting multiplayerScreenButtonOrientation = new ModeSetting(this, Text.translatable("general_settings.viafabricplus.multiplayer_screen_button_orientation"), 1, Text.translatable("base.viafabricplus.left_top"), @@ -63,10 +63,6 @@ public class GeneralSettings extends SettingGroup { emulateInventoryActionsInAlphaVersions.setTooltip(Text.translatable("base.viafabricplus.this_will_require_a_restart")); } - public static GeneralSettings global() { - return instance; - } - public static ButtonWidget.Builder withOrientation(final ButtonWidget.Builder builder, final int orientationIndex, final int width, final int height) { return switch (orientationIndex) { case 0 -> builder.position(5, 5); @@ -77,4 +73,8 @@ public class GeneralSettings extends SettingGroup { }; } + public static GeneralSettings global() { + return INSTANCE; + } + } diff --git a/src/main/java/de/florianmichael/viafabricplus/settings/impl/VisualSettings.java b/src/main/java/de/florianmichael/viafabricplus/settings/impl/VisualSettings.java index 1eab804e..02aefeb4 100644 --- a/src/main/java/de/florianmichael/viafabricplus/settings/impl/VisualSettings.java +++ b/src/main/java/de/florianmichael/viafabricplus/settings/impl/VisualSettings.java @@ -27,7 +27,7 @@ import net.raphimc.vialoader.util.VersionRange; public class VisualSettings extends SettingGroup { - private static final VisualSettings instance = new VisualSettings(); + private static final VisualSettings INSTANCE = new VisualSettings(); // 1.20.3 -> 1.20.2 and 1.16 -> 1.15.2 public final VersionedBooleanSetting removeNewerFeaturesFromJigsawScreen = new VersionedBooleanSetting(this, Text.translatable("visual_settings.viafabricplus.remove_newer_features_from_jigsaw_screen"), VersionRange.andOlder(VersionEnum.r1_20_2)); @@ -66,7 +66,7 @@ public class VisualSettings extends SettingGroup { } public static VisualSettings global() { - return instance; + return INSTANCE; } }