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.WRITABLE_BOOK) {
if (!editBookEvent.isCancelled()) {
if (editBookEvent.isSigning()) {
itemInHand.setItem(Items.WRITTEN_BOOK);
}
CraftMetaBook meta = (CraftMetaBook) editBookEvent.getNewBookMeta();
List<IChatBaseComponent> pages = meta.pages;
for (int i = 0; i < pages.size(); i++) {
pages.set(i, stripEvents(pages.get(i)));
}
CraftItemStack.setItemMeta(itemInHand, meta);
}
// 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));
}
}
CraftEventFactory.java 文件源码
java
阅读 24
收藏 0
点赞 0
评论 0
项目:Craftbukkit
作者:
评论列表
文章目录