Class O2Books

java.lang.Object
net.pottercraft.ollivanders2.book.O2Books
All Implemented Interfaces:
org.bukkit.event.Listener

public final class O2Books extends Object implements org.bukkit.event.Listener
Manages all Ollivanders2 magic books and handles book learning mechanics.

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

    Constructors
    Constructor
    Description
    O2Books(@NotNull Ollivanders2 plugin)
    Constructor that initializes the O2Books manager.
  • Method Summary

    Modifier and Type
    Method
    Description
    @NotNull List<org.bukkit.inventory.ItemStack>
    Returns a list of ItemStacks for all available Ollivanders2 books.
    @NotNull List<String>
    Returns all book titles, sorted alphabetically.
    @Nullable org.bukkit.inventory.ItemStack
    getBookByTitle(@NotNull String title)
    Returns a book item for the book with the given title.
    @Nullable org.bukkit.inventory.ItemStack
    getBookByType(@NotNull O2BookType bookType)
    Returns a book item for the given book type.
    @Nullable O2BookType
    Retrieves a book type by its title using case-insensitive, partial matching.
    void
    onBookRead(@NotNull org.bukkit.event.player.PlayerInteractEvent event)
    Process book read events when bookLearning is enabled.
    void
    Cleanup when the plugin disables.
    void
    Load all books on plugin enable.
    boolean
    runCommand(@NotNull org.bukkit.command.CommandSender sender, @NotNull String[] args)
    Handles the /olli books subcommands.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • O2Books

      public O2Books(@NotNull @NotNull Ollivanders2 plugin)
      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

      @Nullable public @Nullable O2BookType getBookTypeByTitle(String title)
      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

      @NotNull public @NotNull List<org.bukkit.inventory.ItemStack> 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

      @NotNull public @NotNull List<String> 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 sender
      args - the command arguments (args[1] is the subcommand)
      Returns:
      always true
      Since:
      2.2.4