diff --git a/paper-api/src/main/java/org/bukkit/event/player/PlayerHarvestBlockEvent.java b/paper-api/src/main/java/org/bukkit/event/player/PlayerHarvestBlockEvent.java new file mode 100644 index 0000000000..0ee86dca04 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/player/PlayerHarvestBlockEvent.java @@ -0,0 +1,74 @@ +package org.bukkit.event.player; + +import java.util.List; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; + +/** + * This event is called whenever a player harvests a block. + *
+ * A 'harvest' is when a block drops an item (usually some sort of crop) and + * changes state, but is not broken in order to drop the item. + *
+ * This event is not called for when a block is broken, to handle that, listen + * for {@link org.bukkit.event.block.BlockBreakEvent} and + * {@link org.bukkit.event.block.BlockDropItemEvent}. + */ +public class PlayerHarvestBlockEvent extends PlayerEvent implements Cancellable { + + private static final HandlerList handlers = new HandlerList(); + private boolean cancel = false; + private final Block harvestedBlock; + private final List itemsHarvested; + + public PlayerHarvestBlockEvent(@NotNull Player player, @NotNull Block harvestedBlock, @NotNull List itemsHarvested) { + super(player); + this.harvestedBlock = harvestedBlock; + this.itemsHarvested = itemsHarvested; + } + + /** + * Gets the block that is being harvested. + * + * @return The block that is being harvested + */ + @NotNull + public Block getHarvestedBlock() { + return harvestedBlock; + } + + /** + * Gets a list of items that are being harvested from this block. + * + * @return A list of items that are being harvested from this block + */ + @NotNull + public List getItemsHarvested() { + return itemsHarvested; + } + + @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; + } +}