Java Code Examples for org.bukkit.inventory.meta.BookMeta#setLore()

The following examples show how to use org.bukkit.inventory.meta.BookMeta#setLore() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Spy.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onPlayerDeath(EntityDeathEvent event, ItemStack stack) {
	
	Player player = (Player)event.getEntity();
	Resident resident = CivGlobal.getResident(player);
	if (resident == null || !resident.hasTown()) {
		return;
	}
	
	
	ArrayList<String> bookout = MissionLogger.getMissionLogs(resident.getTown());
	
	ItemStack book = new ItemStack(Material.WRITTEN_BOOK, 1);
	BookMeta meta = (BookMeta) book.getItemMeta();
	ArrayList<String> lore = new ArrayList<String>();
	lore.add("Mission Report");
	meta.setAuthor("Mission Reports");
	meta.setTitle("Missions From "+resident.getTown().getName());
	
	String out = "";
	for (String str : bookout) {
		out += str+"\n";
	}
	BookUtil.paginate(meta, out);			

	
	meta.setLore(lore);
	book.setItemMeta(meta);
	player.getWorld().dropItem(player.getLocation(), book);
	
}
 
Example 2
Source File: Journal.java    From BetonQuest with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Generates the journal as ItemStack
 *
 * @return the journal ItemStack
 */
public ItemStack getAsItem() {
    // create the book with default title/author
    ItemStack item = new ItemStack(Material.WRITTEN_BOOK);
    BookMeta meta = (BookMeta) item.getItemMeta();
    meta.setTitle(Utils.format(Config.getMessage(lang, "journal_title")));
    meta.setAuthor(PlayerConverter.getPlayer(playerID).getName());
    List<String> lore = new ArrayList<>();
    lore.add(Utils.format(Config.getMessage(lang, "journal_lore")));
    meta.setLore(lore);
    // add main page and generate pages from texts
    List<String> finalList = new ArrayList<>();
    if (Config.getString("config.journal.one_entry_per_page").equalsIgnoreCase("false")) {
        String color = Config.getString("config.journal_colors.line");
        String separator = Config.parseMessage(playerID, "journal_separator", null);
        if (separator == null) {
            separator = "---------------";
        }
        String line = "\n§" + color + separator + "\n";

        if (Config.getString("config.journal.show_separator") != null &&
                Config.getString("config.journal.show_separator").equalsIgnoreCase("false")) {
            line = "\n";
        }

        StringBuilder stringBuilder = new StringBuilder();
        for (String entry : getText()) {
            stringBuilder.append(entry).append(line);
        }
        if (mainPage != null && mainPage.length() > 0) {
            if (Config.getString("config.journal.full_main_page").equalsIgnoreCase("true")) {
                finalList.addAll(Utils.pagesFromString(mainPage));
            } else {
                stringBuilder.insert(0, mainPage + line);
            }
        }
        String wholeString = stringBuilder.toString().trim();
        finalList.addAll(Utils.pagesFromString(wholeString));
    } else {
        if (mainPage != null && mainPage.length() > 0) {
            finalList.addAll(Utils.pagesFromString(mainPage));
        }
        finalList.addAll(getText());
    }
    if (finalList.size() > 0) {
        meta.setPages(Utils.multiLineColorCodes(finalList, "§" + Config.getString("config.journal_colors.line")));
    } else {
        meta.addPage("");
    }
    item.setItemMeta(meta);
    return item;
}
 
Example 3
Source File: MissionBook.java    From civcraft with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
private static void performInvestigateTown(Player player, ConfigMission mission) throws CivException {
	
	Resident resident = CivGlobal.getResident(player);
	if (resident == null || !resident.hasTown()) {
		throw new CivException("Only residents of towns can perform spy missions.");
	}
	
	// Must be within enemy town borders.
	ChunkCoord coord = new ChunkCoord(player.getLocation());
	TownChunk tc = CivGlobal.getTownChunk(coord);
	
	if (tc == null || tc.getTown().getCiv() == resident.getTown().getCiv()) {
		throw new CivException("Must be in another civilization's town's borders.");
	}
	
	if(processMissionResult(player, tc.getTown(), mission)) {
		ItemStack book = new ItemStack(Material.WRITTEN_BOOK, 1);
		BookMeta meta = (BookMeta) book.getItemMeta();
		ArrayList<String> lore = new ArrayList<String>();
		lore.add("Mission Report");
		
		meta.setAuthor("Mission Reports");
		meta.setTitle("Investigate Town");
		
	//	ArrayList<String> out = new ArrayList<String>();
		String out = "";
		
		out += ChatColor.UNDERLINE+"Town:"+tc.getTown().getName()+"\n"+ChatColor.RESET;
		out += ChatColor.UNDERLINE+"Civ:"+tc.getTown().getCiv().getName()+"\n\n"+ChatColor.RESET;
		
		SimpleDateFormat sdf = new SimpleDateFormat("M/dd h:mm:ss a z");
		out += "Time: "+sdf.format(new Date())+"\n";
		out += ("Treasury: "+tc.getTown().getTreasury().getBalance()+"\n");
		out += ("Hammers: "+tc.getTown().getHammers().total+"\n");
		out += ("Culture: "+tc.getTown().getCulture().total+"\n");
		out += ("Growth: "+tc.getTown().getGrowth().total+"\n");
		out += ("Beakers(civ): "+tc.getTown().getBeakers().total+"\n");
		if (tc.getTown().getCiv().getResearchTech() != null) {
			out += ("Researching: "+tc.getTown().getCiv().getResearchTech().name+"\n");
		} else {
			out += ("Researching:Nothing"+"\n");
		}
		
		BookUtil.paginate(meta, out);
		
		out = ChatColor.UNDERLINE+"Upkeep Info\n\n"+ChatColor.RESET;
		try {
			out += "From Spread:"+tc.getTown().getSpreadUpkeep()+"\n";
			out += "From Structures:"+tc.getTown().getStructureUpkeep()+"\n";
			out += "Total:"+tc.getTown().getTotalUpkeep();
			BookUtil.paginate(meta, out);
		} catch (InvalidConfiguration e) {
			e.printStackTrace();
			throw new CivException("Internal configuration exception.");
		}
		
		
		meta.setLore(lore);
		book.setItemMeta(meta);
		
		HashMap<Integer, ItemStack> leftovers = player.getInventory().addItem(book);
		for (ItemStack stack : leftovers.values()) {
			player.getWorld().dropItem(player.getLocation(), stack);
		}
		
		player.updateInventory();
		
		CivMessage.sendSuccess(player, "Mission Accomplished");
	}
}