Java Code Examples for org.bukkit.Material#WRITTEN_BOOK

The following examples show how to use org.bukkit.Material#WRITTEN_BOOK . 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: EventFilterMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onInteract(final PlayerInteractEvent event) {
    if(cancelUnlessInteracting(event, event.getPlayer())) {
        // Allow the how-to book to be read
        if(event.getMaterial() == Material.WRITTEN_BOOK) {
            event.setUseItemInHand(Event.Result.ALLOW);
        } else {
            event.setUseItemInHand(Event.Result.DENY);
            event.setUseInteractedBlock(Event.Result.DENY);
        }

        MatchPlayer player = getMatch().getPlayer(event.getPlayer());
        if(player == null) return;

        if(!player.isSpawned()) {
            ClickType clickType = convertClick(event.getAction(), event.getPlayer());
            if(clickType == null) return;

            getMatch().callEvent(new ObserverInteractEvent(player, clickType, event.getClickedBlock(), null, event.getItem()));
        }

        // Right-clicking armor will put it on unless we do this
        event.getPlayer().updateInventory();
    }
}
 
Example 2
Source File: CustomBookOverlay.java    From CS-CoreLib with GNU General Public License v3.0 6 votes vote down vote up
public CustomBookOverlay(String title, String author, TellRawMessage... pages) {
	this.book = new ItemStack(Material.WRITTEN_BOOK);

	BookMeta meta = (BookMeta) this.book.getItemMeta();
	meta.setTitle(title);
	meta.setAuthor(author);

	for (TellRawMessage page: pages) {
		try {
			addPage(meta, page);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	this.book.setItemMeta(meta);
}
 
Example 3
Source File: ExhibitionListener.java    From NyaaUtils with MIT License 6 votes vote down vote up
@EventHandler(priority = HIGHEST, ignoreCancelled = true)
public void onPlayerInteractItemFrame(PlayerInteractEntityEvent ev) {
    if (!(ev.getRightClicked() instanceof ItemFrame)) return;
    ItemFrame f = (ItemFrame) ev.getRightClicked();
    if (f.getItem() == null || f.getItem().getType() == Material.AIR) return;
    ExhibitionFrame fr = ExhibitionFrame.fromItemFrame(f);
    if (fr.isSet()) {
        new Message(I18n.format("user.exhibition.looking_at")).append(fr.getItemInFrame()).send(ev.getPlayer());
        ev.getPlayer().sendMessage(I18n.format("user.exhibition.provided_by", fr.getOwnerName()));
        for (String line : fr.getDescriptions()) {
            ev.getPlayer().sendMessage(line);
        }
        ev.setCancelled(true);
        if (fr.hasItem() && fr.getItemInFrame().getType() == Material.WRITTEN_BOOK) {
            ev.getPlayer().openBook(fr.getItemInFrame());
        }
    }
}
 
Example 4
Source File: EventFilterMatchModule.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onInteract(final PlayerInteractEvent event) {
  if (cancelUnlessInteracting(event, event.getPlayer())) {
    // Allow the how-to book to be read
    if (event.getMaterial() == Material.WRITTEN_BOOK) {
      event.setUseItemInHand(Event.Result.ALLOW);
    }

    MatchPlayer player = match.getPlayer(event.getPlayer());
    if (player == null) return;

    ClickType clickType = convertClick(event.getAction(), event.getPlayer());
    if (clickType == null) return;

    match.callEvent(
        new ObserverInteractEvent(
            player, clickType, event.getClickedBlock(), null, event.getItem()));
  }
}
 
Example 5
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 6
Source File: BookPlayerShopkeeper.java    From Shopkeepers with GNU General Public License v3.0 5 votes vote down vote up
private List<ItemStack> getBooksFromChest() {
	List<ItemStack> list = new ArrayList<ItemStack>();
	Block chest = this.getChest();
	if (Utils.isChest(chest.getType())) {
		Inventory inv = ((Chest) chest.getState()).getInventory();
		for (ItemStack item : inv.getContents()) {
			if (!Utils.isEmpty(item) && item.getType() == Material.WRITTEN_BOOK && this.isBookAuthoredByShopOwner(item)) {
				list.add(item);
			}
		}
	}
	return list;
}
 
Example 7
Source File: UtilsMc.java    From NBTEditor with GNU General Public License v3.0 5 votes vote down vote up
public static ItemStack newWrittenBook(String title, String author) {
	ItemStack book = new ItemStack(Material.WRITTEN_BOOK);
	BookMeta meta = (BookMeta) book.getItemMeta();
	meta.setTitle(title);
	meta.setAuthor(author);
	book.setItemMeta(meta);
	return book;
}
 
Example 8
Source File: BookOfSouls.java    From NBTEditor with GNU General Public License v3.0 5 votes vote down vote up
public static boolean isValidBook(ItemStack book) {
	if (book != null && book.getType() == Material.WRITTEN_BOOK) {
		ItemMeta meta = book.getItemMeta();
		String title = ((BookMeta) meta).getTitle();
		if (meta != null && title != null && title.equals(_bosCustomItem.getName())) {
			return true;
		}
	}
	return false;
}
 
Example 9
Source File: CraftItemFactory.java    From Carbon with GNU Lesser General Public License v3.0 5 votes vote down vote up
private ItemMeta getItemMeta(Material material, CraftMetaItem meta) {
	if (material == Material.AIR) {
		return null;
	}
	if (material == Material.WRITTEN_BOOK || material == Material.BOOK_AND_QUILL) {
		return (meta instanceof CraftMetaBook) ? meta : new CraftMetaBook(meta);
	}
	if (material == Material.SKULL_ITEM) {
		return (meta instanceof CraftMetaSkull) ? meta : new CraftMetaSkull(meta);
	}
	if (material == Material.LEATHER_HELMET || material == Material.LEATHER_CHESTPLATE || material == Material.LEATHER_LEGGINGS || material == Material.LEATHER_BOOTS) {
		return (meta instanceof CraftMetaLeatherArmor) ? meta : new CraftMetaLeatherArmor(meta);
	}
	if (material == Material.POTION) {
		return (meta instanceof CraftMetaPotion) ? meta : new CraftMetaPotion(meta);
	}
	if (material == Material.MAP) {
		return (meta instanceof CraftMetaMap) ? meta : new CraftMetaMap(meta);
	}
	if (material == Material.FIREWORK) {
		return (meta instanceof CraftMetaFirework) ? meta : new CraftMetaFirework(meta);
	}
	if (material == Material.FIREWORK_CHARGE) {
		return (meta instanceof CraftMetaCharge) ? meta : new CraftMetaCharge(meta);
	}
	if (material == Material.ENCHANTED_BOOK) {
		return (meta instanceof CraftMetaEnchantedBook) ? meta : new CraftMetaEnchantedBook(meta);
	}
	if (material.toString().equals("BANNER")) {
		if (meta != null && BannerMeta.class.isAssignableFrom(meta.getClass())) {
			return meta;
		} else {
			return new BannerMeta(meta);
		}
	}
	return new CraftMetaItem(meta);
}
 
Example 10
Source File: CraftItemStack.java    From Carbon with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static ItemMeta getItemMeta(net.minecraft.server.v1_7_R4.ItemStack item) {
	if (!hasItemMeta(item)) {
		return CraftItemFactory.instance().getItemMeta(getType(item));
	}
	Material mat = getType(item);
	if (mat == Material.WRITTEN_BOOK || mat == Material.BOOK_AND_QUILL) {
		return new CraftMetaBook(item.tag);
	}
	if (mat == Material.SKULL_ITEM) {
		return new CraftMetaSkull(item.tag);
	}
	if (mat == Material.LEATHER_HELMET || mat == Material.LEATHER_CHESTPLATE || mat == Material.LEATHER_LEGGINGS || mat == Material.LEATHER_BOOTS) {
		return new CraftMetaLeatherArmor(item.tag);
	}
	if (mat == Material.POTION) {
		return new CraftMetaPotion(item.tag);
	}
	if (mat == Material.MAP) {
		return new CraftMetaMap(item.tag);
	}
	if (mat == Material.FIREWORK) {
		return new CraftMetaFirework(item.tag);
	}
	if (mat == Material.FIREWORK_CHARGE) {
		return new CraftMetaCharge(item.tag);
	}
	if (mat == Material.ENCHANTED_BOOK) {
		return new CraftMetaEnchantedBook(item.tag);
	}
	if (mat.toString().equals("BANNER")) {
		return new BannerMeta(item.getData(), item.tag);
	}
	return new CraftMetaItem(item.tag);
}
 
Example 11
Source File: BookPlayerShopkeeper.java    From Shopkeepers with GNU General Public License v3.0 5 votes vote down vote up
private static String getTitleOfBook(ItemStack book) {
	if (book.getType() == Material.WRITTEN_BOOK && book.hasItemMeta()) {
		BookMeta meta = (BookMeta) book.getItemMeta();
		return meta.getTitle();
	}
	return null;
}
 
Example 12
Source File: DeprecatedMethodUtil.java    From PerWorldInventory with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get BookMeta from a JSONObject.
 *
 * @param json The JsonObject of the BannerMeta to deserialize
 * @return The BookMeta constructed
 */
public static BookMeta getBookMeta(JsonObject json) {
    ItemStack dummyItems = new ItemStack(Material.WRITTEN_BOOK, 1);
    BookMeta meta = (BookMeta) dummyItems.getItemMeta();
    String title = null, author = null;
    JsonArray pages = null;
    if (json.has("title"))
        title = json.get("title").getAsString();
    if (json.has("author"))
        author = json.get("author").getAsString();
    if (json.has("pages"))
        pages = json.getAsJsonArray("pages");
    if (title != null)
        meta.setTitle(title);
    if (author != null)
        meta.setAuthor(author);
    if (pages != null) {
        String[] allPages = new String[pages.size()];
        for (int i = 0; i < pages.size() - 1; i++) {
            String page = pages.get(i).getAsString();
            if (page.isEmpty() || page == null)
                page = "";
            allPages[i] = page;
        }
        meta.setPages(allPages);
    }
    return meta;
}
 
Example 13
Source File: BuyingPlayerShopkeeper.java    From Shopkeepers with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean accept(ItemStack item) {
	if (Settings.isCurrencyItem(item) || Settings.isHighCurrencyItem(item)) return false;
	if (item.getType() == Material.WRITTEN_BOOK) return false;
	if (!item.getEnchantments().isEmpty()) return false; // TODO why don't allow buying of enchanted items?
	return true;
}
 
Example 14
Source File: BukkitUtils.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
public static ItemStack generateBook(String title, String author, List<String> pages) {
    ItemStack stack = new ItemStack(Material.WRITTEN_BOOK);
    BookMeta meta = (BookMeta) factory.getItemMeta(Material.WRITTEN_BOOK);

    meta.setTitle(title);
    meta.setAuthor(author);
    meta.setPages(pages);

    stack.setItemMeta(meta);
    return stack;
}
 
Example 15
Source File: MapPoll.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
public void sendBook(MatchPlayer viewer, boolean forceOpen) {
  String title = ChatColor.GOLD + "" + ChatColor.BOLD;
  title += TextTranslations.translate("vote.title.map", viewer.getBukkit());

  ItemStack is = new ItemStack(Material.WRITTEN_BOOK);
  BookMeta meta = (BookMeta) is.getItemMeta();
  meta.setAuthor("PGM");
  meta.setTitle(title);

  TextComponent.Builder content = TextComponent.builder();
  content.append(TranslatableComponent.of("vote.header.map", TextColor.DARK_PURPLE));
  content.append(TextComponent.of("\n\n"));

  for (MapInfo pgmMap : votes.keySet()) content.append(getMapBookComponent(viewer, pgmMap));

  NMSHacks.setBookPages(
      meta, TextTranslations.toBaseComponent(content.build(), viewer.getBukkit()));
  is.setItemMeta(meta);

  ItemStack held = viewer.getInventory().getItemInHand();
  if (held.getType() != Material.WRITTEN_BOOK
      || !title.equals(((BookMeta) is.getItemMeta()).getTitle())) {
    viewer.getInventory().setHeldItemSlot(2);
  }
  viewer.getInventory().setItemInHand(is);

  if (forceOpen || viewer.getSettings().getValue(SettingKey.VOTE) == SettingValue.VOTE_ON)
    NMSHacks.openBook(is, viewer.getBukkit());
}
 
Example 16
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");
	}
}
 
