From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: JRoy 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 7e2f2c503f0af6b63ae496beb7cd9b34e61b16c9..dbae4102766837af9b173773c3d1a09439a1d606 100644 --- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java +++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java @@ -3116,16 +3116,40 @@ 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 { + // 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)) { + 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((irecipe) -> { - ((RecipeBookMenu) this.player.containerMenu).handlePlacement(event.isShiftClick(), irecipe, this.player); + // Paper start + final boolean finalMakeAll = makeAll; + this.server.getRecipeManager().byKey(recipeName).ifPresent((irecipe) -> { + ((RecipeBookMenu) this.player.containerMenu).handlePlacement(finalMakeAll, irecipe, this.player); + // Paper end }); // CraftBukkit end }