aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/unapplied/server/1028-Add-PlayerInsertLecternBookEvent.patch
blob: f15585222fd59c22135fef0a0302f8f5438b836c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Mariell Hoversholm <proximyst@proximyst.com>
Date: Sun, 29 Sep 2024 16:21:26 +0200
Subject: [PATCH] Add PlayerInsertLecternBookEvent


diff --git a/src/main/java/net/minecraft/world/level/block/LecternBlock.java b/src/main/java/net/minecraft/world/level/block/LecternBlock.java
index d7e14ee2c11f34703b63fcd2e2ad5257003e14c8..70f2e6278e2d970245ca5b46fbd9ffae4727b47b 100644
--- a/src/main/java/net/minecraft/world/level/block/LecternBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/LecternBlock.java
@@ -158,7 +158,24 @@ public class LecternBlock extends BaseEntityBlock {
         BlockEntity tileentity = world.getBlockEntity(pos);
 
         if (tileentity instanceof LecternBlockEntity tileentitylectern) {
-            tileentitylectern.setBook(stack.consumeAndReturn(1, user));
+            // Paper start - Add PlayerInsertLecternBookEvent
+            ItemStack eventSourcedBookStack = null;
+            if (user instanceof final net.minecraft.server.level.ServerPlayer serverPlayer) {
+                final io.papermc.paper.event.player.PlayerInsertLecternBookEvent event = new io.papermc.paper.event.player.PlayerInsertLecternBookEvent(
+                    serverPlayer.getBukkitEntity(),
+                    org.bukkit.craftbukkit.block.CraftBlock.at(world, pos),
+                    org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(stack.copyWithCount(1))
+                );
+                if (!event.callEvent()) return;
+                eventSourcedBookStack = org.bukkit.craftbukkit.inventory.CraftItemStack.unwrap(event.getBook());
+            }
+            if (eventSourcedBookStack == null) {
+                eventSourcedBookStack = stack.consumeAndReturn(1, user);
+            } else {
+                stack.consume(1, user);
+            }
+            tileentitylectern.setBook(eventSourcedBookStack);
+            // Paper end - Add PlayerInsertLecternBookEvent
             LecternBlock.resetBookState(user, world, pos, state, true);
             world.playSound((Player) null, pos, SoundEvents.BOOK_PUT, SoundSource.BLOCKS, 1.0F, 1.0F);
         }