diff options
author | Lukas Pioch <lukas@zgow.de> | 2017-07-28 12:11:07 +0200 |
---|---|---|
committer | Lukas Pioch <lukas@zgow.de> | 2017-08-27 14:54:40 +0200 |
commit | c171b272d96453f1a9d13d4623ac4bd3aa7d19e8 (patch) | |
tree | 32828d71b3de14de7489b080f07066dcf49e913e /src/Protocol/Protocol_1_9.cpp | |
parent | Implement anvil chunk sparsing (diff) | |
download | cuberite-c171b272d96453f1a9d13d4623ac4bd3aa7d19e8.tar cuberite-c171b272d96453f1a9d13d4623ac4bd3aa7d19e8.tar.gz cuberite-c171b272d96453f1a9d13d4623ac4bd3aa7d19e8.tar.bz2 cuberite-c171b272d96453f1a9d13d4623ac4bd3aa7d19e8.tar.lz cuberite-c171b272d96453f1a9d13d4623ac4bd3aa7d19e8.tar.xz cuberite-c171b272d96453f1a9d13d4623ac4bd3aa7d19e8.tar.zst cuberite-c171b272d96453f1a9d13d4623ac4bd3aa7d19e8.zip |
Diffstat (limited to 'src/Protocol/Protocol_1_9.cpp')
-rw-r--r-- | src/Protocol/Protocol_1_9.cpp | 101 |
1 files changed, 100 insertions, 1 deletions
diff --git a/src/Protocol/Protocol_1_9.cpp b/src/Protocol/Protocol_1_9.cpp index 7fc6cf5f1..f49a942b8 100644 --- a/src/Protocol/Protocol_1_9.cpp +++ b/src/Protocol/Protocol_1_9.cpp @@ -263,6 +263,17 @@ void cProtocol_1_9_0::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlo +void cProtocol_1_9_0::SendOpenBook(const short a_Hand) +{ + cPacketizer Pkt(*this, 0x18); // Plugin Channel + Pkt.WriteString("MC|BOpen"); + Pkt.WriteVarInt32(static_cast<UInt32>(a_Hand)); +} + + + + + void cProtocol_1_9_0::SendCameraSetTo(const cEntity & a_Entity) { cPacketizer Pkt(*this, 0x36); // Camera Packet (Attach the camera of a player at another entity in spectator mode) @@ -2917,6 +2928,55 @@ void cProtocol_1_9_0::HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, con m_Client->HandleNPCTrade(SlotNum); return; } + else if ((a_Channel == "MC|BSign") || (a_Channel == "MC|BEdit")) + { + HANDLE_READ(a_ByteBuffer, ReadBEInt16, Int16, ItemID); + if (ItemID != E_ITEM_BOOK_AND_QUILL) + { + // Item is not a writeable book + return; + } + + // Skip item count (1 byte) and item damage (2 bytes) + a_ByteBuffer.SkipRead(3); + + // Read nbt content + AString BookData; + a_ByteBuffer.ReadString(BookData, a_ByteBuffer.GetReadableSpace() - 1); + cParsedNBT NBT(BookData.c_str(), BookData.size()); + + cItem BookItem; + if (a_Channel == "MC|BSign") + { + BookItem = cItem(E_ITEM_WRITTEN_BOOK); + // Add the text to a json string + cBookContent::ParseFromNBT(0, BookItem.m_BookContent, NBT, true); + } + else + { + BookItem = cItem(E_ITEM_BOOK_AND_QUILL); + cBookContent::ParseFromNBT(0, BookItem.m_BookContent, NBT); + } + + cPlayer * Player = m_Client->GetPlayer(); + + // If true, player has clicked on the sign button + bool IsSigned = (BookItem.m_ItemType == E_ITEM_WRITTEN_BOOK) ? true : false; + + if (cRoot::Get()->GetPluginManager()->CallHookPlayerEditingBook(*Player, BookItem.m_BookContent, IsSigned)) + { + // Plugin denied the editing of the book + return; + } + + // Book has been edited, inform plugins + cRoot::Get()->GetPluginManager()->CallHookPlayerEditedBook(*Player, BookItem.m_BookContent, IsSigned); + + cInventory & inv = Player->GetInventory(); + inv.SetHotbarSlot(inv.GetEquippedSlotNum(), BookItem); + SendWholeInventory(*Player->GetWindow()); // TODO: Use SendSlot + return; + } LOG("Unhandled vanilla plugin channel: \"%s\".", a_Channel.c_str()); // Read the payload and send it through to the clienthandle: @@ -3334,12 +3394,26 @@ void cProtocol_1_9_0::WriteItem(cPacketizer & a_Pkt, const cItem & a_Item) a_Pkt.WriteBEInt16(a_Item.m_ItemDamage); } - if (a_Item.m_Enchantments.IsEmpty() && a_Item.IsBothNameAndLoreEmpty() && (ItemType != E_ITEM_FIREWORK_ROCKET) && (ItemType != E_ITEM_FIREWORK_STAR) && !a_Item.m_ItemColor.IsValid() && (ItemType != E_ITEM_POTION) && (ItemType != E_ITEM_SPAWN_EGG)) + if ( + a_Item.m_Enchantments.IsEmpty() && + a_Item.IsBothNameAndLoreEmpty() && + (ItemType != E_ITEM_FIREWORK_ROCKET) && (ItemType != E_ITEM_FIREWORK_STAR) && + !a_Item.m_ItemColor.IsValid() && + (ItemType != E_ITEM_POTION) && + (ItemType != E_ITEM_SPAWN_EGG) && + (ItemType != E_ITEM_WRITTEN_BOOK) && (ItemType != E_ITEM_BOOK_AND_QUILL)) { a_Pkt.WriteBEInt8(0); return; } + if ((ItemType == E_ITEM_BOOK_AND_QUILL) && (a_Item.m_BookContent.GetPages().size() == 0)) + { + // Don't send any nbt tag if the book is writeable and has no pages + // If a tag with a empty pages list is send, the player can't enter anything + a_Pkt.WriteBEInt8(0); + return; + } // Send the enchantments and custom names: cFastNBTWriter Writer; @@ -3450,6 +3524,31 @@ void cProtocol_1_9_0::WriteItem(cPacketizer & a_Pkt, const cItem & a_Item) Writer.EndCompound(); } } + if ((a_Item.m_ItemType == E_ITEM_WRITTEN_BOOK) || (a_Item.m_ItemType == E_ITEM_BOOK_AND_QUILL)) + { + if (a_Item.m_ItemType == E_ITEM_WRITTEN_BOOK) + { + // Only send author and title for a signed book + Writer.AddString("author", a_Item.m_BookContent.GetAuthor()); + Writer.AddString("title", a_Item.m_BookContent.GetTitle()); + } + if (a_Item.m_BookContent.GetPages().size() > 0) + { + Writer.BeginList("pages", TAG_String); + for (auto & Page : a_Item.m_BookContent.GetPages()) + { + Writer.AddString("", Page); + } + Writer.EndList(); + } + else + { + // A signed book, has a empty page + Writer.BeginList("pages", TAG_String); + Writer.AddString("", ""); + Writer.EndList(); + } + } Writer.Finish(); |