Written books

Discussion in 'Spigot Plugin Development' started by externo6, Dec 3, 2014.

  1. externo6


    Hello, I am writing a personal plugin, to remove a specific Written book from players inventories.
    The reason is because the Written books created before 1.8 by a specific plugin (Global Market) crash the clients.
    Because Global Market writes data into the book I am having trouble getting my plugin to 'see' the book.
    Here is the code so far:
    Code (Text):
        public void PlayerItemHeldEvent(PlayerItemHeldEvent event){
            Player player = event.getPlayer();  
            ItemStack log = new ItemStack(Material.WRITTEN_BOOK, 1);
            BookMeta meta = (BookMeta) log.getItemMeta();
            ItemMeta logmeta = log.getItemMeta();
            String[] loglore = {ChatColor.DARK_GRAY + "Not tradable"};
            logmeta.setDisplayName(ChatColor.WHITE + "Transaction Log");
            if (event.getPlayer().getInventory().contains(log)){
             player.sendMessage(ChatColor.GREEN + "Transaction Log removed to prevent you from crashing!");
             Bukkit.getConsoleSender().sendMessage(ChatColor.DARK_RED + "TLR: " + ChatColor.WHITE + player.getName() + ChatColor.DARK_RED + " had a Transaction Log removed via " + ChatColor.WHITE + "Item Held Event");
    Giving myself that item stack, allows the book to be removed from me. But because of the extra NBT data that Global Market inserts into the book, books created by the plugin are not removed.

    In short what I am asking is, how do I get the plugin to ignore any NBT data inside the book and only look for that it is called 'Transaction log' and is a Written Book.

    Hope I have made sense.
    Thank you :D
  2. Loop through the players inventory making sure the item isn't null, is a book, and that the title matches what you're looking for, then set item type to air