mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-06 00:07:56 +01:00
#503: Add PlayerHarvestBlockEvent
By: DiamondDagger590 <diamonddagger590@gmail.com>
This commit is contained in:
parent
f399ada24d
commit
3f517f0191
@ -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.
|
||||||
|
* <br>
|
||||||
|
* 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.
|
||||||
|
* <br>
|
||||||
|
* 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<ItemStack> itemsHarvested;
|
||||||
|
|
||||||
|
public PlayerHarvestBlockEvent(@NotNull Player player, @NotNull Block harvestedBlock, @NotNull List<ItemStack> 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<ItemStack> 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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user