Skip to content

Commit

Permalink
rename serverInfo to scoreboard
Browse files Browse the repository at this point in the history
  • Loading branch information
kaduvert committed Nov 12, 2024
1 parent cddf2d2 commit 652c098
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 45 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mineflayer-griefergames",
"version": "0.1.14",
"version": "0.1.15",
"description": "rich, high-level API for creating bots for GrieferGames (griefergames.net)",
"main": "src/index.js",
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/basic/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const plugins = [
require('./pathfinder'),
require('./playerUtils'),
require('./privateChat'),
require('./serverInfo'),
require('./scoreboard'),
require('./slowChat'),
require('./switch'),
require('./tpa')
Expand Down
49 changes: 49 additions & 0 deletions src/basic/scoreboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
module.exports = function load(bot, ns) {
const scoreboard = ns.data['scoreboard']

ns.scoreboard.getCurrentServer = () => bot.scoreboard.sidebar.items[2].displayName.toString()

ns.scoreboard.getBalance = () => bot.scoreboard.sidebar.items[5].displayName.toString()

ns.scoreboard.getOnlineCount = () => bot.scoreboard.sidebar.items[8].displayName.toString()

ns.scoreboard.getPlaytime = () => bot.scoreboard.sidebar.items[11].displayName.toString()

ns.scoreboard.getTranslatedServer = (server = ns.scoreboard.getCurrentServer()) => {
if (scoreboard.scoreboardCitybuildRegex.test(server) || (scoreboard.nonCitybuildServer.includes(server.toLowerCase()) || scoreboard.abnormallyNamedCitybuildServer.includes(server.toLowerCase()))) {
return server.toLowerCase()
}

const switcherName = scoreboard.scoreboardToSwitcherMap[server]
if (switcherName) {
return switcherName
}
}

ns.scoreboard.getNumericBalance = () => ns.money.toNumberScoreboard(ns.scoreboard.getBalance())

ns.scoreboard.isOnCitybuild = () => !scoreboard.nonCitybuildServer.includes(ns.scoreboard.getTranslatedServer())

ns.scoreboard.isHub = () => ns.scoreboard.getTranslatedServer() === scoreboard.hubIdentifier

ns.scoreboard.isPortal = () => ns.scoreboard.getTranslatedServer() === scoreboard.portalIdentifier

ns.scoreboard.isScoreboardLoaded = () => bot.scoreboard?.sidebar?.items?.length >= 14

ns.data.serverInfo = scoreboard
ns.serverInfo = ns.scoreboard

bot.on('scoreboardCreated', async () => {
const listenForLoadedInterval = setInterval(() => {
if (ns.scoreboard.isScoreboardLoaded()) {
bot.emit('misc:scoreboard->loaded')
bot.emit('misc:scoreboard->join')

bot.emit('misc:serverInfo->scoreboardLoaded')
bot.emit('misc:serverInfo->join')

clearInterval(listenForLoadedInterval)
}
}, 50)
})
}
43 changes: 0 additions & 43 deletions src/basic/serverInfo.js

This file was deleted.

0 comments on commit 652c098

Please sign in to comment.