diff options
author | Josh Roy <[email protected]> | 2020-06-23 00:33:08 -0400 |
---|---|---|
committer | GitHub <[email protected]> | 2020-06-22 23:33:08 -0500 |
commit | e6142995170ee746e07f82b1feab44f457a13bc2 (patch) | |
tree | 487b907cd6ec29deac2c92940d359cae76b6fb83 | |
parent | 9bb4e93090cd235a73a3903f8ecbb4f3c0d02019 (diff) | |
download | Paper-e6142995170ee746e07f82b1feab44f457a13bc2.tar.gz Paper-e6142995170ee746e07f82b1feab44f457a13bc2.zip |
Add and implement PlayerRecipeBookClickEvent (#3351)
Co-authored-by: LordKorea <[email protected]>
-rw-r--r-- | Spigot-API-Patches/0212-Add-and-implement-PlayerRecipeBookClickEvent.patch | 96 | ||||
-rw-r--r-- | Spigot-Server-Patches/0548-Add-and-implement-PlayerRecipeBookClickEvent.patch | 29 |
2 files changed, 125 insertions, 0 deletions
diff --git a/Spigot-API-Patches/0212-Add-and-implement-PlayerRecipeBookClickEvent.patch b/Spigot-API-Patches/0212-Add-and-implement-PlayerRecipeBookClickEvent.patch new file mode 100644 index 0000000000..93bd233b85 --- /dev/null +++ b/Spigot-API-Patches/0212-Add-and-implement-PlayerRecipeBookClickEvent.patch @@ -0,0 +1,96 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: LordKorea <[email protected]> +Date: Mon, 11 May 2020 22:38:10 -0400 +Subject: [PATCH] Add and implement PlayerRecipeBookClickEvent + + +diff --git a/src/main/java/com/destroystokyo/paper/event/player/PlayerRecipeBookClickEvent.java b/src/main/java/com/destroystokyo/paper/event/player/PlayerRecipeBookClickEvent.java +new file mode 100644 +index 0000000000000000000000000000000000000000..7fa937d339ee98ad308deebb523fead6522eb262 +--- /dev/null ++++ b/src/main/java/com/destroystokyo/paper/event/player/PlayerRecipeBookClickEvent.java +@@ -0,0 +1,84 @@ ++package com.destroystokyo.paper.event.player; ++ ++import org.bukkit.NamespacedKey; ++import org.bukkit.entity.Player; ++import org.bukkit.event.Cancellable; ++import org.bukkit.event.HandlerList; ++import org.bukkit.event.player.PlayerEvent; ++import org.jetbrains.annotations.NotNull; ++ ++/** ++ * Called when a player clicks a recipe in the recipe book ++ */ ++public class PlayerRecipeBookClickEvent extends PlayerEvent implements Cancellable { ++ private static final HandlerList handlers = new HandlerList(); ++ private boolean cancel = false; ++ @NotNull private NamespacedKey recipe; ++ private boolean makeAll; ++ ++ public PlayerRecipeBookClickEvent(@NotNull Player player, @NotNull NamespacedKey recipe, boolean makeAll) { ++ super(player); ++ this.recipe = recipe; ++ this.makeAll = makeAll; ++ } ++ ++ /** ++ * Gets the namespaced key of the recipe that was clicked by the player ++ * ++ * @return The namespaced key of the recipe ++ */ ++ @NotNull ++ public NamespacedKey getRecipe() { ++ return recipe; ++ } ++ ++ /** ++ * Changes what recipe is requested. This sets the requested recipe to the recipe with the given key ++ * ++ * @param recipe The key of the recipe that should be requested ++ */ ++ public void setRecipe(@NotNull NamespacedKey recipe) { ++ this.recipe = recipe; ++ } ++ ++ /** ++ * Gets a boolean which indicates whether or not the player requested to make the maximum amount of results. This is ++ * true if shift is pressed while the recipe is clicked in the recipe book ++ * ++ * @return {@code true} if shift is pressed while the recipe is clicked ++ */ ++ public boolean isMakeAll() { ++ return makeAll; ++ } ++ ++ /** ++ * Sets whether or not the maximum amount of results should be made. If this is true, the request is handled as if ++ * the player had pressed shift while clicking on the recipe ++ * ++ * @param makeAll {@code true} if the request should attempt to make the maximum amount of results ++ */ ++ public void setMakeAll(boolean makeAll) { ++ this.makeAll = makeAll; ++ } ++ ++ @Override ++ public boolean isCancelled() { ++ return cancel; ++ } ++ ++ @Override ++ public void setCancelled(boolean cancel) { ++ this.cancel = cancel; ++ } ++ ++ @NotNull ++ @Override ++ public HandlerList getHandlers() { ++ return handlers; ++ } ++ ++ @NotNull ++ public static HandlerList getHandlerList() { ++ return handlers; ++ } ++} diff --git a/Spigot-Server-Patches/0548-Add-and-implement-PlayerRecipeBookClickEvent.patch b/Spigot-Server-Patches/0548-Add-and-implement-PlayerRecipeBookClickEvent.patch new file mode 100644 index 0000000000..60db6e2b7a --- /dev/null +++ b/Spigot-Server-Patches/0548-Add-and-implement-PlayerRecipeBookClickEvent.patch @@ -0,0 +1,29 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: JRoy <[email protected]> +Date: Fri, 5 Jun 2020 18:24:06 -0400 +Subject: [PATCH] Add and implement PlayerRecipeBookClickEvent + + +diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java +index 3e5dea60fd043010506436e700601c0e8ffd8f17..639d186971b9f334ed026964f10f1bf33c1e0afc 100644 +--- a/src/main/java/net/minecraft/server/PlayerConnection.java ++++ b/src/main/java/net/minecraft/server/PlayerConnection.java +@@ -2476,9 +2476,15 @@ public class PlayerConnection implements PacketListenerPlayIn { + PlayerConnectionUtils.ensureMainThread(packetplayinautorecipe, this, this.player.getWorldServer()); + this.player.resetIdleTimer(); + if (!this.player.isSpectator() && this.player.activeContainer.windowId == packetplayinautorecipe.b() && this.player.activeContainer.c(this.player) && this.player.activeContainer instanceof ContainerRecipeBook) { +- this.minecraftServer.getCraftingManager().a(packetplayinautorecipe.c()).ifPresent((irecipe) -> { +- ((ContainerRecipeBook) this.player.activeContainer).a(packetplayinautorecipe.d(), 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(packetplayinautorecipe.c()), packetplayinautorecipe.d()); ++ if (event.callEvent()) { ++ this.minecraftServer.getCraftingManager().a(org.bukkit.craftbukkit.util.CraftNamespacedKey.toMinecraft(event.getRecipe())).ifPresent((irecipe) -> { ++ ((ContainerRecipeBook) this.player.activeContainer).a(event.isMakeAll(), irecipe, this.player); ++ }); ++ } ++ // Paper end + } + } + |