more overhauls

This commit is contained in:
Parker2991
2025-08-14 10:13:54 -05:00
parent 28be25d2e6
commit dc08bcad37
39 changed files with 924 additions and 491 deletions
+94 -185
View File
@@ -1,6 +1,8 @@
const loadPrismarineChat = require("prismarine-chat");
const KaboomChatParser = require("../chat_parsers/kaboom");
const CreayunChatParser = require("../chat_parsers/creayun");
const ChipmunkModChatParser = require("../chat_parsers/chipmunkmod")
const VanilaChatParser = require("../chat_parsers/vanilla")
const convertNbtComponentToJson = require("../util/nbt_parser");
function tryParse(json) {
@@ -23,224 +25,125 @@ class chat {
if (options.mode === "savageFriends") {
bot.chatParsers = [CreayunChatParser];
} else {
bot.chatParsers = [KaboomChatParser];
bot.chatParsers = [KaboomChatParser, ChipmunkModChatParser, VanilaChatParser];
}
bot.on("packet.profileless_chat", (packet) => {
let message
let sender
if (bot._client.version === "1.21" || bot.options.version === "1.21.1") {
message = convertNbtComponentToJson(null, packet.message);
sender = convertNbtComponentToJson(null, packet.name);
} else {
message = tryParse(packet.message);
sender = tryParse(packet.name);
}
message = tryParse(packet.message);
sender = tryParse(packet.name);
if (bot.options.version === "1.21" || bot._client.version === "1.21.1") {
switch (packet.type.registryIndex) {
case 6:
bot.emit("message", {
translate: "chat.type.announcement",
with: [sender, message],
});
break;
case 5:
bot.emit("message", message);
break;
case 4:
bot.emit("message", {
switch (packet.type) {
case 1:
bot.emit("message", {
translate: "chat.type.emote",
with: [sender, message],
});
break;
case 2:
bot.emit("message", {
translate: "commands.message.display.incoming",
with: [sender, message],
color: "gray",
italic: true,
});
break;
case 3:
bot.emit("message", [
{
translate: "commands.message.display.outgoing",
with: [sender, message],
color: "gray",
italic: true,
});
break;
case 3:
bot.emit("message", {
translate: "commands.message.display.incoming",
with: [sender, message],
color: "gray",
italic: true,
});
break;
case 2:
bot.emit("message", {
translate: "chat.type.emote",
with: [sender, message],
});
break;
}
} else {
switch (packet.type) {
case 1:
bot.emit("message", {
translate: "chat.type.emote",
with: [sender, message],
});
break;
case 2:
bot.emit("message", {
translate: "commands.message.display.incoming",
with: [sender, message],
color: "gray",
italic: true,
});
break;
case 3:
bot.emit("message", [
{
translate: "commands.message.display.outgoing",
with: [sender, message],
color: "gray",
italic: true,
},
]);
break;
case 4:
bot.emit("message", [message]);
break;
case 5:
bot.emit("message", [
{ translate: "chat.type.announcement", with: [sender, message] },
]);
break;
}
},
]);
break;
case 4:
bot.emit("message", [message]);
break;
case 5:
bot.emit("message", [
{ translate: "chat.type.announcement", with: [sender, message] },
]);
break;
}
tryParsingMessage(message, { senderName: sender, players: bot.players, chatType: "profileless", getMessageAsPrismarine: bot.getMessageAsPrismarine })
});
bot.on("packet.player_chat", (packet, data) => {
let unsigned;
if (bot.options.version === "1.21" || bot.options.version === "1.21.1") {
unsigned = convertNbtComponentToJson(null, packet.unsignedChatContent);
} else {
unsigned = tryParse(packet.unsignedChatContent);
}
unsigned = tryParse(packet.unsignedChatContent);
if (bot.options.version === "1.21" || bot.options.version === "1.21.1") {
switch (packet.type.registryIndex) {
case 6:
bot.emit("message", {
translate: "chat.type.announcement",
with: [
bot.players.find((player) => player.uuid === packet.senderUuid)
.profile.name,
switch (packet.type) {
case 5:
bot.emit("message", {
translate: "chat.type.announcement",
with: [
bot.players.find((player) => player.uuid === packet.senderUuid)
.profile.name,
packet.plainMessage,
],
});
break;
case 4:
bot.emit("message", unsigned);
break;
case 3:
bot.emit("message", {
translate: "commands.message.display.outgoing",
with: [
bot.players.find((player) => player.uuid === packet.senderUuid)
.profile.name,
packet.plainMessage,
],
color: "gray",
italic: true,
});
break;
case 2:
bot.emit("message", {
translate: "commands.message.display.incoming",
with: [
bot.players.find((player) => player.uuid === packet.senderUuid)
.profile.name,
packet.plainMessage,
],
});
break;
case 5:
bot.emit("message", unsigned);
break;
case 4:
bot.emit("message", {
translate: "commands.message.display.outgoing",
with: [
bot.players.find((player) => player.uuid === packet.senderUuid)
.profile.name,
packet.plainMessage,
],
color: "gray",
italic: true,
});
break;
case 3:
bot.emit("message", {
translate: "commands.message.display.incoming",
with: [
bot.players.find((player) => player.uuid === packet.senderUuid)
.profile.name,
packet.plainMessage,
],
color: "gray",
italic: true,
});
break;
case 2:
bot.emit("message", {
translate: "chat.type.emote",
with: [
bot.players.find((player) => player.uuid === packet.senderUuid)
.profile.name,
packet.plainMessage,
],
});
break;
}
} else {
switch (packet.type) {
case 5:
bot.emit("message", {
translate: "chat.type.announcement",
with: [
bot.players.find((player) => player.uuid === packet.senderUuid)
.profile.name,
packet.plainMessage,
],
});
break;
case 4:
bot.emit("message", unsigned);
break;
case 3:
bot.emit("message", {
translate: "commands.message.display.outgoing",
with: [
bot.players.find((player) => player.uuid === packet.senderUuid)
.profile.name,
packet.plainMessage,
],
color: "gray",
italic: true,
});
break;
case 2:
bot.emit("message", {
translate: "commands.message.display.incoming",
with: [
bot.players.find((player) => player.uuid === packet.senderUuid)
.profile.name,
packet.plainMessage,
],
color: "gray",
italic: true,
});
break;
case 1:
bot.emit("message", {
translate: "chat.type.emote",
with: [
bot.players.find((player) => player.uuid === packet.senderUuid)
.profile.name,
packet.plainMessage,
],
});
break;
}
],
color: "gray",
italic: true,
});
break;
case 1:
bot.emit("message", {
translate: "chat.type.emote",
with: [
bot.players.find((player) => player.uuid === packet.senderUuid)
.profile.name,
packet.plainMessage,
],
});
break;
}
tryParsingMessage(unsigned, {
senderUuid: packet.senderUuid,
players: bot.players,
getMessageAsPrismarine: bot.getMessageAsPrismarine,
chatType: "player"
});
});
bot.on("packet.system_chat", (packet) => {
let message;
if (bot.options.version === "1.21" || bot.options.version === "1.21.1") {
message = convertNbtComponentToJson(null, packet.content);
} else {
message = tryParse(packet.content);
}
message = tryParse(packet.content);
if (
message.translate === "advMode.setCommand.success" &&
config?.debug?.commandSetMessage === false
)
return;
return;
if (message.translate === "multiplayer.message_not_delivered") return;
if (packet.isActionBar) {
@@ -250,14 +153,17 @@ class chat {
if (message.translate === "advMode.notAllowed") return;
bot.emit("message", message);
bot.emit("system_chat", message)
tryParsingMessage(message, {
players: bot.players,
getMessageAsPrismarine: bot.getMessageAsPrismarine,
chatType: "system"
});
});
function tryParsingMessage(message, data) {
try {
let parsed;
for (const parser of bot.chatParsers) {
@@ -267,6 +173,9 @@ class chat {
if (!parsed) return;
bot.emit("parsed_message", parsed);
} catch (e) {
console.log(e.stack)
}
}
bot.getMessageAsPrismarine = (message) => {
+19 -7
View File
@@ -25,7 +25,7 @@ class command_core {
usePlacedCommandBlock: false,
refill() {
chatRefill() {
const pos = bot.core.position;
const { start, end } = bot.core.area;
const itemPosition = bot.core.itemPosition;
@@ -35,10 +35,18 @@ class command_core {
if (bot.options.mode === "savageFriends") {
command = `minecraft:fill ${pos.x + start.x} ${pos.y + start.y} ${pos.z + start.z} ${pos.x + end.x} ${pos.y + end.y} ${pos.z + end.z} command_block`;
} else {
command = `minecraft:fill ${pos.x + start.x} ${pos.y + start.y} ${pos.z + start.z} ${pos.x + end.x} ${pos.y + end.y} ${pos.z + end.z} command_block{CustomName:'${JSON.stringify(config.core.name)}'}`;
command = `minecraft:fill ${pos.x + start.x} ${pos.y + start.y} ${pos.z + start.z} ${pos.x + end.x} ${pos.y + end.y} ${pos.z + end.z} command_block{CustomName:${JSON.stringify(config.core.name)}}`;
}
bot.chat.command(command)
},
if (config.core.itemRefill && bot.options.mode !== "savageFriends") {
itemRefill () {
const pos = bot.core.position;
const { start, end } = bot.core.area;
const itemPosition = bot.core.itemPosition;
command = `minecraft:fill ${pos.x + start.x} ${pos.y + start.y} ${pos.z + start.z} ${pos.x + end.x} ${pos.y + end.y} ${pos.z + end.z} command_block{CustomName:${JSON.stringify(config.core.name)}}`;
if (bot.options.mode !== "savageFriends") {
bot._client.write("set_creative_slot", {
slot: 36,
item: Item.toNotch(
@@ -71,8 +79,6 @@ class command_core {
} else {
bot.core.commandBlock(command, itemPosition, 1, 5)
}
} else {
bot.chat.command(`${command}`);
}
},
@@ -89,7 +95,11 @@ class command_core {
z: Math.floor(pos.z),
};
bot.core.refill();
if (bot.options.itemRefill) {
bot.core.itemRefill();
} else {
bot.core.chatRefill()
}
},
currentBlock() {
@@ -127,8 +137,9 @@ class command_core {
},
commandBlock (command, location, mode, flags) {
if (!bot.loggedIn) return;
bot._client.write("update_command_block", {
command: command.substring(0, 32767),
command: command?.substring(0, 32767),
location: location,
mode: mode,
flags: flags,
@@ -136,6 +147,7 @@ class command_core {
},
run(command) {
if (!bot.loggedIn) return;
const location = bot.core.currentBlock();
const itemPosition = bot.core.itemPosition;
+2 -1
View File
@@ -14,7 +14,7 @@ class command_handler {
prefixes.map((prefix) => {
const plainMessage = bot
.getMessageAsPrismarine(data.contents)
?.toMotd();
?.toString();
if (!plainMessage?.startsWith(prefix)) return;
const command = plainMessage.substring(prefix.length);
@@ -22,6 +22,7 @@ class command_handler {
const source = new CommandSource(
data.sender,
{ discord: false, console: false },
data.chatType,
null
);
+2 -2
View File
@@ -12,7 +12,7 @@ class command_loop {
};
this.list.push(timer);
bot.on("end", () => {
/* bot.on("end", () => {
this.clear();
});
@@ -24,7 +24,7 @@ class command_loop {
interval,
};
this.list.push(timer);
});
});*/
},
remove(index) {
+8 -4
View File
@@ -32,7 +32,6 @@ class command_manager {
const options = context.options;
const { MessageBuilder } = require('prismarine-chat')(bot._client.version)
bot.commandManager = {
commands: {},
commandlist: [],
@@ -46,9 +45,11 @@ class command_manager {
)
else source.sendFeedback(unknownCommand(MessageBuilder, commandName, bot))
}
const event = bot.discord.message;
const roles = event?.member?.roles?.cache;
// console.log(command)
// console.log(source)
switch (command?.data?.trustLevel) {
case 0:
@@ -163,7 +164,7 @@ class command_manager {
break
}
if (source.sources.discord) {
/* if (source.sources.discord) {
discordClient.channels.cache
.get("1361739286113685534")
.send(
@@ -175,8 +176,11 @@ class command_manager {
.send(
`User: ${source.player.profile.name}, Command: ${command?.data?.name}, Args: ${args.join(" ")}, Time/Date: ${new Date().toLocaleString("en-us", { TimeZone: "America/Chicago" })}, Source: Minecraft, Server: ${bot.options.host}:${bot.options.port}`,
);
}
}*/
// if (command.playerOnly === true && source.ChatType.find((e) => e)) return;
return command?.execute({
bot,
source,
+46
View File
@@ -0,0 +1,46 @@
class command_spy {
constructor (context) {
const bot = context.bot
bot.on('system_chat', (message) => {
try {
const child = message.extra
const sender = bot.players.find((e) => e?.profile?.name === message.text)?.profile?.name === message.text
if (!child || !message.text || !message.color || !sender) return
const command = child[1].text.substring('/'.length)
if (
(
message.color === 'yellow'
&&
child[0].text === ': '
&&
child[1].text === `/${command}`
&&
sender
)
||
(
message.color === 'aqua'
&&
child[0].text === ': '
&&
child[1].text === `/${command}`
&&
sender
)
) bot.emit('parsed_message', {
sender: bot.players.find((e) => e.profile.name === message.text),
contents: { text: command },
type: "minecraft:chat",
chatType: "command_spy",
displayName: bot.players.find((e) => e.profile.name === message.text).displayName
})
} catch (e) {
console.log(e.stack)
}
})
}
}
module.exports = command_spy;
+7
View File
@@ -0,0 +1,7 @@
class database {
constructor (context) {
}
}
module.exports = database
+8 -18
View File
@@ -9,12 +9,12 @@ class player_list {
bot.on("packet.player_info", async (packet) => {
const actions = [];
if (packet.action & 0b000001) actions.push(addPlayer);
if (packet.action & 0b000010) actions.push(initializeChat);
if (packet.action & 0b000100) actions.push(updateGamemode);
if (packet.action & 0b001000) actions.push(updateListed);
if (packet.action & 0b010000) actions.push(updateLatency);
if (packet.action & 0b100000) actions.push(updateDisplayName);
if (packet.action._value & 0b000001) actions.push(addPlayer);
if (packet.action._value & 0b000010) actions.push(initializeChat);
if (packet.action._value & 0b000100) actions.push(updateGamemode);
if (packet.action._value & 0b001000) actions.push(updateListed);
if (packet.action._value & 0b010000) actions.push(updateLatency);
if (packet.action._value & 0b100000) actions.push(updateDisplayName);
for (const entry of packet.data) {
for (const action of actions) {
@@ -44,6 +44,7 @@ class player_list {
});
function addPlayer(entry) {
console.log
bot.players = bot.players.filter((_entry) => _entry.uuid !== entry.uuid);
bot.players.push({
uuid: entry.uuid,
@@ -59,7 +60,6 @@ class player_list {
displayName: undefined,
vanished: false,
});
// console.log(entry)
}
function initializeChat(entry) {}
@@ -90,17 +90,7 @@ class player_list {
if (!target) return;
try {
if (
bot.options.version === "1.21" ||
bot.options.version === "1.21.1"
) {
target.displayName = convertNbtComponentToJson(
null,
entry.displayName,
);
} else {
target.displayName = JSON.parse(entry.displayName);
}
target.displayName = JSON.parse(entry.displayName);
} catch {
// do nothing
}
+1 -1
View File
@@ -5,7 +5,7 @@ class registry {
const bot = context.bot;
bot.on("packet.login", (packet) => {
bot.registry = createRegistry(bot._client.version);
bot.registry.language = require("../data/language.json");
// bot.registry.language = require("../data/language.json");
bot.emit("registry_ready", bot.registry);
});
}
+53 -33
View File
@@ -6,19 +6,37 @@ class selfcare {
const bot = context.bot
const config = context.config
const options = context.options
let messageSelfcare
let loadMessageSelfcare
bot.selfcare = {
permissionLevel: 2,
entityId: undefined,
gameMode: undefined,
commandSpy: undefined
commandSpy: undefined,
prefix: undefined,
vanished: undefined,
mute: undefined,
username: undefined,
nickname: undefined,
god: undefined,
position_count: 0,
}
for (const file of fs.readdirSync(path.join(__dirname, '../selfcare/message'))) {
let selfcare = [];
for (const file of fs.readdirSync(path.join(__dirname, '../selfcare/extras'))) {
try {
loadMessageSelfcare = require(path.join(__dirname, '../selfcare/message', file))
const extrasSelfcare = require(path.join(__dirname, '../selfcare/extras', file))
selfcare.push(extrasSelfcare)
} catch (e) {
console.error(e.stack)
}
}
for (const file of fs.readdirSync(path.join(__dirname, '../selfcare/essentials'))) {
try {
const essentialsSelfcare = require(path.join(__dirname, '../selfcare/essentials', file))
selfcare.push(essentialsSelfcare)
} catch (e) {
console.error(e.stack)
}
@@ -27,50 +45,52 @@ class selfcare {
for (const file of fs.readdirSync(path.join(__dirname, '../selfcare/entity'))) {
try {
const loadEntitySelfcare = require(path.join(__dirname, '../selfcare/entity', file))
const entitySelfcare = new loadEntitySelfcare({ bot, config, options })
new loadEntitySelfcare({ bot, config, options })
} catch (e) {
console.error(e.stack)
}
} // how the fuck do i want to implement this...
}
bot.on('message', (message) => {
bot.on('system_chat', (message) => {
const stringMessage = bot.getMessageAsPrismarine(message)?.toString()
//new loadMessageSelfcare({ bot, options, config, stringMessage })
for (const file of selfcare) new file({ bot, config, options, stringMessage })
})
let timer;
bot.on('packet.login', (data) => {
bot.selfcare.entityId = data.entityId;
if (bot.options.version === "1.21" || bot.options.version === "1.21.1") {
switch (data.worldState.gamemode) {
case "survival":
bot.selfcare.gameMode = 0;
break;
case "creative":
gameMode = 1;
break;
case "adventure":
bot.selfcare.gameMode = 2;
break;
case "spectator":
bot.selfcare.gameMode = 3;
break;
default:
bot.selfcare.gameMode = 0;
break;
}
} else {
bot.selfcare.gameMode = data.gameMode;
}
bot.selfcare.gameMode = data.gameMode;
timer = setInterval(() => {
if (bot.selfcare.permissionLevel < 2) bot.chat.command('minecraft:op @s[type=player]')
else if (bot.selfcare.gameMode !== 1) bot.chat.command('minecraft:gamemode creative')
//else if (!bot.selfcare.commandSpy) bot.core.run(`commandspy ${bot.uuid} on`)
if (bot.options.mode === "savageFriends") {
} else {
if (!bot.selfcare.prefix) bot.chat.command(`extras:prefix &8[&bPrefix&8: &3${config.prefixes[0]}&8]`);
else if (bot.selfcare.permissionLevel < 2) bot.chat.command('minecraft:op @s[type=player]')
else if (bot.selfcare.username) bot.chat.command(`extras:username ${bot._client.username}`)
else if (bot.selfcare.gameMode !== 1) bot.chat.command('minecraft:gamemode creative')
else if (!bot.selfcare.commandSpy) bot.core.run(`commandspy ${bot.uuid} on`)
else if (!bot.selfcare.vanished) bot.core.run(`essentials:vanish ${bot._client.username} on`)
else if (!bot.selfcare.god) bot.core.run(`essentials:god ${bot._client.username} on`)
else if (bot.selfcare.mute) bot.core.run(`essentials:mute ${bot._client.uuid}`)
else if (bot.selfcare.nickname) bot.core.run(`essentials:nickname ${bot._client.username} off`)
}
}, options.selfcareInterval)
})
bot.on('end', () => {
if (timer) clearInterval(timer)
bot.selfcare.commandSpy = false
bot.selfcare.prefix = false
bot.selfcare.vanished = false
bot.selfcare.mute = false
bot.selfcare.username = false
bot.selfcare.nickname = false
bot.selfcare.god = false
})
}
}