aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/kr/syeyoung/dungeonsguide/RichPresenceManager.java
blob: f3b75d41357e4c2d47570a94a8b47708d4dce830 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package kr.syeyoung.dungeonsguide;

import com.jagrosh.discordipc.IPCClient;
import com.jagrosh.discordipc.IPCListener;
import com.jagrosh.discordipc.entities.Packet;
import com.jagrosh.discordipc.entities.RichPresence;
import com.jagrosh.discordipc.entities.User;
import com.jagrosh.discordipc.exceptions.NoDiscordClientException;
import kr.syeyoung.dungeonsguide.events.SkyblockJoinedEvent;
import kr.syeyoung.dungeonsguide.events.SkyblockLeftEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import org.json.JSONObject;

import java.time.OffsetDateTime;

public class RichPresenceManager implements IPCListener {
    public static RichPresenceManager INSTANCE = new RichPresenceManager();

    private IPCClient ipcClient;
    public void setup() throws NoDiscordClientException {
        ipcClient = new IPCClient(816298079732498473L);
        ipcClient.setListener(this);
        ipcClient.connect();
    }

    @Override
    public void onReady(IPCClient client) {
        updatePresence();
    }

    @Override
    public void onActivityJoinRequest(IPCClient client, String secret, User user) {
        System.out.println(user.getAsMention()+" wanna join");
    }

    @Override
    public void onPacketReceived(IPCClient client, Packet packet) {
        System.out.println("Packet recv from rpc "+packet);
    }

    @Override
    public void onDisconnect(IPCClient client, Throwable t) {
        t.printStackTrace();
        try {
            setup();
        } catch (NoDiscordClientException e) {
            e.printStackTrace();
        }
    }

    private SkyblockStatus skyblockStatus = e.getDungeonsGuide().getSkyblockStatus();


    public void updatePresence() {
        if (!skyblockStatus.isOnHypixel()) {
            ipcClient.sendRichPresence(null);
        } else {
            ipcClient.sendRichPresence(new RichPresence.Builder()
            .setJoinSecret(""));
        }
    }

    private String JOIN_SECRET;


    @SubscribeEvent
    public void joinSkyblock(SkyblockJoinedEvent skyblockJoinedEvent) {
        updatePresence();
    }
    @SubscribeEvent
    public void leaveSkyblock(SkyblockLeftEvent skyblockLeftEvent) {
        updatePresence();
    }
}