From eb1da343c839f0d820466c0235ffc079ecaeedd1 Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Sun, 5 Feb 2023 11:01:36 +1100 Subject: [PATCH] SPIGOT-7224: Add events for brewing stands and campfires starting their actions By: FreeSoccerHDX --- .../bukkit/event/block/BrewingStartEvent.java | 49 +++++++++++++++ .../event/block/CampfireStartEvent.java | 62 +++++++++++++++++++ .../event/block/InventoryBlockStartEvent.java | 52 ++++++++++++++++ .../inventory/FurnaceStartSmeltEvent.java | 21 ++----- 4 files changed, 169 insertions(+), 15 deletions(-) create mode 100644 paper-api/src/main/java/org/bukkit/event/block/BrewingStartEvent.java create mode 100644 paper-api/src/main/java/org/bukkit/event/block/CampfireStartEvent.java create mode 100644 paper-api/src/main/java/org/bukkit/event/block/InventoryBlockStartEvent.java diff --git a/paper-api/src/main/java/org/bukkit/event/block/BrewingStartEvent.java b/paper-api/src/main/java/org/bukkit/event/block/BrewingStartEvent.java new file mode 100644 index 0000000000..9e54ef5b60 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/block/BrewingStartEvent.java @@ -0,0 +1,49 @@ +package org.bukkit.event.block; + +import org.bukkit.block.Block; +import org.bukkit.event.HandlerList; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; + +/** + * Called when a brewing stand starts to brew. + */ +public class BrewingStartEvent extends InventoryBlockStartEvent { + + private static final HandlerList handlers = new HandlerList(); + private int brewingTime; + + public BrewingStartEvent(@NotNull final Block furnace, @NotNull ItemStack source, int brewingTime) { + super(furnace, source); + this.brewingTime = brewingTime; + } + + /** + * Gets the total brew time associated with this event. + * + * @return the total brew time + */ + public int getTotalBrewTime() { + return brewingTime; + } + + /** + * Sets the total brew time for this event. + * + * @param brewTime the new total brew time + */ + public void setTotalBrewTime(int brewTime) { + this.brewingTime = brewTime; + } + + @NotNull + @Override + public HandlerList getHandlers() { + return handlers; + } + + @NotNull + public static HandlerList getHandlerList() { + return handlers; + } +} diff --git a/paper-api/src/main/java/org/bukkit/event/block/CampfireStartEvent.java b/paper-api/src/main/java/org/bukkit/event/block/CampfireStartEvent.java new file mode 100644 index 0000000000..53119742be --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/block/CampfireStartEvent.java @@ -0,0 +1,62 @@ +package org.bukkit.event.block; + +import org.bukkit.block.Block; +import org.bukkit.event.HandlerList; +import org.bukkit.inventory.CampfireRecipe; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; + +/** + * Called when a Campfire starts to cook. + */ +public class CampfireStartEvent extends InventoryBlockStartEvent { + + private static final HandlerList handlers = new HandlerList(); + private int cookingTime; + private CampfireRecipe campfireRecipe; + + public CampfireStartEvent(@NotNull final Block furnace, @NotNull ItemStack source, @NotNull CampfireRecipe recipe) { + super(furnace, source); + this.cookingTime = recipe.getCookingTime(); + this.campfireRecipe = recipe; + } + + /** + * Gets the CampfireRecipe associated with this event. + * + * @return the CampfireRecipe being cooked + */ + @NotNull + public CampfireRecipe getRecipe() { + return campfireRecipe; + } + + /** + * Gets the total cook time associated with this event. + * + * @return the total cook time + */ + public int getTotalCookTime() { + return cookingTime; + } + + /** + * Sets the total cook time for this event. + * + * @param cookTime the new total cook time + */ + public void setTotalCookTime(int cookTime) { + this.cookingTime = cookTime; + } + + @NotNull + @Override + public HandlerList getHandlers() { + return handlers; + } + + @NotNull + public static HandlerList getHandlerList() { + return handlers; + } +} diff --git a/paper-api/src/main/java/org/bukkit/event/block/InventoryBlockStartEvent.java b/paper-api/src/main/java/org/bukkit/event/block/InventoryBlockStartEvent.java new file mode 100644 index 0000000000..12d8d5f50a --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/block/InventoryBlockStartEvent.java @@ -0,0 +1,52 @@ +package org.bukkit.event.block; + +import org.bukkit.Warning; +import org.bukkit.block.Block; +import org.bukkit.event.HandlerList; +import org.bukkit.event.inventory.FurnaceStartSmeltEvent; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; + +/** + * Used when: + * + * + * @deprecated draft API + */ +@Deprecated +@Warning(false) +public class InventoryBlockStartEvent extends BlockEvent { + + private static final HandlerList handlers = new HandlerList(); + private final ItemStack source; + + public InventoryBlockStartEvent(@NotNull final Block block, @NotNull ItemStack source) { + super(block); + this.source = source; + } + + /** + * Gets the source ItemStack for this event. + * + * @return the source ItemStack + */ + @NotNull + public ItemStack getSource() { + return source; + } + + @NotNull + @Override + public HandlerList getHandlers() { + return handlers; + } + + @NotNull + public static HandlerList getHandlerList() { + return handlers; + } +} diff --git a/paper-api/src/main/java/org/bukkit/event/inventory/FurnaceStartSmeltEvent.java b/paper-api/src/main/java/org/bukkit/event/inventory/FurnaceStartSmeltEvent.java index 533a33dbd4..1440c61155 100644 --- a/paper-api/src/main/java/org/bukkit/event/inventory/FurnaceStartSmeltEvent.java +++ b/paper-api/src/main/java/org/bukkit/event/inventory/FurnaceStartSmeltEvent.java @@ -2,34 +2,25 @@ package org.bukkit.event.inventory; import org.bukkit.block.Block; import org.bukkit.event.HandlerList; -import org.bukkit.event.block.BlockEvent; +import org.bukkit.event.block.InventoryBlockStartEvent; import org.bukkit.inventory.CookingRecipe; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; -public class FurnaceStartSmeltEvent extends BlockEvent { +/** + * Called when a Furnace starts smelting. + */ +public class FurnaceStartSmeltEvent extends InventoryBlockStartEvent { private static final HandlerList handlers = new HandlerList(); - private final ItemStack source; private final CookingRecipe recipe; private int totalCookTime; public FurnaceStartSmeltEvent(@NotNull final Block furnace, @NotNull ItemStack source, @NotNull final CookingRecipe recipe) { - super(furnace); - this.source = source; + super(furnace, source); this.recipe = recipe; this.totalCookTime = recipe.getCookingTime(); } - /** - * Gets the source ItemStack for this event - * - * @return the source ItemStack - */ - @NotNull - public ItemStack getSource() { - return source; - } - /** * Gets the FurnaceRecipe associated with this event *