diff options
author | syeyoung <cyong06@naver.com> | 2021-03-06 13:01:03 +0900 |
---|---|---|
committer | syeyoung <cyong06@naver.com> | 2021-03-06 13:01:03 +0900 |
commit | ccdcb508b1b7b5fcc212efc39466434631118e87 (patch) | |
tree | f09e4fb0db49a10a1f91757c0432a908e6f89a6d /src/main/java/kr/syeyoung/dungeonsguide/RichPresenceManager.java | |
parent | d07cfe08841302ad1ce1e29902d06c4c439a589f (diff) | |
download | Skyblock-Dungeons-Guide-ccdcb508b1b7b5fcc212efc39466434631118e87.tar.gz Skyblock-Dungeons-Guide-ccdcb508b1b7b5fcc212efc39466434631118e87.tar.bz2 Skyblock-Dungeons-Guide-ccdcb508b1b7b5fcc212efc39466434631118e87.zip |
UHH why would you troll
Diffstat (limited to 'src/main/java/kr/syeyoung/dungeonsguide/RichPresenceManager.java')
-rw-r--r-- | src/main/java/kr/syeyoung/dungeonsguide/RichPresenceManager.java | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/RichPresenceManager.java b/src/main/java/kr/syeyoung/dungeonsguide/RichPresenceManager.java index 422d15e1..641522a6 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/RichPresenceManager.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/RichPresenceManager.java @@ -6,18 +6,23 @@ import kr.syeyoung.dungeonsguide.features.FeatureRegistry; import kr.syeyoung.dungeonsguide.party.PartyManager; import kr.syeyoung.dungeonsguide.stomp.StompHeader; import kr.syeyoung.dungeonsguide.stomp.StompPayload; -import net.arikia.dev.drpc.DiscordEventHandlers; -import net.arikia.dev.drpc.DiscordRPC; -import net.arikia.dev.drpc.DiscordRichPresence; -import net.arikia.dev.drpc.DiscordUser; +import net.arikia.dev.drpc.*; import net.arikia.dev.drpc.callbacks.*; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; import org.json.JSONObject; -public class RichPresenceManager implements JoinRequestCallback, JoinGameCallback, ErroredCallback, DisconnectedCallback { +import java.io.*; +import java.net.URL; + +public class RichPresenceManager implements JoinRequestCallback, JoinGameCallback, ErroredCallback, DisconnectedCallback, Runnable { public static RichPresenceManager INSTANCE = new RichPresenceManager(); + public RichPresenceManager() { + setup(); + new Thread(this).start(); + Runtime.getRuntime().addShutdownHook(new Thread(DiscordRPC::discordShutdown)); + } public void setup() { DiscordRPC.discordInitialize("816298079732498473", new DiscordEventHandlers.Builder() .setReadyEventHandler(new ReadyCallback() { @@ -36,7 +41,6 @@ public class RichPresenceManager implements JoinRequestCallback, JoinGameCallbac public void updatePresence() { - nextUpdate= System.currentTimeMillis() + 10000L; if (!skyblockStatus.isOnHypixel() || !FeatureRegistry.ADVANCED_RICHPRESENCE.isEnabled()) { DiscordRPC.discordClearPresence(); } else { @@ -67,17 +71,9 @@ public class RichPresenceManager implements JoinRequestCallback, JoinGameCallbac } private String lastLoc = ""; - private long nextUpdate = System.currentTimeMillis() + 10000L; + @SubscribeEvent public void tick(TickEvent.ClientTickEvent clientTickEvent) { - try { - if (skyblockStatus.isOnSkyblock() && !lastLoc.equalsIgnoreCase(skyblockStatus.getDungeonName())) { - lastLoc = skyblockStatus.getDungeonName()+""; - updatePresence(); - } else if (nextUpdate < System.currentTimeMillis()) { - updatePresence(); - } - } catch (Exception e) {e.printStackTrace();} } @Override @@ -99,4 +95,17 @@ public class RichPresenceManager implements JoinRequestCallback, JoinGameCallbac System.out.println(user.username+" wants to join"); DiscordRPC.discordRespond(user.userId, DiscordRPC.DiscordReply.YES); } + + @Override + public void run() { + while(true) { + try { + DiscordRPC.discordRunCallbacks(); + if (skyblockStatus.isOnSkyblock() && !lastLoc.equalsIgnoreCase(skyblockStatus.getDungeonName())) { + lastLoc = skyblockStatus.getDungeonName()+""; + } + updatePresence(); + } catch (Exception e) {e.printStackTrace();} + } + } } |