summaryrefslogtreecommitdiffstats
path: root/src/Protocol
diff options
context:
space:
mode:
authorLukas Pioch <lukas@zgow.de>2017-08-23 18:09:47 +0200
committerLukas Pioch <lukas@zgow.de>2017-08-27 17:49:08 +0200
commita5bae9f2f37921bfcf6203282155a8779c818120 (patch)
treeb51bcc42cdc65fd7d0d76fd312216ec0720c706a /src/Protocol
parentAdded a new param to OnPlayerEditingBook and changed the names (diff)
downloadcuberite-books.tar
cuberite-books.tar.gz
cuberite-books.tar.bz2
cuberite-books.tar.lz
cuberite-books.tar.xz
cuberite-books.tar.zst
cuberite-books.zip
Diffstat (limited to 'src/Protocol')
-rw-r--r--src/Protocol/Protocol_1_9.cpp32
1 files changed, 18 insertions, 14 deletions
diff --git a/src/Protocol/Protocol_1_9.cpp b/src/Protocol/Protocol_1_9.cpp
index 712658329..8e43fd2cc 100644
--- a/src/Protocol/Protocol_1_9.cpp
+++ b/src/Protocol/Protocol_1_9.cpp
@@ -2966,20 +2966,24 @@ void cProtocol_1_9_0::HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, con
BookItem = cItem(E_ITEM_BOOK_AND_QUILL);
cBookContent::ParseFromNBT(0, BookItem.m_BookContent, NBT);
}
+ BookItem.m_BookContent.SetIsSigned(IsSigned);
// The equipped item contains the old book content
if (cRoot::Get()->GetPluginManager()->CallHookPlayerEditingBook(Player, Player.GetEquippedItem().m_BookContent, BookItem.m_BookContent, IsSigned))
{
- // Plugin denied the editing of the book
+ // Plugin denied the player to edit the book
+ cInventory & inv = Player.GetInventory();
+ inv.SetHotbarSlot(inv.GetEquippedSlotNum(), BookItem);
+ Player.GetInventory().SendEquippedSlot();
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);
Player.GetInventory().SendEquippedSlot();
+
+ // Book has been edited by player, inform plugins
+ cRoot::Get()->GetPluginManager()->CallHookPlayerEditedBook(Player, BookItem.m_BookContent, IsSigned);
return;
}
LOG("Unhandled vanilla plugin channel: \"%s\".", a_Channel.c_str());
@@ -3418,9 +3422,9 @@ void cProtocol_1_9_0::WriteItem(cPacketizer & a_Pkt, const cItem & a_Item)
return;
}
- if ((ItemType == E_ITEM_BOOK_AND_QUILL) && (a_Item.m_BookContent.GetPages().size() == 0))
+ if ((ItemType == E_ITEM_BOOK_AND_QUILL) && a_Item.m_BookContent.GetPages().empty())
{
- // Don't send any nbt tag if the book is writeable and has no pages
+ // Don't send any nbt tag if the book is not signed 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;
@@ -3539,24 +3543,24 @@ void cProtocol_1_9_0::WriteItem(cPacketizer & a_Pkt, const cItem & a_Item)
{
if (a_Item.m_ItemType == E_ITEM_WRITTEN_BOOK)
{
- // Only send author and title for a signed book
+ // Only send author and title if the book is signed
Writer.AddString("author", a_Item.m_BookContent.GetAuthor());
Writer.AddString("title", a_Item.m_BookContent.GetTitle());
}
- if (a_Item.m_BookContent.GetPages().size() > 0)
+ if (a_Item.m_BookContent.GetPages().empty())
{
+ // A signed book, has a empty page
Writer.BeginList("pages", TAG_String);
- for (auto & Page : a_Item.m_BookContent.GetPages())
- {
- Writer.AddString("", Page);
- }
+ Writer.AddString("", "");
Writer.EndList();
}
else
{
- // A signed book, has a empty page
Writer.BeginList("pages", TAG_String);
- Writer.AddString("", "");
+ for (const auto & Page : a_Item.m_BookContent.GetPages())
+ {
+ Writer.AddString("", Page);
+ }
Writer.EndList();
}
}