Skip to content

Commit

Permalink
Version 1.2.3 - Fix Spotify + More
Browse files Browse the repository at this point in the history
  • Loading branch information
conorthedev committed Jul 11, 2020
1 parent 3bd36d1 commit 354b7ac
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 21 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ buildscript {

apply plugin: 'net.minecraftforge.gradle.forge'

version = "1.2.2"
version = "1.2.3"
group = "me.conorthedev" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "MediaMod"

Expand Down
26 changes: 21 additions & 5 deletions src/main/java/dev/conorthedev/mediamod/MediaMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
import dev.conorthedev.mediamod.media.browser.BrowserHandler;
import dev.conorthedev.mediamod.media.spotify.SpotifyHandler;
import dev.conorthedev.mediamod.parties.PartyManager;
import dev.conorthedev.mediamod.util.Metadata;
import dev.conorthedev.mediamod.util.PlayerMessager;
import dev.conorthedev.mediamod.util.VersionChecker;
import dev.conorthedev.mediamod.util.*;
import net.minecraft.client.Minecraft;
import net.minecraftforge.client.ClientCommandHandler;
import net.minecraftforge.common.MinecraftForge;
Expand All @@ -29,6 +27,10 @@
import java.io.File;
import java.io.IOException;

class ClientIDResponse {
String clientID;
}

/**
* The main class for MediaMod
*
Expand All @@ -40,7 +42,7 @@ public class MediaMod {
/**
* The API Endpoint for MediaMod requests
*/
public static final String ENDPOINT = "http://localhost:3000/";
public static final String ENDPOINT = "https://mediamodapi.cbyrne.dev/";

/**
* An instance of this class to access non-static methods from other classes
Expand Down Expand Up @@ -70,6 +72,11 @@ public class MediaMod {
*/
public final PartyManager partyManager = new PartyManager();

/**
* The client ID used for Spotify Requests
*/
public String spotifyClientID;

private boolean firstLoad = true;

/**
Expand Down Expand Up @@ -126,7 +133,16 @@ public void init(FMLInitializationEvent event) {
try {
this.coreMod.register();
} catch (IOException e) {
LOGGER.warn("Failed to register with analytics! " + e.getMessage());
LOGGER.warn("Failed to register with analytics! " + e.getLocalizedMessage());
}

try {
ClientIDResponse clientIDResponse = WebRequest.requestToMediaMod(WebRequestType.GET, "clientID", ClientIDResponse.class);
if(clientIDResponse != null) {
spotifyClientID = clientIDResponse.clientID;
}
} catch (IOException e) {
LOGGER.warn("Failed to get Spotify Client ID: " + e.getLocalizedMessage());
}

LOGGER.info("Loading Configuration...");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
package dev.conorthedev.mediamod.command;

import dev.conorthedev.mediamod.MediaMod;
import dev.conorthedev.mediamod.gui.GuiMediaModSettings;
import dev.conorthedev.mediamod.util.ChatColor;
import dev.conorthedev.mediamod.util.PlayerMessager;
import dev.conorthedev.mediamod.util.TickScheduler;
import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender;
import net.minecraft.event.ClickEvent;
import net.minecraft.event.HoverEvent;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.IChatComponent;
import net.minecraftforge.fml.client.FMLClientHandler;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -39,6 +32,8 @@ public List<String> getCommandAliases() {

@Override
public void processCommand(ICommandSender sender, String[] args) {
TickScheduler.INSTANCE.schedule(1, () -> FMLClientHandler.instance().getClient().displayGuiScreen(new GuiMediaModSettings()));
/*
if(args.length <= 0) {
TickScheduler.INSTANCE.schedule(1, () -> FMLClientHandler.instance().getClient().displayGuiScreen(new GuiMediaModSettings()));
} else {
Expand Down Expand Up @@ -80,6 +75,7 @@ public void processCommand(ICommandSender sender, String[] args) {
}
}
}
*/
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import net.minecraft.util.IChatComponent;
import net.minecraftforge.fml.client.FMLClientHandler;

import javax.print.attribute.standard.Media;
import java.awt.*;
import java.io.IOException;
import java.io.OutputStream;
Expand Down Expand Up @@ -48,6 +49,7 @@ private static void handleRequest(String code) {
PlayerMessager.sendMessage("&7Exchanging authorization code for access token, this may take a moment...");
try {
TokenAPIResponse tokenAPIResponse = WebRequest.requestToMediaModAPI(WebRequestType.GET, "spotify/getToken?code=" + code, TokenAPIResponse.class);

if (tokenAPIResponse == null) {
MediaMod.INSTANCE.LOGGER.error("Error: tokenAPIResponse is null");
PlayerMessager.sendMessage("&c&lERROR: &rFailed to login to Spotify!");
Expand All @@ -66,6 +68,8 @@ private static void handleRequest(String code) {
if (MediaMod.INSTANCE.DEVELOPMENT_ENVIRONMENT && currentTrack != null) {
PlayerMessager.sendMessage("&8&lDEBUG: &rCurrent Song: " + currentTrack.item.name + " by " + currentTrack.item.album.artists[0].name);
}
} else {
PlayerMessager.sendMessage("&c&lERROR: &rFailed to login to Spotify! | Refresh token was null!");
}
} catch (Exception e) {
logged = false;
Expand All @@ -88,7 +92,7 @@ private void attemptToOpenAuthURL() {
}

Desktop desktop = Desktop.getDesktop();
String spotifyUrl = "https://accounts.spotify.com/authorize?client_id=2892e1e967084cc2b9cbba8fb90c7e56&response_type=code&redirect_uri=http%3A%2F%2Flocalhost:9103%2Fcallback%2F&scope=user-read-playback-state%20user-read-currently-playing%20user-modify-playback-state&state=34fFs29kd09";
String spotifyUrl = "https://accounts.spotify.com/authorize?client_id=" + MediaMod.INSTANCE.spotifyClientID + "&response_type=code&redirect_uri=http%3A%2F%2Flocalhost:9103%2Fcallback%2F&scope=user-read-playback-state%20user-read-currently-playing%20user-modify-playback-state&state=34fFs29kd09";
try {
desktop.browse(new URI(spotifyUrl));
} catch (URISyntaxException e) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/dev/conorthedev/mediamod/util/Metadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
public class Metadata {
public static final String NAME = "MediaMod";
public static final String MODID = "mediamod";
public static final String VERSION = "1.2.2";
public static final int VERSION_INT = 6;
public static final String VERSION = "1.2.3";
public static final int VERSION_INT = 7;
}
35 changes: 35 additions & 0 deletions src/main/java/dev/conorthedev/mediamod/util/WebRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,41 @@
import java.util.stream.Collectors;

public class WebRequest {
public static <T> T requestToMediaMod(WebRequestType type, String path, Class<T> toClass) throws IOException {
URL url = new URL(MediaMod.ENDPOINT + path);

HttpURLConnection connection = null;
BufferedReader reader = null;

try {
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod(type.name());
connection.setRequestProperty("User-Agent", "MediaMod/1.0");
connection.connect();

reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String content = reader.lines().collect(Collectors.joining());

return new Gson().fromJson(content, toClass);
} catch (Exception e) {
MediaMod.INSTANCE.LOGGER.error("Failed to perform web request! Error: " + e.getMessage());
} finally {
try {
if (connection != null) {
connection.disconnect();
}

if (reader != null) {
reader.close();
}
} catch (Exception e) {
MediaMod.INSTANCE.LOGGER.error("Failed to perform web request! Error: " + e.getMessage());
}
}

return null;
}

public static <T> T requestToMediaModAPI(WebRequestType type, String path, Class<T> toClass) throws IOException {
URL url = new URL(MediaMod.ENDPOINT + "api/" + path);

Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/assets/mediamod/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ menu.guiplayersettings.buttons.customize.tooltip=Move, resize and modify element
menu.guiplayersettings.buttons.progressStyle.name=Progress Style:
menu.guiplayersettings.buttons.progressStyle.tooltip=Cycles through progress display styles

menu.guiplayersettings.buttons.position.name=Position Player
menu.guiplayersettings.buttons.position.tooltip=Change the size and position of the MediaMod HUD

menu.guiplayersettings.buttons.progressStyle.bar_and_numbers_new=Progress bar + text (new)
menu.guiplayersettings.buttons.progressStyle.bar_and_numbers_old=Progress bar + text (old)
menu.guiplayersettings.buttons.progressStyle.bar_only=Progress Bar Only
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/mcmod.info
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"modid": "mediamod",
"name": "MediaMod",
"description": "Get integration for your favourite streaming services right in Minecraft",
"version": "1.2.2",
"version": "1.2.3",
"mcversion": "1.8.9",
"url": "https://mediamod.cbyrne.dev/",
"updateUrl": "",
Expand Down
8 changes: 4 additions & 4 deletions version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"latestVersionInt": 6,
"latestVersionS": "1.2.2",
"changelog": "MediaMod v1.2.2: Fixes Spotify login Download from https://github.com/MediaModMC/MediaMod/",
"downloadURL": "https://github.com/MediaModMC/MediaMod/releases/download/1.2.2/MediaMod-1.2.2.jar"
"latestVersionInt": 7,
"latestVersionS": "1.2.3",
"changelog": "MediaMod v1.2.3: Improves Spotify reliability Download from https://github.com/MediaModMC/MediaMod/",
"downloadURL": "https://github.com/MediaModMC/MediaMod/releases/download/1.2.3/MediaMod-1.2.3.jar"
}

0 comments on commit 354b7ac

Please sign in to comment.