java类org.bukkit.inventory.meta.BookMeta的实例源码

CraftEventFactory.java 文件源码 项目:CraftBukkit 阅读 22 收藏 0 点赞 0 评论 0
public static void handleEditBookEvent(EntityPlayer player, ItemStack newBookItem) {
    int itemInHandIndex = player.inventory.itemInHandIndex;

    PlayerEditBookEvent editBookEvent = new PlayerEditBookEvent(player.getBukkitEntity(), player.inventory.itemInHandIndex, (BookMeta) CraftItemStack.getItemMeta(player.inventory.getItemInHand()), (BookMeta) CraftItemStack.getItemMeta(newBookItem), newBookItem.getItem() == Items.WRITTEN_BOOK);
    player.world.getServer().getPluginManager().callEvent(editBookEvent);
    ItemStack itemInHand = player.inventory.getItem(itemInHandIndex);

    // If they've got the same item in their hand, it'll need to be updated.
    if (itemInHand != null && itemInHand.getItem() == Items.BOOK_AND_QUILL) {
        if (!editBookEvent.isCancelled()) {
            CraftItemStack.setItemMeta(itemInHand, editBookEvent.getNewBookMeta());
            if (editBookEvent.isSigning()) {
                itemInHand.setItem(Items.WRITTEN_BOOK);
            }
        }

        // Client will have updated its idea of the book item; we need to overwrite that
        Slot slot = player.activeContainer.getSlot(player.inventory, itemInHandIndex);
        player.playerConnection.sendPacket(new PacketPlayOutSetSlot(player.activeContainer.windowId, slot.rawSlotIndex, itemInHand));
    }
}
BookSerialization.java 文件源码 项目:NexusInventory 阅读 16 收藏 0 点赞 0 评论 0
/**
 * Gets a JSONObject representation of a BookMeta. Book and Quills books will have a pages key, while
 * finished, written, books will also have an author and title key.
 *
 * @param meta The BookMeta to serialize
 * @return A JSON Representation of the give BookMeta
 */
