Add delfcare and command core

This commit is contained in:
7cc5c4f330d47060 2024-10-23 21:18:45 -04:00
parent 6c2f05c487
commit ab593cfd7d
Signed by: 7cc5c4f330d47060
SSH key fingerprint: SHA256:e+4tcZut1nBpe10PqjaO+Rvie0Q7W4qIvFzcUw+7riA
4 changed files with 280 additions and 0 deletions

140
plugins/commandblock.js Executable file
View file

@ -0,0 +1,140 @@
import { uuidToInt } from '../util/uuidtoint.js'
import { parse2 as plainParser } from '../util/chatparse_plain.js'
import { parse2 as mcParser } from '../util/chatparse_mc.js'
const cs = {
x: 4,
y: 6,
z: 4
}
const load = function (b) {
b.interval.commandFill = setInterval(() => { if (b.sc_tasks.cc) b.sc_tasks.cc.failed = 1 }, 150000)
b.ccq = []
b.blocknoX = 0
b.blocknoZ = 0
b.ccStarted = false
b.blocknoY = 0
b.pos = { x: 0, y: 0, z: 0 }
b.refillCoreCmd = `/fill ~ 55 ~ ~${cs.x - 1} ${54 + cs.y} ~${cs.z - 1} command_block{CustomName:'{"translate":"%s %s","with":[{"translate":"entity.minecraft.ender_dragon"},{"translate":"language.region"}],"color":"#FFAAEE"}'}`
b.advanceccq = function () {
if (b.host.options.useChat) return
if (b.ccq[0] && b.ccq[0].length !== 0) {
b._client.write('update_command_block', {
command: '/',
location: {
x: b.commandPos.x + b.blocknoX,
y: b.commandPos.y + b.blocknoY,
z: b.commandPos.z + b.blocknoZ
},
mode: 2,
flags: 1
})
b._client.write('update_command_block', {
command: b.ccq[0].substr(0, 32767),
location: {
x: b.commandPos.x + b.blocknoX,
y: b.commandPos.y + b.blocknoY,
z: b.commandPos.z + b.blocknoZ
},
mode: 2,
flags: 5
})
b.blocknoX++
if (b.blocknoX === cs.x) {
b.blocknoY++
b.blocknoX = 0
if (b.blocknoY === cs.y) {
b.blocknoZ++
b.blocknoY = 0
if (b.blocknoZ === cs.z) {
b.blocknoZ = 0
}
}
}
}
b.ccq.splice(0, 1)
}
b._client.on('login', () => {
b._client.write('settings', {
locale: 'ru_RU',
viewDistance: 4,
chatFlags: 0, // Enable full chat functionality
chatColors: true,
skinParts: 127, // Allow the second layer of the skin, when the bot is sudoed to do /skin
mainHand: 1 // Right hand
})
if (!b.host.options.useChat) {
b.add_sc_task('cc', () => {
b.chat(b.refillCoreCmd)
}, true)
b.add_sc_task('cc_size', () => {
b.chat('/gamerule commandModificationBlockLimit 32768')
})
}
})
b.on('ccstart', () => {
setTimeout(() => { b.interval.ccqi = setInterval(b.advanceccq, 2) }, 1000)
b.ccStarted = true
})
b.on('chat_unparsed', (data) => {
if (data.json.translate === 'commands.fill.failed' || (data.json.extra && data.json.extra[0] && data.json.extra[0].translate === 'commands.fill.failed') ||
data.json.translate === 'commands.fill.success' || (data.json.extra && data.json.extra[0] && data.json.extra[0].translate === 'commands.fill.success')) {
if (!b.ccStarted) {
b.emit('ccstart')
}
b.sc_tasks.cc.failed = 0
b.sc_tasks.cc_size.failed = 0
} else if (data.json.translate === 'commands.fill.toobig' || (data.json.extra && data.json.extra[0] && data.json.extra[0].translate === 'commands.fill.toobig')) {
b.sc_tasks.cc_size.failed = 1
}
})
b._client.on('position', function (a) {
if (!b.ccStarted) {
b.original_pos = { x: a.x, y: a.y, z: a.z }
b.pos = { x: a.x, y: a.y, z: a.z }
} else {
b.pos = { x: a.x, y: a.y, z: a.z }
if (a.x !== b.original_pos.x || a.z !== b.original_pos.z) {
b.original_pos = { x: a.x, y: a.y, z: a.z }
b.sc_tasks.cc.failed = 1
}
}
b.commandPos = {
x: Math.floor(a.x),
z: Math.floor(a.z),
y: 55
}
b._client.write('teleport_confirm', { teleportId: a.teleportId })
})
b.tellraw = (uuid, message) => {
let finalname = ''
if (b.host.options.useChat) {
if (b.host.options.useAmpersandColorCodes) {
b.chat(mcParser(message).replaceAll('§', '&'))
} else {
b.chat(plainParser(message))
}
} else {
if (uuid === '@a') {
finalname = '@a'
} else if (uuid.match(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/)) {
finalname = `@a[nbt={UUID:[I;${uuidToInt(uuid)}]}]`
} else {
finalname = uuid
}
let tellrawCommand
if (b.host.options.isVanilla) {
tellrawCommand = 'tellraw'
} else {
tellrawCommand = 'minecraft:tellraw'
}
b.ccq.push(`/${tellrawCommand} ${finalname} ${JSON.stringify(message)}`)
}
}
}
export { load }

