aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0369-Add-PlayerRecipeBookClickEvent.patch
blob: add0eaf3d46f2f080c0cfe24602ff5516f79e423 (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
47
48
49
50
51
52
53
54
55
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: JRoy <joshroy126@gmail.com>
Date: Fri, 5 Jun 2020 18:24:06 -0400
Subject: [PATCH] Add PlayerRecipeBookClickEvent


diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index 3455781a47fbececab33406e829ceb392c72a113..b4af560246c1fe102bae9ec9383cbef385bb1887 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -3056,16 +3056,40 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
             if (!this.player.containerMenu.stillValid(this.player)) {
                 ServerGamePacketListenerImpl.LOGGER.debug("Player {} interacted with invalid menu {}", this.player, this.player.containerMenu);
             } else {
+                // Paper start - Add PlayerRecipeBookClickEvent
+                ResourceLocation recipeName = packet.getRecipe();
+                boolean makeAll = packet.isShiftDown();
+                com.destroystokyo.paper.event.player.PlayerRecipeBookClickEvent paperEvent = new com.destroystokyo.paper.event.player.PlayerRecipeBookClickEvent(
+                    this.player.getBukkitEntity(), org.bukkit.craftbukkit.util.CraftNamespacedKey.fromMinecraft(recipeName), makeAll
+                );
+                if (!paperEvent.callEvent()) {
+                    return;
+                }
+                recipeName = CraftNamespacedKey.toMinecraft(paperEvent.getRecipe());
+                makeAll = paperEvent.isMakeAll();
+                if (org.bukkit.event.player.PlayerRecipeBookClickEvent.getHandlerList().getRegisteredListeners().length > 0) {
+                // Paper end - Add PlayerRecipeBookClickEvent
                 // CraftBukkit start - implement PlayerRecipeBookClickEvent
-                org.bukkit.inventory.Recipe recipe = this.cserver.getRecipe(CraftNamespacedKey.fromMinecraft(packet.getRecipe()));
+                org.bukkit.inventory.Recipe recipe = this.cserver.getRecipe(CraftNamespacedKey.fromMinecraft(recipeName)); // Paper
                 if (recipe == null) {
                     return;
                 }
-                org.bukkit.event.player.PlayerRecipeBookClickEvent event = CraftEventFactory.callRecipeBookClickEvent(this.player, recipe, packet.isShiftDown());
+                // Paper start - Add PlayerRecipeBookClickEvent
+                org.bukkit.event.player.PlayerRecipeBookClickEvent event = CraftEventFactory.callRecipeBookClickEvent(this.player, recipe, makeAll);
+                recipeName = CraftNamespacedKey.toMinecraft(((org.bukkit.Keyed) event.getRecipe()).getKey());
+                makeAll = event.isShiftClick();
+                }
+                if (!(this.player.containerMenu instanceof RecipeBookMenu<?, ?> recipeBookMenu)) {
+                    return;
+                }
+                // Paper end - Add PlayerRecipeBookClickEvent
 
                 // Cast to keyed should be safe as the recipe will never be a MerchantRecipe.
-                this.server.getRecipeManager().byKey(CraftNamespacedKey.toMinecraft(((org.bukkit.Keyed) event.getRecipe()).getKey())).ifPresent((recipeholder) -> {
-                    ((RecipeBookMenu) this.player.containerMenu).handlePlacement(event.isShiftClick(), recipeholder, this.player);
+                // Paper start - Add PlayerRecipeBookClickEvent
+                final boolean finalMakeAll = makeAll;
+                this.server.getRecipeManager().byKey(recipeName).ifPresent((recipeholder) -> {
+                    recipeBookMenu.handlePlacement(finalMakeAll, recipeholder, this.player);
+                    // Paper end - Add PlayerRecipeBookClickEvent
                 });
                 // CraftBukkit end
             }