public static JSONObject serializeBookMeta(BookMeta meta) {
    try {
        JSONObject root = new JSONObject();
        if (meta.hasTitle())
            root.put("title", meta.getTitle());
        if (meta.hasAuthor())
            root.put("author", meta.getAuthor());
        if (meta.hasPages()) {
            String[] pages = meta.getPages().toArray(new String[]{});
            root.put("pages", pages);
        }
        return root;
    } catch (JSONException e) {
        e.printStackTrace();
        return null;
    }
}
CraftEventFactory.java 文件源码 项目:Uranium 阅读 67 收藏 0 点赞 0 评论 0
public static void handleEditBookEvent(net.minecraft.entity.player.EntityPlayerMP player, net.minecraft.item.ItemStack newBookItem) {
    int itemInHandIndex = player.inventory.currentItem;

    PlayerEditBookEvent editBookEvent = new PlayerEditBookEvent(player.getBukkitEntity(), player.inventory.currentItem, (BookMeta) CraftItemStack.getItemMeta(player.inventory.getCurrentItem()), (BookMeta) CraftItemStack.getItemMeta(newBookItem), newBookItem.getItem() == net.minecraft.init.Items.written_book);
    player.worldObj.getServer().getPluginManager().callEvent(editBookEvent);
    net.minecraft.item.ItemStack itemInHand = player.inventory.getStackInSlot(itemInHandIndex);

    // If they've got the same item in their hand, it'll need to be updated.
    if (itemInHand != null && itemInHand.getItem() == net.minecraft.init.Items.writable_book) {
        if (!editBookEvent.isCancelled()) {
            CraftItemStack.setItemMeta(itemInHand, editBookEvent.getNewBookMeta());
            if (editBookEvent.isSigning()) {
                itemInHand.func_150996_a(net.minecraft.init.Items.written_book);
            }
        }

        // Client will have updated its idea of the book item; we need to overwrite that
        net.minecraft.inventory.Slot slot = player.openContainer.getSlotFromInventory((net.minecraft.inventory.IInventory) player.inventory, itemInHandIndex);
        player.playerNetServerHandler.sendPacket(new net.minecraft.network.play.server.S2FPacketSetSlot(player.openContainer.windowId, slot.slotNumber, itemInHand));
    }
}
SpellTome.java 文件源码 项目:MystiCraft 阅读 24 收藏 0 点赞 0 评论 0
public static ItemStack getSpellTome(String label, Player crafter) {
    ItemStack i = new ItemStack(MATERIAL);
    Spell spell = MystiCraft.getSpellManager().getSpell(label);
    BookMeta meta = (BookMeta)i.getItemMeta();
    meta.setDisplayName(DISPLAY_NAME + StringUtils.capitalize(label));
    if (crafter != null)
        meta.setAuthor(crafter.getName());
    else
        meta.setAuthor("unknown");
    meta.setGeneration(Generation.TATTERED);
    meta.setLore(Arrays.asList(new String[]{ChatColor.GRAY + spell.getDescription(), ChatColor.GRAY + "Mana Cost: " + spell.getManaCost()}));
    // TODO Add description
    meta.addPage("-------------------=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");
    i.setItemMeta(meta);
    return i;
}
FBull.java 文件源码 项目:FactionsXL 阅读 21 收藏 0 点赞 0 评论 0
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
    Player player = event.getPlayer();
    Location location = player.getLocation();
    ItemStack item = event.getItem();
    if (isBull(item) && event.getAction() == Action.RIGHT_CLICK_AIR | event.getAction() == Action.RIGHT_CLICK_BLOCK) {
        if (!FactionsXL.getInstance().getBoard().isAnnexable(location)) {
            ParsingUtil.sendMessage(player, FMessage.ERROR_LAND_NOT_FOR_SALE.getMessage());
            return;
        }
        FactionCache factions = FactionsXL.getInstance().getFactionCache();
        BookMeta meta = ((BookMeta) item.getItemMeta());
        String title = meta.getTitle().replace(" ", "-");
        if (factions.getByName(title) != null) {
            title += NumberUtil.generateRandomInt(0, 100);
        }
        FireworkUtil.spawnRandom(location);
        FactionsXL.getInstance().getFactionCache().create(player, title);
        player.getInventory().remove(item);
    }
}
ItemBook.java 文件源码 项目:Kineticraft 阅读 16 收藏 0 点赞 0 评论 0
@Override
public void updateItem() {

    if (getTitle() != null)
        getMeta().setTitle(getTitle());
    if (getAuthor() != null)
        getMeta().setAuthor(getAuthor());

    getMeta().setPages(new ArrayList<>()); // A book needs its page tag, so we'll default to an empty one.
    if (isWriteLines())// Save the book pages to the item.
        getMeta().pages.addAll(getPages().stream().map(TextBuilder::create)
                .map(TextUtils::toNMSComponent).collect(Collectors.toList()));

    if (getMeta().pages.isEmpty()) // Allow the book to be opened / editted.
        getMeta().addPage("");

    getMeta().setGeneration(BookMeta.Generation.TATTERED);
    this.page = 0; // Reset writer.
}
ItemUtil.java 文件源码 项目:PA 阅读 21 收藏 0 点赞 0 评论 0
public static ItemStack createBook(String name, List<String> lore, String... pages) {
    ItemStack book = new ItemStack(Material.WRITTEN_BOOK);
    BookMeta meta = (BookMeta) book.getItemMeta();
    ItemMeta bookMeta = book.getItemMeta();

    bookMeta.setDisplayName(Utils.colorize(name));
    ArrayList<String> colorLore = new ArrayList<>();
    if (lore != null) lore.forEach(str -> colorLore.add(Utils.colorize(str)));
    bookMeta.setLore(colorLore);

    meta.addPage(pages);
    meta.setAuthor(Utils.colorize("&6ProjectAlpha"));

    book.setItemMeta(bookMeta);

    return book;
}
CraftEventFactory.java 文件源码 项目:ThermosRebased 阅读 21 收藏 0 点赞 0 评论 0
public static void handleEditBookEvent(net.minecraft.entity.player.EntityPlayerMP player, net.minecraft.item.ItemStack newBookItem) {
    int itemInHandIndex = player.inventory.currentItem;

    PlayerEditBookEvent editBookEvent = new PlayerEditBookEvent(player.getBukkitEntity(), player.inventory.currentItem, (BookMeta) CraftItemStack.getItemMeta(player.inventory.getCurrentItem()), (BookMeta) CraftItemStack.getItemMeta(newBookItem), newBookItem.getItem() == net.minecraft.init.Items.written_book);
    player.worldObj.getServer().getPluginManager().callEvent(editBookEvent);
    net.minecraft.item.ItemStack itemInHand = player.inventory.getStackInSlot(itemInHandIndex);

    // If they've got the same item in their hand, it'll need to be updated.
    if (itemInHand != null && itemInHand.getItem() == net.minecraft.init.Items.writable_book) {
        if (!editBookEvent.isCancelled()) {
            CraftItemStack.setItemMeta(itemInHand, editBookEvent.getNewBookMeta());
            if (editBookEvent.isSigning()) {
                itemInHand.func_150996_a(net.minecraft.init.Items.written_book);
            }
        }

        // Client will have updated its idea of the book item; we need to overwrite that
        net.minecraft.inventory.Slot slot = player.openContainer.getSlotFromInventory((net.minecraft.inventory.IInventory) player.inventory, itemInHandIndex);
        player.playerNetServerHandler.sendPacket(new net.minecraft.network.play.server.S2FPacketSetSlot(player.openContainer.windowId, slot.slotNumber, itemInHand));
    }
}
XMLItemMeta.java 文件源码 项目:Arcade2 阅读 21 收藏 0 点赞 0 评论 0
public static ItemMeta parse(Element xml, ItemMeta source) {
    if (source instanceof BannerMeta) {
        return parseBanner(xml, (BannerMeta) source);
    } else if (source instanceof BookMeta) {
        return parseBook(xml, (BookMeta) source);
    } else if (source instanceof EnchantmentStorageMeta) {
        return parseEnchantmentStorage(xml, (EnchantmentStorageMeta) source);
    } else if (source instanceof FireworkMeta) {
        return parseFirework(xml, (FireworkMeta) source);
    } else if (source instanceof FireworkEffectMeta) {
        return parseFireworkEffect(xml, (FireworkEffectMeta) source);
    } else if (source instanceof LeatherArmorMeta) {
        return parseLeatherArmor(xml, (LeatherArmorMeta) source);
    } else if (source instanceof MapMeta) {
        return parseMap(xml, (MapMeta) source);
    } else if (source instanceof PotionMeta) {
        return parsePotion(xml, (PotionMeta) source);
    } else if (source instanceof SkullMeta) {
        return parseSkull(xml, (SkullMeta) source);
    } else if (source instanceof SpawnEggMeta) {
        return parseSpawnEgg(xml, (SpawnEggMeta) source);
    }

    return source;
}
XMLItemMeta.java 文件源码 项目:Arcade2 阅读 24 收藏 0 点赞 0 评论 0
public static BookMeta parseBook(Element xml, BookMeta source) {
    Element book = xml.getChild("book");
    if (book != null) {
        Attribute author = book.getAttribute("author");
        if (author != null) {
            source.setAuthor(parseMessage(author.getValue()));
        }

        Attribute title = book.getAttribute("title");
        if (title != null) {
            source.setTitle(parseMessage(title.getValue()));
        }

        for (Element page : book.getChildren("page")) {
            source.addPage(parseMessage(page.getTextNormalize()));
        }
    }

    return source;
}
FileManager.java 文件源码 项目:Breakpoint 阅读 19 收藏 0 点赞 0 评论 0
public static BookMeta loadWikiBook(BookMeta im)
{
    String path = "plugins/Breakpoint/wikiBook/";
    List<String> contents = new ArrayList<String>();
    int page = 0;
    File file = new File(path + page + ".txt");
    while (file.exists())
    {
        String pageContent = getString(file);
        contents.add(pageContent);
        page++;
        file = new File(path + page + ".txt");
    }
    im.setPages(contents);

    return im;
}
FileManager.java 文件源码 项目:Breakpoint 阅读 27 收藏 0 点赞 0 评论 0
public static void saveWikiBook()
{
    String path = "plugins/Breakpoint/wikiBook/";
    BookMeta im = (BookMeta) InventoryMenuManager.wikiBook.getItemMeta();
    List<String> contents = im.getPages();
    for (int page = 0; page < contents.size(); page++)
    {
        File file = new File(path + page + ".txt");
        File pathFile = new File(path);
        pathFile.mkdirs();
        try
        {
            if (!file.exists())
                file.createNewFile();
            setString(file, contents.get(page));
        }
        catch (IOException e)
        {
            Breakpoint.warn("Wiki book did not save properly.");
            e.printStackTrace();
        }
    }
}
CustomBookOverlay.java 文件源码 项目:CS-CoreLib 阅读 21 收藏 0 点赞 0 评论 0
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);
}
QuestManager.java 文件源码 项目:QuestManager 阅读 27 收藏 0 点赞 0 评论 0
@EventHandler
public void onItemPickup(PlayerPickupItemEvent e) {

    if (e.isCancelled()) {
        return;
    }

    ItemStack item = e.getItem().getItemStack();

    if (item.getType().equals(Material.WRITTEN_BOOK)) {
        BookMeta meta = (BookMeta) item.getItemMeta();

        if (meta.getTitle().equals("Quest Log")) {
            e.getItem().remove();
            e.setCancelled(true);

            QuestManagerPlugin.questManagerPlugin.getPlayerManager().getPlayer(
                    e.getPlayer().getUniqueId()).addQuestBook();

        }
    }

}
CommandHandler.java 文件源码 项目:NyaaUtils 阅读 16 收藏 0 点赞 0 评论 0
@SubCommand(value = "setbookauthor", permission = "nu.setbook")
public void setbookauthor(CommandSender sender, Arguments args) {
    if (!(args.length() > 1)) {
        msg(sender, "manual.setbookauthor.usage");
        return;
    }
    String author = args.next();
    Player p = asPlayer(sender);
    author = ChatColor.translateAlternateColorCodes('&', author);
    ItemStack item = p.getInventory().getItemInMainHand();
    if (item == null || !item.getType().equals(Material.WRITTEN_BOOK)) {
        msg(sender, "user.setbook.no_book");
        return;
    }
    BookMeta meta = (BookMeta) item.getItemMeta();
    meta.setAuthor(author);
    item.setItemMeta(meta);
    msg(sender, "user.setbook.success");
}
CommandHandler.java 文件源码 项目:NyaaUtils 阅读 28 收藏 0 点赞 0 评论 0
@SubCommand(value = "setbooktitle", permission = "nu.setbook")
public void setbooktitle(CommandSender sender, Arguments args) {
    if (!(args.length() > 1)) {
        msg(sender, "manual.setbooktitle.usage");
        return;
    }
    String title = args.next();
    Player p = asPlayer(sender);
    title = ChatColor.translateAlternateColorCodes('&', title);

    ItemStack item = p.getInventory().getItemInMainHand();
    if (item == null || !item.getType().equals(Material.WRITTEN_BOOK)) {
        msg(sender, "user.setbook.no_book");
        return;
    }
    BookMeta meta = (BookMeta) item.getItemMeta();
    meta.setTitle(title);
    item.setItemMeta(meta);
    msg(sender, "user.setbook.success");
}
CommandHandler.java 文件源码 项目:NyaaUtils 阅读 13 收藏 0 点赞 0 评论 0
@SubCommand(value = "setbookunsigned", permission = "nu.setbook")
public void setbookunsigned(CommandSender sender, Arguments args) {
    Player p = asPlayer(sender);
    ItemStack item = p.getInventory().getItemInMainHand();
    if (item == null || !item.getType().equals(Material.WRITTEN_BOOK)) {
        msg(sender, "user.setbook.no_book");
        return;
    }
    BookMeta meta = (BookMeta) item.getItemMeta();
    ItemStack newbook = new ItemStack(Material.BOOK_AND_QUILL, 1);
    BookMeta newbookMeta = (BookMeta) newbook.getItemMeta();
    newbookMeta.setPages(meta.getPages());
    newbook.setItemMeta(newbookMeta);
    p.getInventory().setItemInMainHand(newbook);
    msg(sender, "user.setbook.success");
}
CondHasTitle.java 文件源码 项目:Skellett 阅读 13 收藏 0 点赞 0 评论 0
public boolean check(Event e) {
    BookMeta book = (BookMeta) item.getSingle(e).getItemMeta();
    if (book.hasTitle()) {
        if (boo == true) {
            return true;
        } else {
            return false;
        }
    } else {
        if (boo == false) {
            return true;
        } else {
            return false;
        }
    }
}
CondHasAuthor.java 文件源码 项目:Skellett 阅读 16 收藏 0 点赞 0 评论 0
public boolean check(Event e) {
    BookMeta book = (BookMeta) item.getSingle(e).getItemMeta();
    if (book.hasAuthor()) {
        if (boo == true) {
            return true;
        } else {
            return false;
        }
    } else {
        if (boo == false) {
            return true;
        } else {
            return false;
        }
    }
}
CondHasGeneration.java 文件源码 项目:Skellett 阅读 17 收藏 0 点赞 0 评论 0
public boolean check(Event e) {
    BookMeta book = (BookMeta) item.getSingle(e).getItemMeta();
    if (book.hasGeneration()) {
        if (boo == true) {
            return true;
        } else {
            return false;
        }
    } else {
        if (boo == false) {
            return true;
        } else {
            return false;
        }
    }
}
ItemMatcher.java 文件源码 项目:RpgPlus 阅读 17 收藏 0 点赞 0 评论 0
private boolean bookPropertiesMatch(ItemStack itemStack) {
    ItemMeta meta = itemStack.getItemMeta();

    if (meta instanceof BookMeta) {
        BookMeta book = (BookMeta) meta;
        if (bookTitle != null && !bookTitle.equals(book.getTitle())) {
            return false;
        }
        if (bookAuthor != null && !bookAuthor.equals(book.getAuthor())) {
            return false;
        }
        if (bookPages != null && !bookPages.equals(book.getPages())) {
            return false;
        }
    }

    return true;
}
CraftEventFactory.java 文件源码 项目:Thermos 阅读 18 收藏 0 点赞 0 评论 0
public static void handleEditBookEvent(net.minecraft.entity.player.EntityPlayerMP player, net.minecraft.item.ItemStack newBookItem) {
    int itemInHandIndex = player.inventory.currentItem;

    PlayerEditBookEvent editBookEvent = new PlayerEditBookEvent(player.getBukkitEntity(), player.inventory.currentItem, (BookMeta) CraftItemStack.getItemMeta(player.inventory.getCurrentItem()), (BookMeta) CraftItemStack.getItemMeta(newBookItem), newBookItem.getItem() == net.minecraft.init.Items.written_book);
    player.worldObj.getServer().getPluginManager().callEvent(editBookEvent);
    net.minecraft.item.ItemStack itemInHand = player.inventory.getStackInSlot(itemInHandIndex);

    // If they've got the same item in their hand, it'll need to be updated.
    if (itemInHand != null && itemInHand.getItem() == net.minecraft.init.Items.writable_book) {
        if (!editBookEvent.isCancelled()) {
            CraftItemStack.setItemMeta(itemInHand, editBookEvent.getNewBookMeta());
            if (editBookEvent.isSigning()) {
                itemInHand.func_150996_a(net.minecraft.init.Items.written_book);
            }
        }

        // Client will have updated its idea of the book item; we need to overwrite that
        net.minecraft.inventory.Slot slot = player.openContainer.getSlotFromInventory((net.minecraft.inventory.IInventory) player.inventory, itemInHandIndex);
        player.playerNetServerHandler.sendPacket(new net.minecraft.network.play.server.S2FPacketSetSlot(player.openContainer.windowId, slot.slotNumber, itemInHand));
    }
}
CraftEventFactory.java 文件源码 项目:KCauldron 阅读 22 收藏 0 点赞 0 评论 0
public static void handleEditBookEvent(net.minecraft.entity.player.EntityPlayerMP player, net.minecraft.item.ItemStack newBookItem) {
    int itemInHandIndex = player.inventory.currentItem;

    PlayerEditBookEvent editBookEvent = new PlayerEditBookEvent(player.getBukkitEntity(), player.inventory.currentItem, (BookMeta) CraftItemStack.getItemMeta(player.inventory.getCurrentItem()), (BookMeta) CraftItemStack.getItemMeta(newBookItem), newBookItem.getItem() == net.minecraft.init.Items.written_book);
    player.worldObj.getServer().getPluginManager().callEvent(editBookEvent);
    net.minecraft.item.ItemStack itemInHand = player.inventory.getStackInSlot(itemInHandIndex);

    // If they've got the same item in their hand, it'll need to be updated.
    if (itemInHand != null && itemInHand.getItem() == net.minecraft.init.Items.writable_book) {
        if (!editBookEvent.isCancelled()) {
            CraftItemStack.setItemMeta(itemInHand, editBookEvent.getNewBookMeta());
            if (editBookEvent.isSigning()) {
                itemInHand.func_150996_a(net.minecraft.init.Items.written_book);
            }
        }

        // Client will have updated its idea of the book item; we need to overwrite that
        net.minecraft.inventory.Slot slot = player.openContainer.getSlotFromInventory((net.minecraft.inventory.IInventory) player.inventory, itemInHandIndex);
        player.playerNetServerHandler.sendPacket(new net.minecraft.network.play.server.S2FPacketSetSlot(player.openContainer.windowId, slot.slotNumber, itemInHand));
    }
}
CraftEventFactory.java 文件源码 项目:CauldronGit 阅读 19 收藏 0 点赞 0 评论 0
public static void handleEditBookEvent(net.minecraft.entity.player.EntityPlayerMP player, net.minecraft.item.ItemStack newBookItem) {
    int itemInHandIndex = player.inventory.currentItem;

    PlayerEditBookEvent editBookEvent = new PlayerEditBookEvent(player.getBukkitEntity(), player.inventory.currentItem, (BookMeta) CraftItemStack.getItemMeta(player.inventory.getCurrentItem()), (BookMeta) CraftItemStack.getItemMeta(newBookItem), newBookItem.getItem() == net.minecraft.init.Items.written_book);
    player.worldObj.getServer().getPluginManager().callEvent(editBookEvent);
    net.minecraft.item.ItemStack itemInHand = player.inventory.getStackInSlot(itemInHandIndex);

    // If they've got the same item in their hand, it'll need to be updated.
    if (itemInHand != null && itemInHand.getItem() == net.minecraft.init.Items.writable_book) {
        if (!editBookEvent.isCancelled()) {
            CraftItemStack.setItemMeta(itemInHand, editBookEvent.getNewBookMeta());
            if (editBookEvent.isSigning()) {
                itemInHand.func_150996_a(net.minecraft.init.Items.written_book);
            }
        }

        // Client will have updated its idea of the book item; we need to overwrite that
        net.minecraft.inventory.Slot slot = player.openContainer.getSlotFromInventory((net.minecraft.inventory.IInventory) player.inventory, itemInHandIndex);
        player.playerNetServerHandler.sendPacket(new net.minecraft.network.play.server.S2FPacketSetSlot(player.openContainer.windowId, slot.slotNumber, itemInHand));
    }
}
CraftEventFactory.java 文件源码 项目:Cauldron-Old 阅读 20 收藏 0 点赞 0 评论 0
public static void handleEditBookEvent(net.minecraft.entity.player.EntityPlayerMP player, net.minecraft.item.ItemStack newBookItem) {
    int itemInHandIndex = player.inventory.currentItem;

    PlayerEditBookEvent editBookEvent = new PlayerEditBookEvent(player.getBukkitEntity(), player.inventory.currentItem, (BookMeta) CraftItemStack.getItemMeta(player.inventory.getCurrentItem()), (BookMeta) CraftItemStack.getItemMeta(newBookItem), newBookItem.getItem() == net.minecraft.init.Items.written_book);
    player.worldObj.getServer().getPluginManager().callEvent(editBookEvent);
    net.minecraft.item.ItemStack itemInHand = player.inventory.getStackInSlot(itemInHandIndex);

    // If they've got the same item in their hand, it'll need to be updated.
    if (itemInHand != null && itemInHand.getItem() == net.minecraft.init.Items.writable_book) {
        if (!editBookEvent.isCancelled()) {
            CraftItemStack.setItemMeta(itemInHand, editBookEvent.getNewBookMeta());
            if (editBookEvent.isSigning()) {
                itemInHand.func_150996_a(net.minecraft.init.Items.written_book);
            }
        }

        // Client will have updated its idea of the book item; we need to overwrite that
        net.minecraft.inventory.Slot slot = player.openContainer.getSlotFromInventory((net.minecraft.inventory.IInventory) player.inventory, itemInHandIndex);
        player.playerNetServerHandler.sendPacket(new net.minecraft.network.play.server.S2FPacketSetSlot(player.openContainer.windowId, slot.slotNumber, itemInHand));
    }
}
CraftEventFactory.java 文件源码 项目:Cauldron-Reloaded 阅读 16 收藏 0 点赞 0 评论 0
public static void handleEditBookEvent(net.minecraft.entity.player.EntityPlayerMP player, net.minecraft.item.ItemStack newBookItem) {
    int itemInHandIndex = player.inventory.currentItem;

    PlayerEditBookEvent editBookEvent = new PlayerEditBookEvent(player.getBukkitEntity(), player.inventory.currentItem, (BookMeta) CraftItemStack.getItemMeta(player.inventory.getCurrentItem()), (BookMeta) CraftItemStack.getItemMeta(newBookItem), newBookItem.getItem() == net.minecraft.init.Items.written_book);
    player.worldObj.getServer().getPluginManager().callEvent(editBookEvent);
    net.minecraft.item.ItemStack itemInHand = player.inventory.getStackInSlot(itemInHandIndex);

    // If they've got the same item in their hand, it'll need to be updated.
    if (itemInHand != null && itemInHand.getItem() == net.minecraft.init.Items.writable_book) {
        if (!editBookEvent.isCancelled()) {
            CraftItemStack.setItemMeta(itemInHand, editBookEvent.getNewBookMeta());
            if (editBookEvent.isSigning()) {
                itemInHand.func_150996_a(net.minecraft.init.Items.written_book);
            }
        }

        // Client will have updated its idea of the book item; we need to overwrite that
        net.minecraft.inventory.Slot slot = player.openContainer.getSlotFromInventory((net.minecraft.inventory.IInventory) player.inventory, itemInHandIndex);
        player.playerNetServerHandler.sendPacket(new net.minecraft.network.play.server.S2FPacketSetSlot(player.openContainer.windowId, slot.slotNumber, itemInHand));
    }
}
SpellTome.java 文件源码 项目:Zephyr 阅读 24 收藏 0 点赞 0 评论 0
public static ItemStack getSpellTome(Spell spell, User user) {
    ItemStack stack = new ItemStack(Material.WRITTEN_BOOK);
    BookMeta meta = (BookMeta) stack.getItemMeta();

    StringBuilder page = new StringBuilder();

    page.append("Spell: " + spell.getName() + "\n");
    page.append(spell.getDescription() + "\n");
    page.append("Mana Cost: " + spell.getManaCost());
    page.append("\n\n");
    page.append("Cast this spell with /cast " + WordUtils.capitalize(spell.getName()) + "\n\n");
    page.append("Learn this spell by left clicking the book");

    meta.setPages(page.toString());
    meta.setAuthor(user.<Player> getPlayer().getName());
    meta.setDisplayName(ChatColor.GOLD + "Spell Tome" + ChatColor.GRAY + SEPERATOR
            + WordUtils.capitalize(spell.getName()));
    meta.setLore(Lists.newArrayList(ChatColor.GRAY + "Learn by left clicking"));
    stack.setItemMeta(meta);
    return stack;
}
BookCommand.java 文件源码 项目:AdvancedAchievements 阅读 18 收藏 0 点赞 0 评论 0
/**
 * Adds pages to the BookMeta. A Spigot commit in the late days of Minecraft 1.11.2 started enforcing extremely low
 * limits (why? If it's not broken, don't fix it.), with books limited in page size and total number of pages, as
 * well as title length. This function bypasses such limits and restores the original CraftBukkit behaviour. See
 * https://hub.spigotmc.org/stash/projects/SPIGOT/repos/craftbukkit/commits/4acd0f49e07e0912096e79494472535baf0db2ab
 * for more information.
 *
 * @param bookPages
 * @param bookMeta
 */