133
plugins/selfcare.js Executable file
View file

@ -0,0 +1,133 @@
import { parse2 as parsePlain } from '../util/chatparse_plain.js'
import { parse2 as parseMc } from '../util/chatparse_mc_withHex.js'
import { default as settings } from '../settings.json' with {type: "json"}
import { default as version } from '../version.json' with {type: "json"}
class SCTask {
constructor (failTask, startFailed = false) {
/*
* failed: Whether to run this task
* failTask: Command to run when failed is true
*/
this.failed = startFailed
this.failTask = failTask
}
}
const load = (b) => {
b.sc_tasks = {}
b.selfcareRun = 0
b.interval.sc = setInterval(() => {
if (Date.now() - b.selfcareRun <= 600) {
return
}
for (const i in b.sc_tasks) {
if (b.sc_tasks[i].failed) {
b.sc_tasks[i].failTask()
}
}
b.selfcareRun = Date.now()
}, 40)
b.add_sc_task = (name, failTask, startFailed) => {
b.sc_tasks[name] = new SCTask(failTask, startFailed)
}
// Self care tasks
// Operator
b.add_sc_task('op', () => {
b.chat('/op @s[type=player]')
})
b._client.on('login', (p) => {
b.entityId = p.entityId
})
b._client.on('entity_status', (p) => {
if (p.entityId === b.entityId && p.entityStatus === 24) {
b.sc_tasks.op.failed = 1
} else if (p.entityId === b.entityId && p.entityStatus === 28) {
b.sc_tasks.op.failed = 0
}
})
// CommandSpy
if (!b.host.options.isVanilla) {
b.add_sc_task('cspy', () => {
b.chat('/cspy on')
}, true)
b.on('plainchat', (msg) => {
if (msg === 'Successfully disabled CommandSpy') {
b.sc_tasks.cspy.failed = 1
} else if (msg === 'Successfully enabled CommandSpy') {
b.sc_tasks.cspy.failed = 0
}
})
}
// Gamemode / end portal bug
b.add_sc_task('gamemode', () => {
b.chat('/minecraft:gamemode creative')
})
b._client.on('game_state_change', (p) => {
if (p.reason === 3 && p.gameMode !== 1) {
b.sc_tasks.gamemode.failed = 1
} else if (p.reason === 3 && p.gameMode === 1) {
b.sc_tasks.gamemode.failed = 0
} else if (p.reason === 4) {
b.sc_tasks.respawn.failed = 1
}
})
// Respawning after dying
b.add_sc_task('respawn', () => {
b._client.write('client_command', { actionId: 0 }) // Simulates respawning
b.sc_tasks.respawn.failed = 0
})
b.on('chat_unparsed', (data) => {
if (data.json.translate === 'chat.disabled.options' || (data.json.extra && data.json.extra[0] && data.json.extra[0].translate === 'chat.disabled.options') ||
data.json.translate === 'Chat disabled in client options' || (data.json.extra && data.json.extra[0] && data.json.extra[0].translate === 'Chat disabled in client options')) {
b.sc_tasks.respawn.failed = 1
}
})
// Prefix tablist ads
if (!b.host.options.isVanilla) {
b.adPrefix = {
translate: '[%s] %s', // Since the bot aims to have an invisible name, the ad prefix should contain information about the bot.
color: 'white',
with: [
{
translate: '%s: %s',
color: settings.colors.secondary,
with: [
{
text: 'Prefix'
},
{
text: settings.prefix[0],
color: settings.colors.primary
}
]
},
{
text: version.botName,
color: settings.colors.primary
}
]
}
b.add_sc_task('playerlist_ads', () => {
b.chat(`/prefix ${parseMc(b.adPrefix).replaceAll('§', '&')}`)
})
b.on('playerdata', (uuid, displayName) => {
if (uuid === b._client.uuid && !displayName.startsWith(parsePlain(b.adPrefix))) {
b.sc_tasks.playerlist_ads.failed = 1
}
})
b.on('plainchat', (msg) => {
if (msg === `You now have the tag: ${parseMc(b.adPrefix).replaceAll('§', '&')}`) {
b.sc_tasks.playerlist_ads.failed = 0
}
})
}
}
export { load }

6
util/uuidtoint.js Normal file
View file

@ -0,0 +1,6 @@
const uuidToInt = function (uuid) {
const splitUUID = uuid.replace(/[^0-9a-f]/g, '').replace(/.{1,8}/g, a => { return `0x${a}` }).match(/.{1,10}/g)
const numUUID = [+splitUUID[0] << 0, +splitUUID[1] << 0, +splitUUID[2] << 0, +splitUUID[3] << 0]
return numUUID
}
export { uuidToInt }

1
version.json Normal file
View file

@ -0,0 +1 @@
{}