diff --git a/src/main/java/com/tttsaurus/ingameinfo/IgiConfig.java b/src/main/java/com/tttsaurus/ingameinfo/IgiConfig.java index c0b2fbb..3575db0 100644 --- a/src/main/java/com/tttsaurus/ingameinfo/IgiConfig.java +++ b/src/main/java/com/tttsaurus/ingameinfo/IgiConfig.java @@ -6,6 +6,7 @@ public class IgiConfig { public static String SPOTIFY_CLIENT_ID; public static String SPOTIFY_CLIENT_SECRET; + public static boolean SPOTIFY_AUTO_DISPLAY; public static Configuration CONFIG; @@ -17,6 +18,7 @@ public static void loadConfig() SPOTIFY_CLIENT_ID = CONFIG.getString("Spotify Client Id", "spotify", "", "Input client id of your spotify app \nDeclaration: this mod doesn't record or share your client id \nand it's not recommended for you to share your client id \nGuide: you have to create a spotify app to get client id & secrete \nhttps://developer.spotify.com/documentation/web-api/concepts/apps \nRedirect URI should be set to http://localhost:8888 for this mod to listen"); SPOTIFY_CLIENT_SECRET = CONFIG.getString("Spotify Client Secret", "spotify", "", "Input client secret of your spotify app \nDeclaration: this mod doesn't record or share your client secret \nand it's not recommended for you to share your client secret"); + SPOTIFY_AUTO_DISPLAY = CONFIG.getBoolean("Try Auto Display Overlay", "spotify", true, "Whether to try displaying the overlay when the game starts \nMay fail due to token/auth issues"); } catch (Exception ignored) { } finally diff --git a/src/main/java/com/tttsaurus/ingameinfo/common/impl/appcommunication/spotify/SpotifyCommandHandler.java b/src/main/java/com/tttsaurus/ingameinfo/common/impl/appcommunication/spotify/SpotifyCommandHandler.java index 226dae6..b0df4f3 100644 --- a/src/main/java/com/tttsaurus/ingameinfo/common/impl/appcommunication/spotify/SpotifyCommandHandler.java +++ b/src/main/java/com/tttsaurus/ingameinfo/common/impl/appcommunication/spotify/SpotifyCommandHandler.java @@ -71,18 +71,7 @@ else if (message.startsWith("#spotify-gui")) { player.sendMessage(new TextComponentString(TextFormatting.DARK_PURPLE + message)); boolean flag = param.equals("true"); - if (flag) - { - if (SpotifyUserInfo.token.accessToken.isEmpty()) - { - player.sendMessage(new TextComponentString(TextFormatting.AQUA + "[SpotifyBot]" + TextFormatting.RESET + " The access token is empty.")); - player.sendMessage(new TextComponentString(TextFormatting.AQUA + "[SpotifyBot]" + TextFormatting.RESET + " Please run the command #spotify-oauth first.")); - return; - } - EventCenter.spotifyOverlayEvent.trigger(true); - } - else - EventCenter.spotifyOverlayEvent.trigger(false); + EventCenter.spotifyOverlayEvent.trigger(flag); } } } diff --git a/src/main/java/com/tttsaurus/ingameinfo/common/impl/appcommunication/spotify/SpotifyViewModel.java b/src/main/java/com/tttsaurus/ingameinfo/common/impl/appcommunication/spotify/SpotifyViewModel.java index 42f0f37..e9b3125 100644 --- a/src/main/java/com/tttsaurus/ingameinfo/common/impl/appcommunication/spotify/SpotifyViewModel.java +++ b/src/main/java/com/tttsaurus/ingameinfo/common/impl/appcommunication/spotify/SpotifyViewModel.java @@ -1,5 +1,6 @@ package com.tttsaurus.ingameinfo.common.impl.appcommunication.spotify; +import com.tttsaurus.ingameinfo.IgiConfig; import com.tttsaurus.ingameinfo.common.api.appcommunication.spotify.SpotifyAccessUtils; import com.tttsaurus.ingameinfo.common.api.appcommunication.spotify.SpotifyOAuthUtils; import com.tttsaurus.ingameinfo.common.api.appcommunication.spotify.SpotifyUserInfo; @@ -8,6 +9,10 @@ import com.tttsaurus.ingameinfo.common.api.mvvm.binding.ReactiveObject; import com.tttsaurus.ingameinfo.common.api.mvvm.viewmodel.ViewModel; import com.tttsaurus.ingameinfo.common.impl.igievent.EventCenter; +import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.util.text.TextComponentString; +import net.minecraft.util.text.TextFormatting; import java.io.File; import java.io.RandomAccessFile; import java.time.Duration; @@ -110,6 +115,17 @@ public void start() { if (flag) { + if (SpotifyUserInfo.token.accessToken.isEmpty()) + { + EntityPlayerSP player = Minecraft.getMinecraft().player; + if (player != null) + { + player.sendMessage(new TextComponentString(TextFormatting.AQUA + "[SpotifyBot]" + TextFormatting.RESET + " The access token is empty.")); + player.sendMessage(new TextComponentString(TextFormatting.AQUA + "[SpotifyBot]" + TextFormatting.RESET + " Please run the command #spotify-oauth first.")); + } + return; + } + activeSetter.invoke(true); trackTitleText.set("Please wait..."); @@ -177,6 +193,8 @@ public void start() SpotifyUserInfo.userName = SpotifyAccessUtils.getUserName(SpotifyUserInfo.token.accessToken); } catch (Exception ignored) { } + if (IgiConfig.SPOTIFY_AUTO_DISPLAY) + EventCenter.spotifyOverlayEvent.trigger(true); } return null; });