Paper/patches/server/0408-Add-and-implement-PlayerRecipeBookClickEvent.patch
Jake Potrebic 3c0d6aaed9
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#10085)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
0c7aedbc SPIGOT-7554, PR-954: Add DecoratedPotInventory

CraftBukkit Changes:
53ebb05e3 SPIGOT-7554, PR-1323: Add DecoratedPotInventory
33a2d8773 Ensure that PlayerMoveEvent is always fired where applicable
7df18510f SPIGOT-7555: Don't cast ItemFlags to byte
19aec59ea Use provided case for non-existent OfflinePlayers

Spigot Changes:
e7ce55a3 Remove obsolete PlayerMoveEvent improvements
3e5e22c0 Remove obsolete lowercasing of non existent OfflinePlayer names
2023-12-28 12:47:57 -08:00

56 lines
3.7 KiB
Diff

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 33a9d4047d3a2bd57b12f3517592a333a574fa32..0bc8e06a2a7bc7858433e78fb0ad381d2fcb1f72 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -2970,16 +2970,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
+ 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
// 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
+ 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
// 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
+ final boolean finalMakeAll = makeAll;
+ this.server.getRecipeManager().byKey(recipeName).ifPresent((recipeholder) -> {
+ recipeBookMenu.handlePlacement(finalMakeAll, recipeholder, this.player);
+ // Paper end
});
// CraftBukkit end
}