aboutsummaryrefslogtreecommitdiff
path: root/commands/claim.js
diff options
context:
space:
mode:
authorNinjune x <enderknight537@gmail.com>2022-11-29 21:19:03 -0600
committerNinjune x <enderknight537@gmail.com>2022-11-29 21:19:03 -0600
commitad055ba90a3055db32f04ff5163ff4e1c85dfdfa (patch)
treeaee8962d031dffddd27fa702262a0ef7c66c08ce /commands/claim.js
parent00f4ecbc69216d4aee44bcdac92955c4eb774298 (diff)
downloadcoleweight-ad055ba90a3055db32f04ff5163ff4e1c85dfdfa.tar.gz
coleweight-ad055ba90a3055db32f04ff5163ff4e1c85dfdfa.tar.bz2
coleweight-ad055ba90a3055db32f04ff5163ff4e1c85dfdfa.zip
Diffstat (limited to 'commands/claim.js')
-rw-r--r--commands/claim.js50
1 files changed, 35 insertions, 15 deletions
diff --git a/commands/claim.js b/commands/claim.js
index d549056..ae20924 100644
--- a/commands/claim.js
+++ b/commands/claim.js
@@ -2,7 +2,7 @@ import axios from "../../axios"
import settings from "../settings"
import constants from "../util/constants"
const PREFIX = constants.PREFIX
-
+const serverId = java.util.UUID.randomUUID().toString().replace("-", "")
export function claim(structure)
{
@@ -23,35 +23,56 @@ export function claim(structure)
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}`)
+
+ axios.get(`https://ninjune.dev/api/claim?type=${structure}&lobby=${constants.serverData.server}&username=${Player.getName()}&serverID=${serverId}`)
.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}`)
+ {
+ ChatLib.chat(`${PREFIX}&cError: ${res.data.reason}.`)
+ if(res.data.code == 501)
+ {
+ ChatLib.chat(`${PREFIX}&cError: Not logged into the auth server. Try running the command again.`)
+ Client.getMinecraft().func_152347_ac().joinServer(Client.getMinecraft().func_110432_I().func_148256_e(), Client.getMinecraft().func_110432_I().func_148254_d(), serverId)
+ }
+ }
})
.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('gameLoad', (event) => {
+ Client.getMinecraft().func_152347_ac().joinServer(Client.getMinecraft().func_110432_I().func_148256_e(), Client.getMinecraft().func_110432_I().func_148254_d(), serverId)
+})
register('worldLoad', () => {
if(!settings.claiming) return
-
+ axios.get(`https://ninjune.dev/api/unclaim?username=${Player.getName()}&serverID=${serverId}`)
+ .then(res => {
+ if(settings.debug && !res.data.success)
+ ChatLib.chat("Unclaim: " + res.data.reason)
+ if(res.data.code == 501)
+ Client.getMinecraft().func_152347_ac().joinServer(Client.getMinecraft().func_110432_I().func_148256_e(), Client.getMinecraft().func_110432_I().func_148254_d(), serverId)
+ })
+ .catch(err => {
+ if(settings.debug)
+ ChatLib.chat(`${PREFIX}&cError: ${err}`)
+ })
+ // unclaims the lobby, isn't needed but will allow another player to claim lobby after claimer leaves.
setTimeout(() => {
const NetHandlerPlayClient = Client.getConnection(),
- PlayerMap = NetHandlerPlayClient.func_175106_d() // getPlayerInfoMap
+ PlayerMap = NetHandlerPlayClient.func_175106_d() // getPlayerInfoMap
if(settings.debug) console.log(constants.serverData.server)
- axios.get(`https://ninjune.dev/api/claim?claimedlobby=${constants.serverData.server}`)
+ axios.get(`https://ninjune.dev/api/claimed?serverID=${constants.serverData.server}&authServer=${serverId}&passedName=${Player.getName()}`)
.then(res => {
if(res.data.claimed)
{
- PlayerMap.filter(player => player.func_178853_c() > 0 && !player.func_178845_a().name.startsWith("!")).forEach((PlayerMP) => {
- let player = PlayerMP.func_178845_a().name
+ PlayerMap.filter(player => player.func_178853_c() /* getResponseTime */ > 0 && !player.func_178845_a()/* getGameProfile */.name.startsWith("!")).forEach((PlayerMP) => {
+ let player = PlayerMP.func_178845_a()/* getGameProfile */.name
res.data.structures.forEach((structure) => {
if (player == structure.player)
@@ -60,15 +81,14 @@ register('worldLoad', () => {
})
})
}
+ else if (res.data.err && settings.debug)
+ {
+ ChatLib.chat("Check claim: " + res.data.reason)
+ }
})
.catch(err => {
if(!settings.debug) return
ChatLib.chat(`${PREFIX}&cError: ${err}`)
})
}, 2000)
-})
-
-register('worldUnload', () => {
- axios.get(`https://ninjune.dev/api/unclaim?claimedlobby=${constants.serverData.server}&key=${constants.data.api_key}`)
- // unclaims the lobby, isn't needed but will allow another player to claim lobby after claimer leaves. key used to verify identity of unclaimer.
}) \ No newline at end of file