@SuppressWarnings("unchecked")
private void setBookPages(List<String> bookPages, BookMeta bookMeta) {
    if (plugin.getServerVersion() >= 11) {
        try {
            // Code we're trying to execute: this.pages.add(CraftChatMessage.fromString(page, true)[0]); in
            // CraftMetaBook.java.
            Class<?> craftMetaBookClass = PackageType.CRAFTBUKKIT
                    .getClass(PACKAGE_INVENTORY + "." + CLASS_CRAFT_META_BOOK);
            List<Object> pages = (List<Object>) craftMetaBookClass.getField(FIELD_PAGES)
                    .get(craftMetaBookClass.cast(bookMeta));
            Method fromStringMethod = PackageType.CRAFTBUKKIT
                    .getClass(PACKAGE_UTIL + "." + CLASS_CRAFT_CHAT_MESSAGE)
                    .getMethod(METHOD_FROM_STRING, String.class, boolean.class);
            for (String bookPage : bookPages) {
                pages.add(((Object[]) fromStringMethod.invoke(null, bookPage, true))[0]);
            }
        } catch (Exception e) {
            plugin.getLogger().warning(
                    "Error while creating book pages. Your achievements book may be trimmed down to 50 pages.");
            bookMeta.setPages(bookPages);
        }
    } else {
        bookMeta.setPages(bookPages);
    }
}
CraftEventFactory.java 文件源码 项目:FFoKC 阅读 17 收藏 0 点赞 0 评论 0
public static void handleEditBookEvent(net.minecraft.entity.player.EntityPlayerMP player, net.minecraft.item.ItemStack newBookItem) {
    int itemInHandIndex = player.inventory.currentItem;

    PlayerEditBookEvent editBookEvent = new PlayerEditBookEvent(player.getBukkitEntity(), player.inventory.currentItem, (BookMeta) CraftItemStack.getItemMeta(player.inventory.getCurrentItem()), (BookMeta) CraftItemStack.getItemMeta(newBookItem), newBookItem.getItem() == net.minecraft.init.Items.written_book);
    player.worldObj.getServer().getPluginManager().callEvent(editBookEvent);
    net.minecraft.item.ItemStack itemInHand = player.inventory.getStackInSlot(itemInHandIndex);

    // If they've got the same item in their hand, it'll need to be updated.
    if (itemInHand != null && itemInHand.getItem() == net.minecraft.init.Items.writable_book) {
        if (!editBookEvent.isCancelled()) {
            CraftItemStack.setItemMeta(itemInHand, editBookEvent.getNewBookMeta());
            if (editBookEvent.isSigning()) {
                itemInHand.func_150996_a(net.minecraft.init.Items.written_book);
            }
        }

        // Client will have updated its idea of the book item; we need to overwrite that
        net.minecraft.inventory.Slot slot = player.openContainer.getSlotFromInventory((net.minecraft.inventory.IInventory) player.inventory, itemInHandIndex);
        player.playerNetServerHandler.sendPacket(new net.minecraft.network.play.server.S2FPacketSetSlot(player.openContainer.windowId, slot.slotNumber, itemInHand));
    }
}
ItemBuilder.java 文件源码 项目:SupaCommons 阅读 23 收藏 0 点赞 0 评论 0
/**
 * Sets this book's pages, assuming it is a book.
 * <p />
 * <b>Note: This is a clear and write operation, for appending, see {@link
 * #bookAdd(String...)}</b>
 * <p />
 * <b>UNSAFE</b>
 *
 * @param pages pages to set
 *
 * @return this item builder instance, for chaining
 */
public ItemBuilder bookSet(@Nonnull String... pages) {
  if (pages == null) {
    if (!this.failSilently) {
      throw new IllegalArgumentException("pages cannot be null.");
    }
    return this;
  }
  if (isBookMeta()) {
    try {
      ((BookMeta) this.itemMeta).setPages(pages);
    } catch (Exception e) {
      if (!this.failSilently) {
        e.printStackTrace();
      }
    }
  }
  return this;
}


问题


面经


文章

微信
公众号

扫码关注公众号