2023-11-11latestUpdated for 1.20Nov 11, 2023 Updated for Minecraft 1.20.3.2One more time...Dec 19, 2020 Three time's the charm3.1Duplicate welcome book?!?!Dec 19, 2020 Starting with Minecraft 1.16.4, the event PlayerJoinEvent is being fired twice each time a player joins the game, causing my 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 :-/3.0Recompiled for 1.16Dec 19, 2020 Recompiled for 1.162017-09-30general improvementsSep 30, 2017 This plugin gives new players a welcome book. First create a text file in your Minecraft folder named: book(welcome).txt You can change the file title of the book from (welcome) to whatever else you prefer in the properties file, and also the welcome message. Edit this file 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 See my BOOK plugin for more information... Code (Text): package FredashaySpigotWelcomeBook; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.sql.Date; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.List; import java.util.Properties; import java.util.logging.Logger; import org.bukkit.Material; import org.bukkit.command.CommandExecutor; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; 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 { final static char CRLF = (char) 0x0a; final static int pageWidth = 114; final static int PageLines = 13; final static int pageChars = 240; private static Logger logger = null; private static PluginDescriptionFile pdfFile = null; private static Properties props = new Properties(); private static String welcomeMessage = "Please read the welcome book you now have!"; private static String fileTitle = "welcome"; @Override public void onEnable() { logger = Logger.getLogger("Minecraft"); pdfFile = getDescription(); String propertiesFileName = pdfFile.getName() + ".properties"; getProperties(propertiesFileName); getServer().getPluginManager().registerEvents(this,this); } private void getProperties(String fileName) { InputStream input = null; try { input = new FileInputStream(fileName); props.load(input); } catch (FileNotFoundException ok) { saveProperties(fileName); } catch (IOException oops) { logger.info("[" + pdfFile.getName() + "] Error reading properties file '" + fileName + "'. "); oops.printStackTrace(System.err); } finally { if (input != null) { try { input.close(); } catch (IOException oops) { oops.printStackTrace(System.err); } } } if (props.getProperty("TITLE") != null) { fileTitle = props.getProperty("TITLE"); } if (props.getProperty("MESSAGE") != null) { welcomeMessage = props.getProperty("MESSAGE"); } } private void saveProperties(String fileName) { OutputStream output = null; try { output = new FileOutputStream(fileName); props.setProperty("TITLE", fileTitle); props.setProperty("MESSAGE", welcomeMessage); props.store(output, null); } catch (IOException oops) { logger.info("[" + pdfFile.getName() + "] Error writing properties file '" + fileName + "'. "); oops.printStackTrace(System.err); } finally { try { output.close(); } catch (IOException oops) { oops.printStackTrace(System.err); } } } @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { String fileName = null; Player player = event.getPlayer(); if (!(event.getPlayer().hasPlayedBefore())) { fileName = getFileName(fileTitle); if (fileName != null) { String rawBook = readBook(fileName, player); String bookText = scanBook(rawBook); long fileDate = getFileDate(fileName); String title = getTitle(bookText); String author = getAuthor(bookText); String bookPages[] = formatBook(bookText, fileDate); ItemStack myBook = createBook(title, author, bookPages); giveItemToPlayer(player, myBook, title); logger.info("[" + pdfFile.getName() + "] Gave welcome book to new player '" + player.getName() + "'. "); } } } 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 plr) { File bookFile = null; BufferedReader reader = null; String recordBuffer = null; String fullText = null; bookFile = new File(fileName); if (bookFile.exists()) { try { fullText = ""; reader = new BufferedReader(new FileReader(fileName)); recordBuffer = reader.readLine(); while (recordBuffer != null) { if (recordBuffer.length() > 0) { fullText = fullText.trim() + " " + recordBuffer.trim(); } recordBuffer = reader.readLine(); } } catch (IOException oops) { logger.info("[" + pdfFile.getName() + "] Problem with file '" + fileName + "'. "); fullText = null; } finally { try { reader.close(); } catch (IOException oops) { logger.info("[" + pdfFile.getName() + "] Problem with file '" + fileName + "'. "); fullText = null; }2017-09-18Sep 19, 2017
Similar projects
Plugin →Let Me Despawn
Improves performance by tweaking mob despawn rules. Say bye to pesky unintentional persistent mobs.
25MSueta
JourneyMap
Real-time map used for mapping in-game or your browser as you explore.
14.7MSueta
Emotecraft
Create your own emotes in Minecraft.
7.5MSueta
Simple Tpa
A simple tpa plugin which sends requests
5.4MSueta
Common Network
Forge and Fabric Unified Networking Solution
3.9MSueta
Set Home
A lightweight plugin for players to set their homes.
3.8MSueta