From 71e694ae3629664cff7dc71150395c1fca7d0505 Mon Sep 17 00:00:00 2001 From: Ibrahim Ansari Date: Mon, 31 Jan 2022 19:04:48 +0530 Subject: [PATCH] Add HoverEvent type, close inventories on open. Should avoid EnderChat triggering false positives with anti-cheats. --- src/minecraft/chatToJsx.tsx | 8 +++++++- src/screens/ChatScreen.tsx | 11 ++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/minecraft/chatToJsx.tsx b/src/minecraft/chatToJsx.tsx index 26cea95..d302cd6 100644 --- a/src/minecraft/chatToJsx.tsx +++ b/src/minecraft/chatToJsx.tsx @@ -60,7 +60,7 @@ export interface BaseChat { extra?: PlainTextChat[] insertion?: string clickEvent?: ClickEvent - // HoverEvent unsupported atm. + hoverEvent?: HoverEvent } export interface PlainTextChat extends BaseChat { @@ -85,6 +85,12 @@ export interface ClickEvent { value: string } +// LOW-TODO: How can we display this in EnderChat? +export interface HoverEvent { + action: 'show_text' | 'show_item' | 'show_entity' | 'show_achievement' // <1.12 + value: MinecraftChat +} + const hasColorCodes = (s: string) => /§[0-9a-fk-orx]/.test(s) // const stripColorCodes = (s: string) => s.replace(/§[0-9a-fk-orx]/g, '').trim() const parseColorCodes = (arg: string | PlainTextChat): PlainTextChat[] => { diff --git a/src/screens/ChatScreen.tsx b/src/screens/ChatScreen.tsx index 2ee98a1..0a868a8 100644 --- a/src/screens/ChatScreen.tsx +++ b/src/screens/ChatScreen.tsx @@ -82,6 +82,7 @@ const errorHandler = ( } const sendMessageErr = 'Failed to send message to server!' const parseMessageErr = 'An error occurred when parsing chat.' +const inventoryCloseErr = 'An error occurred when closing an inventory window.' let id = 0 // TODO: Ability to copy text. @@ -127,7 +128,7 @@ const ChatScreen = ({ navigation }: { navigation: ChatNavigationProp }) => { .writePacket(0x03, concatPacketData(['/spawn'])) .catch(errorHandler(addMessage, sendMessageErr)) } - } else if (packet.id === 0x0f) { + } else if (packet.id === 0x0f /* Chat Message (clientbound) */) { try { const [chatLength, chatVarIntLength] = readVarInt(packet.data) const chatJson = packet.data @@ -141,6 +142,14 @@ const ChatScreen = ({ navigation }: { navigation: ChatNavigationProp }) => { } catch (e) { errorHandler(addMessage, parseMessageErr)(e) } + } else if (packet.id === 0x2e /* Open Window */) { + // Just close the window. + const [windowId] = readVarInt(packet.data) + const buf = Buffer.alloc(1) + buf.writeUInt8(windowId) + connection.connection // Close Window (serverbound) + .writePacket(0x09, buf) + .catch(errorHandler(addMessage, inventoryCloseErr)) } }) return () => {