Sueta

Fredashay's Books

2023-11-11

This plugin generates Minecraft books from text files on your server.

·Plugin
  1. 2023-11-11latestUpdated for 1.20Nov 11, 2023
    Updated for Minecraft 1.20.
  2. 3.1The event PlayerJoinEvent is being fired twice each time a player joins the server. This bug is...Dec 19, 2020
    ...is breaking some of my plugins. Starting with Minecraft 1.16.4, the event PlayerJoinEvent is bing fired twice each time a player joins the game, causing my WelcomeBook plugin to give a new player two Welcome Books. I fixed this by checking if a brand new player already has a Welcome Book before giving him one. Since this Book plugin is a dependency for WelcomeBook, I though it a good idea to refresh this one as well just to be safe :-/
    132 downloads
  3. 3.0Recompiled for 1.16Dec 19, 2020
    Recompiled for 1.16
    35 downloads
  4. 2017-09-30general improvementsSep 30, 2017
    This plugin generates Minecraft books from text files on your server. Your can use it to create rule books for your server that your players can obtain, or whatever else warps your starship. You create one or more text files in your Minecraft folder similar to: book(bookname).txt Where bookname can be any name, but cannot contain spaces (not even on systems that allow filenames to contain spaces) because the player has to be able to type the book name as a single word to the /BOOK command. If you name a book file book(my story).txt the player will type /BOOK MY STORY and the plugin will try to load book(my).txt, so don't put spaces in filenames! Your players can type /BOOK BOOKNAME to load any book into their inventory. The book command is not case sensitive, so they can type /book bookname or /BOOK BOOKNAME or /BoOk BoOkNaMe to get the book. If a player types just /BOOK it will list all available books; that is, all files that follow the standard: book(*).txt. And if no books exist, the plugin will create an example book for you to edit. The book file is just a text file that you can edit with Notepad. Do not use a word processor like MS Word or Wordpad! The book file must be a pure text file. A book file looks like this: ^T Book Title ^A Author Name ^C Chapter Title ^P Paragraph ^P Another paragraph ^P Yet another paragraph ^C Another Chapter Title ^P Paragraph ^P Another paragraph ^P Yet another paragraph ^B A line break The book title is the title of the book in Minecraft. The plugin will create a "title page" for your book containing the title, author, and date, just like a real book. Each chapter title forces a new page. If a chapter exceeds the page, it will start a new page automagically. Each paragraph forces a blank line and starts on a new line. You can insert funky characters using the percent % symbol like this: %25 or %5E. This is how you could type a % or a ^ into the text of your book. If you want to add features and fix bugs, go ahead. I included the Java source for just that reason. Code (Text): package FredashaySpigotBook; import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; import java.sql.Date; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.List; import java.util.logging.Logger; import org.bukkit.Material; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.event.Listener; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; import org.bukkit.inventory.meta.BookMeta; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.java.JavaPlugin; public class MyPlugin extends JavaPlugin implements Listener, CommandExecutor { private static Logger logger = null; private static PluginDescriptionFile pdfFile = null; final static char CRLF = (char) 0x0a; final static int pageWidth = 114; final static int PageLines = 13; final static int pageChars = 240; @Override public void onEnable() { logger = Logger.getLogger("Minecraft"); pdfFile = getDescription(); getServer().getPluginManager().registerEvents(this,this); } @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { String fileName = null; String bookText = null; String title = null; String author = null; long fileDate = 0; String bookPages[] = null; File dir = null; File files[] = null; File file = null; int index = 0; int books = 0; if (label.equalsIgnoreCase("book")) { if (!(sender instanceof Player)) { sender.sendMessage("[" + pdfFile.getName() + "] This command can only be issued by a player in the game. "); return (false); } Player player = (Player) sender; if (args.length > 0) { fileName = getFileName(args[0].toLowerCase().trim()); if (fileName == null) { player.sendMessage("<BOOK> Oops! Book, '" + args[0] + "' does not exist. "); } else { bookText = readBook(fileName, player); bookText = scanBook(bookText); fileDate = getFileDate(fileName); title = getTitle(bookText); author = getAuthor(bookText); bookPages = formatBook(bookText, fileDate); ItemStack myBook = createBook(title, author, bookPages); giveItemToPlayer(player, myBook, title); } } else { dir = new File("."); files = dir.listFiles(); index = 0; books = 0; while (index < files.length) { file = files[index]; if (file.isFile()) { fileName = file.getName(); if ((fileName.startsWith("book(")) && (fileName.endsWith(").txt"))) { if (fileName.indexOf('(') + 1 < fileName.indexOf(')')) { if (!fileName.contains(" ")) { if (books == 0) { player.sendMessage("<BOOK> The following books are available: "); } books = books + 1; title = fileName.substring(fileName.indexOf('(') + 1, fileName.indexOf(')')); player.sendMessage(" " + title); } } } } index = index + 1; } if (books == 0) { writeExampleBook(); player.sendMessage("<BOOK> No books are available. I created an example book 'Example' for you to use to start making your own books. Look in your server folder for it. You can edit it with Notepad or vi. "); } } return (true); } return (false); } private String getFileName(String bookName) { String fileName = null; String searchName = null; File dir = null; File files[] = null; File file = null; int index = 0; fileName = null; dir = new File("."); files = dir.listFiles(); index = 0; searchName = ""; while (index < files.length) { file = files[index]; if (file.isFile()) { searchName = file.getName(); if (searchName.equalsIgnoreCase("BOOK(" + bookName + ").TXT")) { fileName = searchName; } } index = index + 1; } return(fileName); } private String readBook(String fileName, Player pl
    94 downloads
  5. 2017-09-17Sep 18, 2017
    67 downloads

Similar projects

Plugin →