aboutsummaryrefslogtreecommitdiff
path: root/features/waypoints/minewaypoints_socket.js
blob: 0cc31e52d0c1964b3ab6ce01a4131bde187bb241 (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
import socketData from "../../../soopyApis/socketData";
import WebsiteCommunicator from "../../../soopyApis/websiteCommunicator";

class MineWayPointsServer extends WebsiteCommunicator {
    constructor() {
        super(socketData.serverNameToId.minewaypoints);

        this.setLocationHandler = undefined
        this.hypixelServer = undefined
        this.lastSend = Date.now()
    }

    onConnect() {
        this.hypixelServer = undefined
    }

    onData(data) {
        switch (data.type) {
            case "setLocation":
                if (this.setLocationHandler) {
                    this.setLocationHandler(data.area, data.location);
                }
                break;
        }
    }

    setLocation(area, loc) {
        this.sendData({
            type: "setLocation",
            area: area,
            location: loc
        });
    }

    setServer(server, worldTime) {
        if (this.hypixelServer === server && Date.now() - this.lastSend < 10000) return;

        this.lastSend = Date.now()
        this.hypixelServer = server
        this.sendData({
            type: "setServer",
            server: server,
            time: worldTime
        });
    }
}

global.soopyV2mineWayPointsServer = new MineWayPointsServer()
export default global.soopyV2mineWayPointsServer;