mirror of
https://github.com/PaperMC/Paper.git
synced 2025-03-13 19:28:03 +01:00
#796: Add HopperInventorySearchEvent to select the Inventory that the Hopper pulls/pushes into
By: James Peters <email@jamesdpeters.com>
This commit is contained in:
parent
3bcb2ea2fb
commit
7ba363e6b2
1 changed files with 95 additions and 0 deletions
|
@ -0,0 +1,95 @@
|
|||
package org.bukkit.event.inventory;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.block.BlockEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Event that gets called each time a Hopper attempts to find its
|
||||
* source/attached containers.
|
||||
*/
|
||||
public class HopperInventorySearchEvent extends BlockEvent {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private Inventory inventory;
|
||||
private final ContainerType containerType;
|
||||
private final Block searchBlock;
|
||||
|
||||
public enum ContainerType {
|
||||
|
||||
/**
|
||||
* The source container the hopper is looking for.
|
||||
*
|
||||
* This is the Inventory above the Hopper where it extracts items from.
|
||||
*/
|
||||
SOURCE,
|
||||
/**
|
||||
* The container the hopper is attached to.
|
||||
*
|
||||
* This is the Inventory the Hopper pushes items into.
|
||||
*/
|
||||
DESTINATION;
|
||||
}
|
||||
|
||||
public HopperInventorySearchEvent(@NotNull Inventory inventory, @NotNull ContainerType containerType, @NotNull Block hopper, @NotNull Block searchBlock) {
|
||||
super(hopper);
|
||||
this.inventory = inventory;
|
||||
this.containerType = containerType;
|
||||
this.searchBlock = searchBlock;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the {@link Inventory} that the Hopper will use for its
|
||||
* source/attached Container.
|
||||
*
|
||||
* @param inventory the inventory to use
|
||||
*/
|
||||
public void setInventory(@Nullable Inventory inventory) {
|
||||
this.inventory = inventory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link Inventory} that the Hopper will use for its
|
||||
* source/attached Container.
|
||||
*
|
||||
* @return the inventory which will be used
|
||||
*/
|
||||
@Nullable
|
||||
public Inventory getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Container type the Hopper is searching for.
|
||||
*
|
||||
* @return the container type being searched for
|
||||
*/
|
||||
@NotNull
|
||||
public ContainerType getContainerType() {
|
||||
return containerType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Block that is being searched for an inventory.
|
||||
*
|
||||
* @return block being searched for an inventory
|
||||
*/
|
||||
@NotNull
|
||||
public Block getSearchBlock() {
|
||||
return searchBlock;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue