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

25 lines
762 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-01-07 01:36:59 +00:00
HOOK(chat_handle_packet_send, void, (Minecraft *minecraft, ChatPacket *packet)) {
2022-06-27 01:17:52 +00:00
// Get Message
2024-01-07 01:36:59 +00:00
char *message = packet->message;
2022-06-27 01:17:52 +00:00
if (message[0] == '/') {
// API Command
2024-01-07 01:36:59 +00:00
Gui *gui = &minecraft->gui;
2022-06-27 01:17:52 +00:00
std::string out = chat_send_api_command(minecraft, &message[1]);
if (out.length() > 0 && out[out.length() - 1] == '\n') {
out[out.length() - 1] = '\0';
}
misc_add_message(gui, out.c_str());
} else {
// Call Original Method
ensure_chat_handle_packet_send();
2024-01-07 08:23:43 +00:00
real_chat_handle_packet_send(minecraft, packet);
2022-06-27 01:17:52 +00:00
}
}