Files
PlazmaBukkitMC/patches/api/feature/sparklypaper/0003-Add-CraftItemRecipeEvent.patch
2025-02-23 20:24:18 +09:00

84 lines
2.6 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrPowerGamerBR <git@mrpowergamerbr.com>
Date: Tue, 25 Jun 2024 02:54:47 -0300
Subject: [PATCH] Add CraftItemRecipeEvent
Used when a player OR a crafter block crafts an item, as an alternative to PrepareItemCraftEvent and CraftItemEvent, because both events are not triggered when a item is crafted from a crafter
diff --git a/src/main/java/net/sparklypower/sparklypaper/event/inventory/CraftItemRecipeEvent.java b/src/main/java/net/sparklypower/sparklypaper/event/inventory/CraftItemRecipeEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..129e5244fd0928fc21d9aa7d4bc28e89c1408be0
--- /dev/null
+++ b/src/main/java/net/sparklypower/sparklypaper/event/inventory/CraftItemRecipeEvent.java
@@ -0,0 +1,70 @@
+package net.sparklypower.sparklypaper.event.inventory;
+
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.Event;
+import org.bukkit.event.HandlerList;
+import org.bukkit.inventory.*;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Called when the recipe of an Item is completed inside a crafting matrix.
+ *
+ * This is an alternate version of [org.bukkit.event.inventory.CraftItemEvent], where this one is called for player crafting items and crafters.
+ */
+public class CraftItemRecipeEvent extends Event implements Cancellable {
+ private static final HandlerList handlers = new HandlerList();
+ private final Recipe recipe;
+ private final ItemStack @Nullable [] matrix;
+ private ItemStack result;
+ private boolean isCancelled = false;
+
+ public CraftItemRecipeEvent(@NotNull ItemStack @Nullable [] matrix, @NotNull Recipe recipe, @Nullable ItemStack result) {
+ this.matrix = matrix;
+ this.recipe = recipe;
+ this.result = result;
+ }
+
+ public void setResult(@Nullable ItemStack result) {
+ this.result = result;
+ }
+
+ @Nullable
+ public ItemStack getResult() {
+ return result;
+ }
+
+ /**
+ * @return A copy of the current recipe on the crafting matrix.
+ */
+ @NotNull
+ public Recipe getRecipe() {
+ return recipe;
+ }
+
+ public @Nullable ItemStack[] getCraftingMatrix() {
+ return matrix;
+ }
+
+ @Override
+ public boolean isCancelled() {
+ return isCancelled;
+ }
+
+ @Override
+ public void setCancelled(boolean cancel) {
+ this.isCancelled = cancel;
+ }
+
+ @NotNull
+ @Override
+ public HandlerList getHandlers() {
+ return handlers;
+ }
+
+ @NotNull
+ public static HandlerList getHandlerList() {
+ return handlers;
+ }
+}
+