2022-07-27 22:46:05 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: JRoy <joshroy126@gmail.com>
|
|
|
|
Date: Fri, 5 Jun 2020 18:24:06 -0400
|
2024-01-20 23:13:41 +01:00
|
|
|
Subject: [PATCH] Add PlayerRecipeBookClickEvent
|
2022-07-27 22:46:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
2024-06-14 14:11:52 +02:00
|
|
|
index b6895f7f6df5519f6cc550f154ecc2c3b9043b8f..5e27b8c2ba4ba009f4c1f155760d0c1d93e220c5 100644
|
2022-07-27 22:46:05 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
2024-06-13 22:14:13 +02:00
|
|
|
@@ -3058,16 +3058,40 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
|
2022-07-27 22:46:05 +02:00
|
|
|
if (!this.player.containerMenu.stillValid(this.player)) {
|
|
|
|
ServerGamePacketListenerImpl.LOGGER.debug("Player {} interacted with invalid menu {}", this.player, this.player.containerMenu);
|
|
|
|
} else {
|
2024-01-20 23:13:41 +01:00
|
|
|
+ // Paper start - Add PlayerRecipeBookClickEvent
|
2023-08-06 02:21:59 +02:00
|
|
|
+ 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;
|
2022-07-27 22:46:05 +02:00
|
|
|
+ }
|
2023-08-06 02:21:59 +02:00
|
|
|
+ recipeName = CraftNamespacedKey.toMinecraft(paperEvent.getRecipe());
|
|
|
|
+ makeAll = paperEvent.isMakeAll();
|
|
|
|
+ if (org.bukkit.event.player.PlayerRecipeBookClickEvent.getHandlerList().getRegisteredListeners().length > 0) {
|
2024-01-20 23:13:41 +01:00
|
|
|
+ // Paper end - Add PlayerRecipeBookClickEvent
|
2023-08-06 02:21:59 +02:00
|
|
|
// 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());
|
2024-01-20 23:13:41 +01:00
|
|
|
+ // Paper start - Add PlayerRecipeBookClickEvent
|
2023-08-06 02:21:59 +02:00
|
|
|
+ org.bukkit.event.player.PlayerRecipeBookClickEvent event = CraftEventFactory.callRecipeBookClickEvent(this.player, recipe, makeAll);
|
|
|
|
+ recipeName = CraftNamespacedKey.toMinecraft(((org.bukkit.Keyed) event.getRecipe()).getKey());
|
|
|
|
+ makeAll = event.isShiftClick();
|
|
|
|
+ }
|
2024-06-14 14:11:52 +02:00
|
|
|
+ if (!(this.player.containerMenu instanceof RecipeBookMenu<?, ?> recipeBookMenu)) {
|
2023-08-06 02:21:59 +02:00
|
|
|
+ return;
|
|
|
|
+ }
|
2024-01-20 23:13:41 +01:00
|
|
|
+ // Paper end - Add PlayerRecipeBookClickEvent
|
2023-08-06 02:21:59 +02:00
|
|
|
|
|
|
|
// Cast to keyed should be safe as the recipe will never be a MerchantRecipe.
|
2023-09-22 06:05:18 +02:00
|
|
|
- this.server.getRecipeManager().byKey(CraftNamespacedKey.toMinecraft(((org.bukkit.Keyed) event.getRecipe()).getKey())).ifPresent((recipeholder) -> {
|
|
|
|
- ((RecipeBookMenu) this.player.containerMenu).handlePlacement(event.isShiftClick(), recipeholder, this.player);
|
2024-01-20 23:13:41 +01:00
|
|
|
+ // Paper start - Add PlayerRecipeBookClickEvent
|
2023-08-06 02:21:59 +02:00
|
|
|
+ final boolean finalMakeAll = makeAll;
|
2023-09-22 06:05:18 +02:00
|
|
|
+ this.server.getRecipeManager().byKey(recipeName).ifPresent((recipeholder) -> {
|
|
|
|
+ recipeBookMenu.handlePlacement(finalMakeAll, recipeholder, this.player);
|
2024-01-20 23:13:41 +01:00
|
|
|
+ // Paper end - Add PlayerRecipeBookClickEvent
|
2023-08-06 02:21:59 +02:00
|
|
|
});
|
|
|
|
// CraftBukkit end
|
2022-07-27 22:46:05 +02:00
|
|
|
}
|