diff options
-rw-r--r-- | commandManager.js | 111 | ||||
-rw-r--r-- | commands/help.js | 18 | ||||
-rw-r--r-- | commands/leaderboard.js | 44 | ||||
-rw-r--r-- | commands/reload.js | 11 | ||||
-rw-r--r-- | commands/setkey.js | 21 | ||||
-rw-r--r-- | commands/spiral.js | 42 | ||||
-rw-r--r-- | commands/throne.js | 34 | ||||
-rw-r--r-- | commands/toggle.js | 9 | ||||
-rw-r--r-- | commands/update.js | 7 | ||||
-rw-r--r-- | util/constants.js | 28 | ||||
-rw-r--r-- | util/updater.js | 22 |
11 files changed, 347 insertions, 0 deletions
diff --git a/commandManager.js b/commandManager.js new file mode 100644 index 0000000..4c67142 --- /dev/null +++ b/commandManager.js @@ -0,0 +1,111 @@ +import axios from '../axios' +import { help } from "./commands/help.js" +import { reload } from "./commands/reload.js" +import { setkey } from "./commands/setkey.js" +import { spiral } from "./commands/spiral.js" +import { throne } from "./commands/throne.js" +import { toggle } from "./commands/toggle.js" +import { leaderboard } from "./commands/leaderboard.js" +import { update } from './commands/update' +import constants from './util/constants.js' +import updater from './util/updater' + +const PREFIX = constants.PREFIX + +register("command", (arg, arg2, arg3) => { + switch(arg) + { + case "setkey": + setkey(arg2) + break + case "help": + help() + break + case "gui": + constants.cwGui.open(); + break + case "toggle": + toggle() + break + case "throne": + throne(arg2) + break + case "spiral": + spiral(arg2) + break + case "reload": + reload() + break + case "leaderboard": + leaderboard(arg2, arg3) + break + case "update": + update() + break + default: + ChatLib.chat(`${constants.PREFIX}Finding Coleweight!`) + let username = "" + if(arg == undefined) + username = Player.getUUID() + else + username = arg + axios.get(`https://ninjune.dev/api/coleweight?username=${username}`) + .then(res => { + let coleweightMessage = new TextComponent(`${constants.PREFIX}&b${res.data.rank}. ${res.data.name}&b's Coleweight: ${res.data.coleweight} (Top &l${res.data.percentile}&b%)`) + .setHoverValue(`&fExperience&f: &a${res.data.exp}\n&fPowder&f: &a${res.data.pow}\n&fCollection&f: &a${res.data.col}\n&fMiscellaneous&f: &a${res.data.bes + res.data.nuc}`) + ChatLib.chat(coleweightMessage) + }) + .catch(err => { + ChatLib.chat(`${PREFIX}&eError. (api may be down)`) + }) + } +}).setTabCompletions((args) => { + let output = [], + commands = ["setkey", "help", "gui", "toggle", "throne", "spiral", "reload", "leaderboard"] + + if(args[0].length == 0 || args[0] == undefined) + output = commands + else + { + for(let i = 0; i < commands.length; i++) + { + for(let j = 0; j < args[0].length; j++) + { + if(commands[i][j] != args[0][j]) + break + else if(j == args[0].length - 1) + output.push(commands[i]) + } + } + } + return output +}).setName("cw").setAliases(["coleweight"]) + +register("command", (arg) => { + if(arg == undefined) { ChatLib.chat(`${PREFIX}&eRequires a username!`); return; } + axios.get(`https://api.ashcon.app/mojang/v2/user/${arg}`) + .then(res => { + let uuid = res.data.uuid; + axios.get(`https://api.hypixel.net/player?key=${constants.data.api_key}&uuid=${uuid}`) + .then(res2 => { + let discordMessage = new TextComponent(`${PREFIX}&a${res.data.username}'s Discord: `) + ChatLib.chat(discordMessage); + ChatLib.chat(`&b${res2.data.player.socialMedia.links.DISCORD}`) + }) + .catch(err => { + ChatLib.chat(`${PREFIX}&eNo discord linked :( (or no key linked)`) + }) + }) + .catch(err => { + ChatLib.chat(`${PREFIX}&eInvalid name! `) + }); +}).setTabCompletions((args) => { + let players = World.getAllPlayers().map((p) => p.getName()) + .filter((n) => + n.toLowerCase().startsWith(args.length ? args[0].toLowerCase() : "") + ) + .sort(), + output = players + + return output +}).setName("fetchdiscord").setAliases(["fdiscord"]);
\ No newline at end of file diff --git a/commands/help.js b/commands/help.js new file mode 100644 index 0000000..c554294 --- /dev/null +++ b/commands/help.js @@ -0,0 +1,18 @@ +import constants from "../util/constants" +const PREFIX = constants.PREFIX + +export function help() +{ + ChatLib.chat("") + ChatLib.chat(`${PREFIX}&b/cw [username] => Gets coleweight`) + ChatLib.chat(`${PREFIX}&b/cw help => This menu.`) + ChatLib.chat(`${PREFIX}&b/cw gui => Change gui location`) + ChatLib.chat(`${PREFIX}&b/cw toggle => Toggle gui (gui is only active when mining)`) + ChatLib.chat(`${PREFIX}&b/cw setkey (key) => Sets API key (can also use /api new)`) + ChatLib.chat(`${PREFIX}&b/cw reload => Reloads the gui.`) + ChatLib.chat(`${PREFIX}&b/cw throne => Guide for setting up waypoints for throne.`) + ChatLib.chat(`${PREFIX}&b/cw spiral => Guide for setting up waypoints for spiral.`) + ChatLib.chat(`${PREFIX}&b/cw leaderboard => Gets leaderboard within a specific range (like 20 40)`) + ChatLib.chat(`${PREFIX}&b/fetchdiscord (username) => Gets discord of username (if linked)`) + ChatLib.chat("") +}
\ No newline at end of file diff --git a/commands/leaderboard.js b/commands/leaderboard.js new file mode 100644 index 0000000..2b2699f --- /dev/null +++ b/commands/leaderboard.js @@ -0,0 +1,44 @@ +import axios from "../../axios" +import constants from "../util/constants" +const PREFIX = constants.PREFIX + +export function leaderboard(arg2, arg3) +{ + if(arg2 != undefined && parseInt(arg2) == arg2 && !isNaN(parseInt(arg2, 10))) + { + if(arg3 == undefined && parseInt(arg2) == arg2 && !isNaN(parseInt(arg2, 10))) + { + axios.get(`https://ninjune.dev/api/coleweight-leaderboard`) + .then(res => { + for(let i = 0; i < arg2; i++) + { + ChatLib.chat(`&a${res.data[i].rank}. &b${res.data[i].name}: &f${res.data[i].coleweight}`) + } + }) + .catch(err => { + ChatLib.chat(`${PREFIX}&4Error! &eApi might be down.`) + }) + } + else if(parseInt(arg3) == arg3 && !isNaN(parseInt(arg3, 10))) + { + axios.get(`https://ninjune.dev/api/coleweight-leaderboard`) + .then(res => { + for(let i = arg2 - 1; i < arg3; i++) + { + ChatLib.chat(`&a${res.data[i].rank}. &b${res.data[i].name}: &f${res.data[i].coleweight}`) + } + }) + .catch(err => { + ChatLib.chat(`${PREFIX}&4Error! &eApi might be down.`) + }) + } + else + { + ChatLib.chat(`${PREFIX}&ePlease enter an integer! (how many positions) (or a range ie. '20 40')`) + } + } +else +{ + ChatLib.chat(`${PREFIX}&ePlease enter an integer! (how many positions) (or a range ie. '20 40')`) +} +} diff --git a/commands/reload.js b/commands/reload.js new file mode 100644 index 0000000..1c5fcc0 --- /dev/null +++ b/commands/reload.js @@ -0,0 +1,11 @@ +import constants from "../util/constants" +const PREFIX = constants.PREFIX + +export function reload() +{ + constants.upTimeTrack = false + constants.stepsSinceLast = 0 + constants.cwValues = [] + constants.uptime = 0 + ChatLib.chat(`${PREFIX}Reloaded!`) +}
\ No newline at end of file diff --git a/commands/setkey.js b/commands/setkey.js new file mode 100644 index 0000000..8024c0f --- /dev/null +++ b/commands/setkey.js @@ -0,0 +1,21 @@ +import constants from "../util/constants" +const PREFIX = constants.PREFIX + +export function setkey(arg2) +{ + if(arg2 == undefined) { ChatLib.chat(`${PREFIX}&eRequires an argument!`); return; } + else key = arg2 + + constants.data.api_key = key + constants.data.save() + axios.get(`https://api.hypixel.net/key?key=${constants.data.api_key}`) + .then(res => { + if(res.data.success == true) + ChatLib.chat(`${PREFIX}&aSuccsessfully set api key!`) + else + ChatLib.chat(`${PREFIX}&eKey is not valid!`) + }) + .catch(err => { + ChatLib.chat(`${PREFIX}&eKey is not valid!`) + }) +}
\ No newline at end of file diff --git a/commands/spiral.js b/commands/spiral.js new file mode 100644 index 0000000..122ee08 --- /dev/null +++ b/commands/spiral.js @@ -0,0 +1,42 @@ +import constants from "../util/constants" +const PREFIX = constants.PREFIX + +export function spiral(arg2) +{ + if(arg2 != "toggle") + { + new TextComponent(`${PREFIX}&bGo to the place in &3this&b picture and do /cw spiral toggle`) + .setClickAction("open_url") + .setClickValue("https://i.imgur.com/dyL30GD.png") + .chat() + } + else + { + if(constants.spiralValues[0] == undefined) + { + let startPos = [Player.getX(), Player.getY(), Player.getZ()] + constants.spiralValues.push([startPos[0]+2, startPos[1]-3, startPos[2]+14]) + constants.spiralValues.push([startPos[0]+3, startPos[1]-21, startPos[2]+6]) + constants.spiralValues.push([startPos[0]+6, startPos[1]-23, startPos[2]-1]) + constants.spiralValues.push([startPos[0]+19, startPos[1]+4, startPos[2]-5]) + constants.spiralValues.push([startPos[0]+21, startPos[1]-7, startPos[2]]) + constants.spiralValues.push([startPos[0]+25, startPos[1]-35, startPos[2]-8]) + constants.spiralValues.push([startPos[0]+39, startPos[1]-36, startPos[2]]) + constants.spiralValues.push([startPos[0]+52, startPos[1]-24, startPos[2]+1]) + constants.spiralValues.push([startPos[0]+48, startPos[1]+3, startPos[2]+3]) + constants.spiralValues.push([startPos[0]+47, startPos[1]+4, startPos[2]+22]) + constants.spiralValues.push([startPos[0]+55, startPos[1]-8, startPos[2]+42]) + constants.spiralValues.push([startPos[0]+46, startPos[1]-11, startPos[2]+49]) + constants.spiralValues.push([startPos[0]+26, startPos[1]+5, startPos[2]+39]) + constants.spiralValues.push([startPos[0]+20, startPos[1]+3, startPos[2]+41]) + constants.spiralValues.push([startPos[0]+8, startPos[1]-23, startPos[2]+32]) + constants.spiralValues.push([startPos[0]+4, startPos[1]-23, startPos[2]+28]) + ChatLib.chat(`${PREFIX}&bSpiral waypoints turned on!`) + } + else + { + constants.spiralValues = [] + ChatLib.chat(`${PREFIX}&bSpiral waypoints turned off!`) + } + } +}
\ No newline at end of file diff --git a/commands/throne.js b/commands/throne.js new file mode 100644 index 0000000..697304d --- /dev/null +++ b/commands/throne.js @@ -0,0 +1,34 @@ +import constants from "../util/constants" +const PREFIX = constants.PREFIX + +export function throne(arg2) +{ + if(arg2 != "toggle") + { + ChatLib.chat(`${PREFIX}&bGo to the throne and sit on the back block then run /cw throne toggle.`) + } + else + { + if(constants.throneValues[0] == undefined) + { + let startPos = [Player.getX()-24, Player.getY()+6, Player.getZ()-59] // calculated below values at a weird start so adjusting them + constants.throneValues.push([startPos[0]+8, startPos[1]+2, startPos[2]-5]) + constants.throneValues.push([startPos[0]+11, startPos[1]-35, startPos[2]-3]) + constants.throneValues.push([startPos[0]+2, startPos[1]-34, startPos[2]-4]) + constants.throneValues.push([startPos[0]+-2, startPos[1]-1, startPos[2]+49]) + constants.throneValues.push([startPos[0]+2, startPos[1]-13, startPos[2]+52]) + constants.throneValues.push([startPos[0]+27, startPos[1]-9, startPos[2]+51]) + constants.throneValues.push([startPos[0]+38, startPos[1]-15, startPos[2]+47]) + constants.throneValues.push([startPos[0]+41, startPos[1]-44, startPos[2]+46]) + constants.throneValues.push([startPos[0]+50, startPos[1]-28, startPos[2]+38]) + constants.throneValues.push([startPos[0]+49, startPos[1]-31, startPos[2]+1]) + constants.throneValues.push([startPos[0]+50, startPos[1]-1, startPos[2]+10]) + ChatLib.chat(`${PREFIX}&bThrone waypoints turned on!`) + } + else + { + constants.throneValues = [] + ChatLib.chat(`${PREFIX}&bThrone waypoints turned off!`) + } + } +}
\ No newline at end of file diff --git a/commands/toggle.js b/commands/toggle.js new file mode 100644 index 0000000..a5e0ec2 --- /dev/null +++ b/commands/toggle.js @@ -0,0 +1,9 @@ +import constants from "../util/constants" +const PREFIX = constants.PREFIX + +export function toggle() +{ + constants.data.cwToggle = !constants.data.cwToggle + constants.data.save() + ChatLib.chat(`${PREFIX}&bSet gui to: &3${constants.data.cwToggle}`) +}
\ No newline at end of file diff --git a/commands/update.js b/commands/update.js new file mode 100644 index 0000000..708757f --- /dev/null +++ b/commands/update.js @@ -0,0 +1,7 @@ +import constants from "../util/constants" +const PREFIX = constants.PREFIX + +export function update() +{ + ChatLib.chat(`${PREFIX}&bTBA`) +}
\ No newline at end of file diff --git a/util/constants.js b/util/constants.js new file mode 100644 index 0000000..889ca14 --- /dev/null +++ b/util/constants.js @@ -0,0 +1,28 @@ +import PogObject from "PogData" + +let PogData = new PogObject("Coleweight", { + "api_key": undefined, + "x": 0.5, + "y": 141, + "coleweight": 0, + "cwToggle": true, + "first_time": true +}, ".cw_data.json"); + +export default +{ + PREFIX: "&2[CW] ", + VERSION: (JSON.parse(FileLib.read("Coleweight", "metadata.json"))).version, + data: PogData, + cwValues: [], + calcCwPerHr: false, + upTimeTrack: false, + uptime: 0, + baseColeweight: 0, + stepsSinceLast: 0, + cwGui: new Gui(), + throneValues: [], + spiralValues: [], + coleweightHr: 0, + cwValuesSum: 0 +}
\ No newline at end of file diff --git a/util/updater.js b/util/updater.js new file mode 100644 index 0000000..dd497b6 --- /dev/null +++ b/util/updater.js @@ -0,0 +1,22 @@ +import axios from "../../axios" +import constants from "./constants" +PREFIX = constants.PREFIX +VERSION = constants.VERSION + +register("worldLoad", () => { + axios.get(`https://raw.githubusercontent.com/Ninjune/coleweight/main/metadata.json`) + .then(res => { + if(res.data.version == VERSION) return + ChatLib.chat(`${PREFIX}&eYou are using an unsupported version of Coleweight!`) + new TextComponent(`${PREFIX}&eClick &3here&e to open the github releases!`) + .setClickAction("open_url") + .setClickValue(`https://github.com/Ninjune/coleweight/releases/${res.data.version}`) + .chat() + ChatLib.chat("") + }) + .catch(err => { + ChatLib.chat(err) + }) +}) + +export default ""
\ No newline at end of file |