Skip to content

Commit

Permalink
Discord RPC
Browse files Browse the repository at this point in the history
  • Loading branch information
koxx12-dev committed Jun 23, 2021
1 parent 7fca3f6 commit ad1bd5d
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 6 deletions.
6 changes: 4 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,16 @@ minecraft {

repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
//maven { url "https://repo.spongepowered.org/repository/maven-public/" }
maven { url "https://repo.sk1er.club/repository/maven-public/" }
}

dependencies {

implementation group: 'org.json', name: 'json', version: '20210307'
implementation("gg.essential:Vigilance:123-10809-SNAPSHOT")
implementation "org.json:json:20210307"
implementation "gg.essential:Vigilance:123-10809-SNAPSHOT"
implementation 'com.github.Vatuu:discord-rpc:1.6.2'
// you may put jars on which you depend on in ./libs
// or you may define them like so..
//compile "some.group:artifact:version:classifier"
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod_id=scc
mod_name=Skyclient Cosmetics
mod_version=BETA-2
mod_version=BETA-3
mod_description=Cosmetics for the mod installer Skyclient!

org.gradle.jvmargs=-Xmx2G
10 changes: 8 additions & 2 deletions src/main/java/io/github/koxx12_dev/scc/GUI/SCCConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,23 @@ public class SCCConfig extends Vigilant {
@Property(type = PropertyType.SWITCH, name = "Hide custom tags", description = "Hides all custom tags in new messages", category = "Main", subcategory = "Tags")
public static boolean TagsHidden = false;

@Property(type = PropertyType.SWITCH, name = "Shorten custom tag", description = "Shortens all custom tags in new messages", category = "Tags", subcategory = "Main")
@Property(type = PropertyType.SWITCH, name = "Shorten custom tag", description = "Shortens all custom tags in new messages", category = "Main", subcategory = "Tags")
public static boolean ShortenTags = false;

@Property(type = PropertyType.BUTTON, name = "Reload Tags", description = "Reloads custom tags", category = "Tags", subcategory = "Main")
@Property(type = PropertyType.BUTTON, name = "Reload Tags", description = "Reloads custom tags", category = "Main", subcategory = "Tags")
private void reload() {
HTTPstuff.reloadTags();
}

@Property(type = PropertyType.SWITCH, name = "DEBUG MODE", description = "FOR DEV ONLY", category = "DEBUG", subcategory = "DEBUG",hidden = true)
public static boolean DEBUG = false;

@Property(type = PropertyType.TEXT, name = "Discord RPC text", description = "Allows you to set one line of the Discord RPC", category = "Main", subcategory = "RPC")
public static String RPCText = "SBE bad";

@Property(type = PropertyType.SWITCH, name = "Discord RPC", description = "Enables Discord RPC", category = "Main", subcategory = "RPC")
public static boolean RPC = true;

//@Property(type = PropertyType.TEXT, name = "Skyclient Cosmetics API key", description = "SCC Api key is used for every feature of this mod", category = "Main", subcategory = "Main", protectedText = true)
//public static String SCCApiKey = "";

Expand Down
9 changes: 8 additions & 1 deletion src/main/java/io/github/koxx12_dev/scc/SCC.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.github.koxx12_dev.scc.Commands.MainCommand;
import io.github.koxx12_dev.scc.GUI.SCCConfig;
import io.github.koxx12_dev.scc.Utils.HTTPstuff;
import io.github.koxx12_dev.scc.Utils.RPC;
import io.github.koxx12_dev.scc.listeners.ChatListeners;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
Expand All @@ -28,6 +29,8 @@ public class SCC {
public static final String MOD_ID = "${GRADLE_MOD_ID}";
public static final String MOD_VERSION = "${GRADLE_MOD_VERSION}";

public static boolean RPCon = false;

public static GuiScreen displayScreen;

public static List<String> HypixelRanks = new ArrayList<>();
Expand Down Expand Up @@ -59,6 +62,11 @@ public void onInit(FMLInitializationEvent event) {
config.preload();
MinecraftForge.EVENT_BUS.register(this);
MinecraftForge.EVENT_BUS.register(new ChatListeners());

RPC.INSTANCE.RPCManager();

MinecraftForge.EVENT_BUS.register(RPC.INSTANCE);

ClientCommandHandler.instance.registerCommand(new MainCommand());

}
Expand All @@ -67,7 +75,6 @@ public void onInit(FMLInitializationEvent event) {
public void onPostInit(FMLPostInitializationEvent event) {
// $USER = The username of the currently logged in user.
// Simply prints out Hello, $USER.

HTTPstuff.reloadTags();

}
Expand Down
68 changes: 68 additions & 0 deletions src/main/java/io/github/koxx12_dev/scc/Utils/RPC.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package io.github.koxx12_dev.scc.Utils;

import io.github.koxx12_dev.scc.GUI.SCCConfig;
import io.github.koxx12_dev.scc.SCC;
import net.arikia.dev.drpc.DiscordEventHandlers;
import net.arikia.dev.drpc.DiscordRPC;
import net.arikia.dev.drpc.DiscordRichPresence;
import net.minecraft.client.Minecraft;

import java.time.Instant;

public class RPC implements Runnable {

public static RPC INSTANCE = new RPC();

private Thread trd = new Thread(this);

private long timestamp = Instant.now().getEpochSecond();

public void RPCManager() {
trd.start();
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
System.out.println("Closing Discord hook.");
DiscordRPC.discordShutdown();
}));
}

public void initRPC() {

DiscordEventHandlers handlers = new DiscordEventHandlers.Builder().setReadyEventHandler((user) -> {
System.out.println("Discord user: " + user.username);
DiscordRichPresence.Builder presence = new DiscordRichPresence.Builder(SCCConfig.RPCText);
presence.setDetails(Minecraft.getMinecraft().getSession().getUsername()+" is very cool");
presence.setBigImage("skyclienticon","skyclient is very cool");
presence.setStartTimestamps(timestamp);
DiscordRPC.discordUpdatePresence(presence.build());
SCC.RPCon = true;
}).build();
DiscordRPC.discordInitialize("857240025288802356", handlers, true);
}

public void updateRPC() {

if (!SCCConfig.RPC) {
DiscordRPC.discordClearPresence();
} else {
DiscordRichPresence.Builder presence = new DiscordRichPresence.Builder(SCCConfig.RPCText);
presence.setDetails(Minecraft.getMinecraft().getSession().getUsername()+" is very cool");
presence.setBigImage("skyclienticon","skyclient is very cool");
presence.setStartTimestamps(timestamp);
DiscordRPC.discordUpdatePresence(presence.build());
}

}

@Override
public void run() {
try {
Thread.sleep(300L);
initRPC();
while(!Thread.interrupted()) {
DiscordRPC.discordRunCallbacks();
Thread.sleep(300L);
updateRPC();
}
} catch (Exception e) {e.printStackTrace();}
}
}

0 comments on commit ad1bd5d

Please sign in to comment.