Skip to content

Commit

Permalink
fixed discord rpc and added large images for all hypixel minigames
Browse files Browse the repository at this point in the history
  • Loading branch information
PepperLola committed Apr 10, 2021
1 parent 5946a49 commit 5cefe98
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 27 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ sourceSets {
main.resources.srcDirs += '../shared/main/resources'
}

version = "1.17.2"
version = "1.17.3"
group= "com.palight.playerinfo" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "playerinfo"

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/palight/playerinfo/PlayerInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class PlayerInfo
//TODO update version here and in build.gradle
public static final String NAME = "playerinfo";
public static final String MODID = "playerinfo";
public static final String VERSION = "1.17.2";
public static final String VERSION = "1.17.3";
public static String commitHash;
public static String defaultBranchName = "master";
public static String githubAPIURL = "https://api.github.com/repos/PepperLola/playerinfo/git/refs/heads/" + defaultBranchName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.palight.playerinfo.util.MCUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiMainMenu;
import net.minecraft.client.gui.GuiMultiplayer;
import net.minecraft.client.gui.GuiScreenServerList;
import net.minecraftforge.client.event.GuiScreenEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
Expand All @@ -21,24 +22,6 @@
import net.minecraftforge.fml.relauncher.SideOnly;

public class DiscordRichPresenceMod extends Module {
public DiscordRichPresenceMod() {
super("discordPresence", "Discord RPC", "Enabled Discord Rich Presence", ModuleType.MISC, null, null);
if (this.enabled) {
/* Discord Rich Presence */
client = new IPCClient(applicationId);
client.setListener(new IPCListener() {
@Override
public void onReady(IPCClient client) {
updateDiscord();
}
});
try {
client.connect();
} catch (NoDiscordClientException e) {
e.printStackTrace();
}
}
}

@ConfigOption
public String hypixelApiKey = "";
Expand All @@ -51,13 +34,37 @@ public void onReady(IPCClient client) {
int updateTicks = 0;
private static IPCClient client;

public DiscordRichPresenceMod() {
super("discordRPC", "Discord RPC", "Enabled Discord Rich Presence", ModuleType.MISC, null, null);
}

public static void updateDiscord() {
if (PlayerInfo.getModules().get("discordRPC").isEnabled()) {
boolean enabled = PlayerInfo.getModules().get("discordRPC").isEnabled();
if (client == null) {
if (enabled) {
/* Discord Rich Presence */
client = new IPCClient(applicationId);
client.setListener(new IPCListener() {
@Override
public void onReady(IPCClient client) {
updateDiscord();
}
});
try {
client.connect();
} catch (NoDiscordClientException e) {
e.printStackTrace();
}
}
}
if (enabled) {
new Thread(() -> {
System.out.println("DISCORD STATE: " + DiscordState.getDisplayString(discordState));
String currentGame = serverIp.contains("hypixel") ? MCUtil.getPlayerStatus().toLowerCase().replaceAll(" ", "_") : "hypixel";
System.out.println("CURRENT GAME: " + currentGame);
RichPresence.Builder builder = new RichPresence.Builder();
builder.setState(DiscordState.getDisplayString(discordState))
.setLargeImage("minecraft", Minecraft.getMinecraft().getSession().getUsername())
.setLargeImage(serverIp.contains("hypixel") ? currentGame : "minecraft", Minecraft.getMinecraft().getSession().getUsername())
.setSmallImage("playerinfo", PlayerInfo.MODID + " v" + PlayerInfo.VERSION);
client.sendRichPresence(builder.build());
}).start();
Expand All @@ -72,14 +79,16 @@ public void setDiscordState(DiscordState state) {
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void onInitGui(GuiScreenEvent.InitGuiEvent.Pre event) {
if (event.gui instanceof GuiMainMenu || event.gui instanceof CustomMainMenuGui || event.gui instanceof GuiScreenServerList) {
if (event.gui instanceof GuiMainMenu || event.gui instanceof CustomMainMenuGui || event.gui instanceof GuiScreenServerList || event.gui instanceof GuiMultiplayer) {
setDiscordState(DiscordState.MAIN_MENU);
serverIp = "";
}
}

@SubscribeEvent
public void clientTickEvent(TickEvent.ClientTickEvent event) {
if (updateTicks >= updateTicksMax) {
setDiscordState(Minecraft.getMinecraft().theWorld != null && Minecraft.getMinecraft().theWorld.isRemote ? DiscordState.MULTIPLAYER : DiscordState.SINGLEPLAYER);
updateDiscord();
updateTicks = 0;
}
Expand All @@ -89,14 +98,16 @@ public void clientTickEvent(TickEvent.ClientTickEvent event) {

@SubscribeEvent
public void onServerJoin(ServerJoinEvent event) {
System.out.println(String.format("CONNECTED TO: %s", event.getServer()));
System.out.printf("CONNECTED TO: %s%n", event.getServer());
setDiscordState(DiscordState.MULTIPLAYER);
serverIp = event.getServer();
updateDiscord();
}

@SubscribeEvent
public void onScoreboardUpdate(ScoreboardTitleChangeEvent event) {
if (serverIp.contains("hypixel.net")) {
if (serverIp.contains("hypixel")) {
setDiscordState(DiscordState.MULTIPLAYER);
updateDiscord();
}
}
Expand All @@ -113,7 +124,7 @@ public static String getDisplayString(DiscordState state) {
case SINGLEPLAYER:
return "In a singleplayer world";
case MULTIPLAYER:
if (serverIp.contains("hypixel.net") && !((DiscordRichPresenceMod) PlayerInfo.getModules().get("discordRPC")).hypixelApiKey.equals("")) {
if (serverIp.contains("hypixel") && !((DiscordRichPresenceMod) PlayerInfo.getModules().get("discordRPC")).hypixelApiKey.equals("")) {
return "Playing " + MCUtil.getPlayerStatus() + " on Hypixel";
}
return "Playing on " + serverIp;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/palight/playerinfo/util/NumberUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public class NumberUtil {
}

public static String integerToRoman(int number) {
System.out.println("TO ROMAN: " + number);
if (number <= 0) return "";
int l = treemap.floorKey(number);
if (number == l) {
Expand Down

0 comments on commit 5cefe98

Please sign in to comment.