Example 17
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 18
Source File: NMSHandler.java    From askyblock with GNU General Public License v2.0 4 votes vote down vote up
@Override
public ItemStack setBook(Tag item) {
    Bukkit.getLogger().warning("Written books in schematics not supported with this version of server");
    return new ItemStack(Material.WRITTEN_BOOK);
}
 
Example 19
Source File: BookOfSoulsCI.java    From NBTEditor with GNU General Public License v3.0 4 votes vote down vote up
public BookOfSoulsCI() {
	super("bos", ChatColor.AQUA + "Book of Souls", Material.WRITTEN_BOOK);
}
 
Example 20
Source File: GeneralCommands.java    From GlobalWarming with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Add an instructional booklet to a player's inventory
 * - Will prevent duplicates
 */
public static void getBooklet(GPlayer gPlayer) {
    Player onlinePlayer = gPlayer.getOnlinePlayer();
    if (onlinePlayer != null) {
        //Prevent duplicates:
        // - Note that empty inventory slots will be NULL
        boolean isDuplicate = false;
        PlayerInventory inventory = onlinePlayer.getInventory();
        for (ItemStack item : inventory.getContents()) {
            if (item != null &&
                    item.getType().equals(Material.WRITTEN_BOOK) &&
                    item.getItemMeta().getDisplayName().equals(Lang.WIKI_NAME.get())) {
                gPlayer.sendMsg(Lang.WIKI_ALREADYADDED);
                isDuplicate = true;
                break;
            }
        }

        //Add the booklet:
        if (!isDuplicate) {
            ItemStack wiki = new ItemStack(Material.WRITTEN_BOOK);
            final BookMeta meta = (BookMeta) wiki.getItemMeta();
            if (meta != null) {
                meta.setDisplayName(Lang.WIKI_NAME.get());
                meta.setAuthor(Lang.WIKI_AUTHOR.get());
                meta.setTitle(Lang.WIKI_LORE.get());
                meta.setPages(
                        Lang.WIKI_INTRODUCTION.get(),
                        Lang.WIKI_SCORES.get(),
                        Lang.WIKI_EFFECTS.get(),
                        Lang.WIKI_BOUNTY.get(),
                        Lang.WIKI_OTHER.get()
                        );

                //Create the book and add to inventory:
                wiki.setItemMeta(meta);
                if (onlinePlayer.getInventory().addItem(wiki).isEmpty()) {
                    //Added:
                    gPlayer.sendMsg(Lang.WIKI_ADDED);
                } else {
                    //Inventory full:
                    gPlayer.sendMsg(Lang.GENERIC_INVENTORYFULL);
                }
            }
        }
    }
}