Class O2Books
- All Implemented Interfaces:
org.bukkit.event.Listener
When bookLearning is enabled, reading a book will increase the reader's spell level by 1 to a maximum of 10. This can be used for classes, creating lessons, or other in-game magic learning.
When bookLearning is enabled, every Ollivanders2 spell must be in a WrittenBook with lore or NBT set up correctly or players will not be able to learn them.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionO2Books(@NotNull Ollivanders2 plugin) Constructor that initializes the O2Books manager. -
Method Summary
Modifier and TypeMethodDescription@NotNull List<org.bukkit.inventory.ItemStack> Returns a list of ItemStacks for all available Ollivanders2 books.Returns all book titles, sorted alphabetically.@Nullable org.bukkit.inventory.ItemStackgetBookByTitle(@NotNull String title) Returns a book item for the book with the given title.@Nullable org.bukkit.inventory.ItemStackgetBookByType(@NotNull O2BookType bookType) Returns a book item for the given book type.@Nullable O2BookTypegetBookTypeByTitle(String title) Retrieves a book type by its title using case-insensitive, partial matching.voidonBookRead(@NotNull org.bukkit.event.player.PlayerInteractEvent event) Process book read events when bookLearning is enabled.voidCleanup when the plugin disables.voidonEnable()Load all books on plugin enable.booleanrunCommand(@NotNull org.bukkit.command.CommandSender sender, @NotNull String[] args) Handles the /olli books subcommands.
-
Constructor Details
-
O2Books
Constructor that initializes the O2Books manager.Initializes book text management, common utilities, and registers this class as a Bukkit event listener to handle book learning events.
- Parameters:
plugin- the Ollivanders2 plugin instance
-
-
Method Details
-
onEnable
public void onEnable()Load all books on plugin enable.This needs to be run after spells and potions are loaded or the text for these will not be loaded.
-
onDisable
public void onDisable()Cleanup when the plugin disables.Called when the Ollivanders2 plugin is being shut down. The O2Books manager performs no cleanup on disable because book data is read-only and does not require persistence. The book map will be repopulated when the plugin is re-enabled via onEnable().
-
onBookRead
public void onBookRead(@NotNull @NotNull org.bukkit.event.player.PlayerInteractEvent event) Process book read events when bookLearning is enabled.- Parameters:
event- the player interact event
-
getBookByTitle
@Nullable public @Nullable org.bukkit.inventory.ItemStack getBookByTitle(@NotNull @NotNull String title) Returns a book item for the book with the given title.- Parameters:
title- the title of the book to retrieve- Returns:
- an ItemStack representing the book, or null if not found
-
getBookByType
@Nullable public @Nullable org.bukkit.inventory.ItemStack getBookByType(@NotNull @NotNull O2BookType bookType) Returns a book item for the given book type.- Parameters:
bookType- the type of book to retrieve- Returns:
- an ItemStack representing the book, or null if creation failed
-
getBookTypeByTitle
Retrieves a book type by its title using case-insensitive, partial matching.Supports case-insensitive lookup and allows partial title matching to accommodate users not typing the full title.
- Parameters:
title- the book title or partial title to search for- Returns:
- the book type if a match is found, null otherwise
-
getAllBooks
Returns a list of ItemStacks for all available Ollivanders2 books.- Returns:
- a list of book ItemStacks for all book types, empty if none found
-
getAllBookTitles
Returns all book titles, sorted alphabetically.- Returns:
- a sorted list of all book titles
-
runCommand
public boolean runCommand(@NotNull @NotNull org.bukkit.command.CommandSender sender, @NotNull @NotNull String[] args) Handles the /olli books subcommands.Supports: "allbooks" - gives all books, "list" - shows book list, "give [player] [title]" - gives a book to a player, or directly retrieve a book by title.
- Parameters:
sender- the command senderargs- the command arguments (args[1] is the subcommand)- Returns:
- always true
- Since:
- 2.2.4
-