aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0417-Add-and-implement-PlayerRecipeBookClickEvent.patch
blob: 0891d484ace624a239d395cbc3c43a04cbcf5f27 (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
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 and implement PlayerRecipeBookClickEvent


diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index bc05121fcda77b1672901fa9bf05ba68af51c77c..4181eaef05589eb1f54c6a3cf76ca98a71bcfed3 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -3117,9 +3117,15 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
             if (!this.player.containerMenu.stillValid(this.player)) {
                 ServerGamePacketListenerImpl.LOGGER.debug("Player {} interacted with invalid menu {}", this.player, this.player.containerMenu);
             } else {
-                this.server.getRecipeManager().byKey(packet.getRecipe()).ifPresent((irecipe) -> {
-                    ((RecipeBookMenu) this.player.containerMenu).handlePlacement(packet.isShiftDown(), irecipe, this.player);
-                });
+                // Paper start - fire event for clicking recipes in the recipe book
+                com.destroystokyo.paper.event.player.PlayerRecipeBookClickEvent event = new com.destroystokyo.paper.event.player.PlayerRecipeBookClickEvent(
+                    player.getBukkitEntity(), org.bukkit.craftbukkit.util.CraftNamespacedKey.fromMinecraft(packet.getRecipe()), packet.isShiftDown());
+                if (event.callEvent() && this.player.containerMenu instanceof RecipeBookMenu<?> recipeBookMenu) { // check if inventory changed during event handling
+                    this.server.getRecipeManager().byKey(org.bukkit.craftbukkit.util.CraftNamespacedKey.toMinecraft(event.getRecipe())).ifPresent((irecipe) -> {
+                        recipeBookMenu.handlePlacement(event.isMakeAll(), irecipe, this.player);
+                    });
+                }
+                // Paper end
             }
         }
     }