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.id == Item.WRITTEN_BOOK.id);
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.id == Item.BOOK_AND_QUILL.id) {
if (!editBookEvent.isCancelled()) {
CraftItemStack.setItemMeta(itemInHand, editBookEvent.getNewBookMeta());
if (editBookEvent.isSigning()) {
itemInHand.id = Item.WRITTEN_BOOK.id;
}
}
// Client will have updated its idea of the book item; we need to overwrite that
Slot slot = player.activeContainer.a((IInventory) player.inventory, itemInHandIndex);
player.playerConnection.sendPacket(new Packet103SetSlot(player.activeContainer.windowId, slot.g, itemInHand));
}
}
CraftEventFactory.java 文件源码
java
阅读 26
收藏 0
点赞 0
评论 0
项目:Almura-Server
作者:
评论列表
文章目录