aboutsummaryrefslogtreecommitdiff
path: root/commands/claim.js
blob: fc0bc57036e5ed8270cce1e2cf6d5be478e76c05 (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
import axios from "../../axios"
import settings from "../settings"
import constants from "../util/constants"
const PREFIX = constants.PREFIX


export function claim(structure)
{
    if(!settings.claiming) 
    {
        ChatLib.chat(`${PREFIX}&cPlease turn on the &3Claiming&c setting in /cw settings!`)
        return
    }

    if (constants.serverData.map != "Crystal Hollows")
    {
        ChatLib.chat(`${PREFIX}&cThis command is only available in the crystal hollows!`)
        return
    }

    if (structure == undefined || !(structure.toLowerCase() == "throne" || structure.toLowerCase() == "spiral"))
    {
        ChatLib.chat(`${PREFIX}&cPlease enter the structure you wish to claim! (&3throne&c or &3spiral&c)`)
        return
    }

    axios.get(`https://ninjune.dev/api/claim?type=${structure}&id=${constants.serverData.server}&key=${constants.data.api_key}`)
    .then(res => {
        if(res.data.success)
            ChatLib.chat(`${PREFIX}&aSuccessfully claimed ${constants.serverData.server} as your server!`)
        else
            ChatLib.chat(`${PREFIX}&cError: ${res.data.reason}`)
    })
    .catch(err => {
        ChatLib.chat(`${PREFIX}&cError: ${err}`)
    })
    // key is used above to verify that the player trying to claim the lobby is the intended player, don't know a better way of doing this.
}


register('worldLoad', () => {
    if(!settings.claiming) return
    setTimeout(() => {
        console.log(constants.serverData.server)
        axios.get(`https://ninjune.dev/api/claim?claimedlobby=${constants.serverData.server}`)
        .then(res => {
            if(res.data.claimed)
            {
                World.getAllPlayers().forEach((player) => {
                    if (player.getName() == res.data.player)
                    ChatLib.chat(`${PREFIX}&cThe ${res.data.structure} in this lobby is claimed by ${res.data.player}.`)
                })
            }
        })
        .catch(err => {
            ChatLib.chat(`${PREFIX}Error: ${err}`)
        })
    }, 2000)
})