aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0468-Add-PlayerLecternPageChangeEvent.patch
blob: 2e62d2becf998f315a361e2f7652c3d5d66b5355 (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
37
38
39
40
41
42
43
44
45
46
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Mon, 23 Nov 2020 12:58:51 -0800
Subject: [PATCH] Add PlayerLecternPageChangeEvent


diff --git a/src/main/java/net/minecraft/world/inventory/LecternMenu.java b/src/main/java/net/minecraft/world/inventory/LecternMenu.java
index 19858ecd7cfaaf0fb09552292bf573bb02b3a6ec..ccba06c419732c63f6b255f5f8c1f7a95f3ecbee 100644
--- a/src/main/java/net/minecraft/world/inventory/LecternMenu.java
+++ b/src/main/java/net/minecraft/world/inventory/LecternMenu.java
@@ -64,6 +64,7 @@ public class LecternMenu extends AbstractContainerMenu {
     @Override
     public boolean clickMenuButton(net.minecraft.world.entity.player.Player player, int id) {
         int j;
+        io.papermc.paper.event.player.PlayerLecternPageChangeEvent playerLecternPageChangeEvent; CraftInventoryLectern bukkitView; // Paper - Add PlayerLecternPageChangeEvent
 
         if (id >= 100) {
             j = id - 100;
@@ -73,11 +74,25 @@ public class LecternMenu extends AbstractContainerMenu {
             switch (id) {
                 case 1:
                     j = this.lecternData.get(0);
-                    this.setData(0, j - 1);
+                    // Paper start - Add PlayerLecternPageChangeEvent
+                    bukkitView = (CraftInventoryLectern) getBukkitView().getTopInventory();
+                    playerLecternPageChangeEvent = new io.papermc.paper.event.player.PlayerLecternPageChangeEvent((org.bukkit.entity.Player) player.getBukkitEntity(), bukkitView.getHolder(), bukkitView.getBook(), io.papermc.paper.event.player.PlayerLecternPageChangeEvent.PageChangeDirection.LEFT, j, j - 1);
+                    if (!playerLecternPageChangeEvent.callEvent()) {
+                        return false;
+                    }
+                    this.setData(0, playerLecternPageChangeEvent.getNewPage());
+                    // Paper end - Add PlayerLecternPageChangeEvent
                     return true;
                 case 2:
                     j = this.lecternData.get(0);
-                    this.setData(0, j + 1);
+                    // Paper start - Add PlayerLecternPageChangeEvent
+                    bukkitView = (CraftInventoryLectern) getBukkitView().getTopInventory();
+                    playerLecternPageChangeEvent = new io.papermc.paper.event.player.PlayerLecternPageChangeEvent((org.bukkit.entity.Player) player.getBukkitEntity(), bukkitView.getHolder(), bukkitView.getBook(), io.papermc.paper.event.player.PlayerLecternPageChangeEvent.PageChangeDirection.RIGHT, j, j + 1);
+                    if (!playerLecternPageChangeEvent.callEvent()) {
+                        return false;
+                    }
+                    this.setData(0, playerLecternPageChangeEvent.getNewPage());
+                    // Paper end - Add PlayerLecternPageChangeEvent
                     return true;
                 case 3:
                     if (!player.mayBuild()) {