Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented books #3877

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
175 changes: 174 additions & 1 deletion Server/Plugins/APIDump/APIDesc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6936,14 +6936,19 @@ These ItemGrids are available in the API and can be manipulated by the plugins,
},
Variables =
{
m_BookContent =
{
Type = "cBookContent",
Notes = "If it's a written or a writeable book, it contains the information of the book: Author, title and pages",
},
m_CustomName =
{
Type = "string",
Notes = "The custom name for an item.",
},
m_Enchantments =
{
Type = "{{cEnchantments|cEnchantments}}}",
Type = "cEnchantments",
Notes = "The enchantments of the item.",
},
m_ItemCount =
Expand Down Expand Up @@ -7014,6 +7019,174 @@ local Item5 = cItem(E_ITEM_DIAMOND_CHESTPLATE, 1, 0, "thorns=1;unbreaking=3");
},
},
},
cBookContent =
{
Desc = [[
This class contains the information for a signed or writeable book: The author, title and the pages. A page of the writeable book is a simple string. For a signed book it can be a json string. Use {{cCompositeChat}} to create a more complex page with formatting.
]],
Functions =
{
AddPage =
{
{
Params =
{
{
Name = "Page",
Type = "string",
},
},
Notes = "Add a page to the end of the book",
},
{
Params =
{
{
Name = "Page",
Type = "cCompositeChat",
},
},
Notes = "Add a page to the end of the book. For signed book saves it as json string, otherwise as simple string",
}
},
Clear =
{
Notes = "Clears the whole book",
},
constructor =
{
Returns =
{
{
Type = "cBookContent",
},
},
Notes = "Creates a empty book",
},
GetAuthor =
{
Returns =
{
{
Type = "string",
},
},
Notes = "Returns the author of the book",
},
GetTitle =
{
Returns =
{
{
Type = "string",
},
},
Notes = "Returns the title of the book",
},
GetPage =
{
Params =
{
{
Type = "number",
},
},
Returns =
{
{
Type = "string",
},
},
Notes = "Returns the page at the given index, can be a json string or a simple string. Note: one-based",
},
GetPages =
{
Returns =
{
{
Type = "table",
},
},
Notes = "Returns the pages of the book as a table",
},
IsEmpty =
{
Returns =
{
{
Type = "boolean",
},
},
Notes = "Returns true if the book has no author, title and no pages",
},
SetAuthor =
{
Params =
{
{
Name = "Author",
Type = "string",
},
},
Notes = "Set the author of the book",
},
SetPage =
{
{
Params =
{
{
Name = "Index",
Type = "number",
},
{
Name = "Page",
Type = "string",
},
},
Notes = "Set's the page at the given index. Note: one-based",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sets

},
{
Params =
{
{
Name = "Index",
Type = "number",
},
{
Name = "Page",
Type = "cCompositeChat",
},
},
Notes = "Set's the page at the given index. For signed book saves it as json string, otherwise as simple string. Note: one-based",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sets

},
},
SetPages =
{
{
Params =
{
{
Name = "Pages",
Type = "table",
},
},
Notes = "Sets all pages of the book. A entry can be a string or a {{cCompositeChat}}",
},
},
SetTitle =
{
Params =
{
{
Name = "Title",
Type = "string",
},
},
Notes = "Set the title of the book",
},
},
},
cItemFrame =
{
Functions =
Expand Down
8 changes: 8 additions & 0 deletions Server/Plugins/APIDump/Classes/Plugins.lua
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,14 @@ cPluginManager.AddHook(cPluginManager.HOOK_CHAT, OnChatMessage);
{
Notes = "Called when the player starts eating a held item. Plugins may abort the eating.",
},
HOOK_PLAYER_EDITED_BOOK =
{
Notes = "This hook is called whenever a {{cPlayer|player}} has edited a book.",
},
HOOK_PLAYER_EDITING_BOOK =
{
Notes = "This hook is called whenever a {{cPlayer|player}} is editing a book."
},
HOOK_PLAYER_FISHED =
{
Notes = "Called when the player reels the fishing rod back in, after the server decides the player's fishing reward.",
Expand Down
27 changes: 27 additions & 0 deletions Server/Plugins/APIDump/Hooks/OnPlayerEditedBook.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
return
{
HOOK_PLAYER_EDITED_BOOK =
{
CalledWhen = "A player has edited a book.",
DefaultFnName = "OnPlayerEditedBook", -- also used as pagename
Desc = [[
This hook is called whenever a {{cPlayer|player}} has edited a book.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whenever -> after

See also the {{OnPlayerEditingBook|HOOK_PLAYER_EDITING_BOOK}} hook for a similar hook, is called when a
player is editing a book.
]],
Params =
{
{ Name = "Player", Type = "cPlayer", Notes = "The player that edited the book" },
{ Name = "NewContent", Type = "cBookContent", Notes = "Contains the new content of the book" },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should have the OldContent parameter, too.

{ Name = "IsSigned", Type = "boolean", Notes = "Player has signed the book" },
},
Returns = [[
If the function returns false or no value, Cuberite calls other plugins with this event. If the
function returns true, no other plugin is called for this event.</p>
]],
}, -- HOOK_PLAYER_EDITED_BOOK
}




28 changes: 28 additions & 0 deletions Server/Plugins/APIDump/Hooks/OnPlayerEditingBook.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
return
{
HOOK_PLAYER_EDITING_BOOK =
{
CalledWhen = "A player is editing a book.",
DefaultFnName = "OnPlayerEditingBook", -- also used as pagename
Desc = [[
This hook is called whenever a {{cPlayer|player}} is editing a book.
See also the {{OnPlayerEditingBook|HOOK_PLAYER_EDITED_BOOK}} hook for a similar hook, is called when a
player has edited a book.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the note that the plugin may override the player edits by changing the NewContent parameter

]],
Params =
{
{ Name = "Player", Type = "cPlayer", Notes = "The player that is editing the book" },
{ Name = "OriginalContent", Type = "cBookContent", Notes = "Contains the original content of the book" },
{ Name = "NewContent", Type = "cBookContent", Notes = "Contains the new content of the book" },
{ Name = "IsSigned", Type = "boolean", Notes = "Player is signing the book" },
},
Returns = [[
If the function returns false or no value, Cuberite calls other plugins with this event. If the function returns true,
no other plugin's callback is called and the editing of the book is denied.
]],
}, -- HOOK_PLAYER_EDITING_BOOK
}




2 changes: 2 additions & 0 deletions src/Bindings/AllToLua.pkg
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ $cfile "../Scoreboard.h"
$cfile "../Statistics.h"
$cfile "../Protocol/MojangAPI.h"
$cfile "../UUID.h"
$cfile "../BookContent.h"


// Entities:
$cfile "../Entities/Entity.h"
Expand Down
1 change: 1 addition & 0 deletions src/Bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ set(BINDING_DEPENDENCIES
../BlockEntities/FlowerPotEntity.h
../BlockID.h
../BlockInfo.h
../BookContent.h
../BoundingBox.h
../ChatColor.h
../ChunkDef.h
Expand Down
11 changes: 11 additions & 0 deletions src/Bindings/LuaState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,17 @@ void cLuaState::Push(const AStringVector & a_Vector)



void cLuaState::Push(const cBookContent & a_Content)
{
ASSERT(IsValid());
auto c = new cBookContent(a_Content);
tolua_pushusertype_and_takeownership(m_LuaState, c, "cBookContent");
}





void cLuaState::Push(const char * a_Value)
{
ASSERT(IsValid());
Expand Down
1 change: 1 addition & 0 deletions src/Bindings/LuaState.h
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,7 @@ class cLuaState
void Push(const AString & a_String);
void Push(const AStringMap & a_Dictionary);
void Push(const AStringVector & a_Vector);
void Push(const cBookContent & a_Content);
void Push(const char * a_Value);
void Push(const cItem & a_Item);
void Push(const cNil & a_Nil);
Expand Down
Loading