minecraft-pi-reborn/example-mods/chat-commands/chat-commands.cpp

26 lines
812 B
C++
Raw Normal View History

2022-06-27 01:17:52 +00:00
// Headers
#include <libreborn/libreborn.h>
#include <symbols/minecraft.h>
#include <mods/chat/chat.h>
#include <mods/misc/misc.h>
// The Actual Mod
2024-09-21 05:49:47 +00:00
HOOK(chat_handle_packet_send, void, (const Minecraft *minecraft, ChatPacket *packet)) {
2022-06-27 01:17:52 +00:00
// Get Message
2024-03-19 04:25:50 +00:00
const char *message = packet->message.c_str();
2022-06-27 01:17:52 +00:00
if (message[0] == '/') {
// API Command
2024-09-21 05:49:47 +00:00
Minecraft *mc = (Minecraft *) minecraft;
Gui *gui = &mc->gui;
std::string out = chat_send_api_command(mc, (char *) &message[1]);
2022-06-27 01:17:52 +00:00
if (out.length() > 0 && out[out.length() - 1] == '\n') {
out[out.length() - 1] = '\0';
}
2024-07-15 07:09:19 +00:00
gui->addMessage(out);
2022-06-27 01:17:52 +00:00
} else {
// Call Original Method
2024-05-05 06:17:46 +00:00
ensure_chat_handle_packet_send();
real_chat_handle_packet_send(minecraft, packet);
2022-06-27 01:17:52 +00:00
}
}