Package org.bukkit.event.world
Class LootGenerateEvent
- java.lang.Object
-
- org.bukkit.event.Event
-
- org.bukkit.event.world.WorldEvent
-
- org.bukkit.event.world.LootGenerateEvent
-
- All Implemented Interfaces:
Cancellable
public class LootGenerateEvent extends WorldEvent implements Cancellable
Called when aLootTable
is generated in the world for anInventoryHolder
. This event is NOT currently called when an entity's loot table has been generated (useEntityDeathEvent.getDrops()
, but WILL be called by plugins invokingLootTable.fillInventory(org.bukkit.inventory.Inventory, java.util.Random, LootContext)
.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.bukkit.event.Event
Event.Result
-
-
Constructor Summary
Constructors Constructor Description LootGenerateEvent(@NotNull World world, @Nullable Entity entity, @Nullable InventoryHolder inventoryHolder, @NotNull LootTable lootTable, @NotNull LootContext lootContext, @NotNull List<ItemStack> items, boolean plugin)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description @Nullable Entity
getEntity()
Get the entity used as context for loot generation (if applicable).static @NotNull HandlerList
getHandlerList()
@NotNull HandlerList
getHandlers()
@Nullable InventoryHolder
getInventoryHolder()
Get the inventory holder in which the loot was generated.@NotNull List<ItemStack>
getLoot()
Get a mutable list of all loot to be generated.@NotNull LootContext
getLootContext()
Get the loot context used to provide context to the loot table's loot generation.@NotNull LootTable
getLootTable()
Get the loot table used to generate loot.boolean
isCancelled()
Gets the cancellation state of this event.boolean
isPlugin()
Check whether or not this event was called as a result of a plugin invokingLootTable.fillInventory(org.bukkit.inventory.Inventory, java.util.Random, LootContext)
.void
setCancelled(boolean cancel)
Sets the cancellation state of this event.void
setLoot(@Nullable Collection<ItemStack> loot)
Set the loot to be generated.-
Methods inherited from class org.bukkit.event.world.WorldEvent
getWorld
-
Methods inherited from class org.bukkit.event.Event
getEventName, isAsynchronous
-
-
-
-
Constructor Detail
-
LootGenerateEvent
public LootGenerateEvent(@NotNull @NotNull World world, @Nullable @Nullable Entity entity, @Nullable @Nullable InventoryHolder inventoryHolder, @NotNull @NotNull LootTable lootTable, @NotNull @NotNull LootContext lootContext, @NotNull @NotNull List<ItemStack> items, boolean plugin)
-
-
Method Detail
-
getEntity
@Nullable public @Nullable Entity getEntity()
Get the entity used as context for loot generation (if applicable). For inventories where entities are not required to generate loot, such as hoppers, null will be returned. This is a convenience method forgetLootContext().getLootedEntity()
.- Returns:
- the entity
-
getInventoryHolder
@Nullable public @Nullable InventoryHolder getInventoryHolder()
Get the inventory holder in which the loot was generated. If the loot was generated as a result of the block being broken, the inventory holder will be null as this event is called post block break.- Returns:
- the inventory holder
-
getLootTable
@NotNull public @NotNull LootTable getLootTable()
Get the loot table used to generate loot.- Returns:
- the loot table
-
getLootContext
@NotNull public @NotNull LootContext getLootContext()
Get the loot context used to provide context to the loot table's loot generation.- Returns:
- the loot context
-
setLoot
public void setLoot(@Nullable @Nullable Collection<ItemStack> loot)
Set the loot to be generated. Null items will be treated as air. Note: the set collection is not the one which will be returned bygetLoot()
.- Parameters:
loot
- the loot to generate, null to clear all loot
-
getLoot
@NotNull public @NotNull List<ItemStack> getLoot()
Get a mutable list of all loot to be generated. Any items added or removed from the returned list will be reflected in the loot generation. Null items will be treated as air.- Returns:
- the loot to generate
-
isPlugin
public boolean isPlugin()
Check whether or not this event was called as a result of a plugin invokingLootTable.fillInventory(org.bukkit.inventory.Inventory, java.util.Random, LootContext)
.- Returns:
- true if plugin caused, false otherwise
-
setCancelled
public void setCancelled(boolean cancel)
Description copied from interface:Cancellable
Sets the cancellation state of this event. A cancelled event will not be executed in the server, but will still pass to other plugins.- Specified by:
setCancelled
in interfaceCancellable
- Parameters:
cancel
- true if you wish to cancel this event
-
isCancelled
public boolean isCancelled()
Description copied from interface:Cancellable
Gets the cancellation state of this event. A cancelled event will not be executed in the server, but will still pass to other plugins- Specified by:
isCancelled
in interfaceCancellable
- Returns:
- true if this event is cancelled
-
getHandlers
@NotNull public @NotNull HandlerList getHandlers()
- Specified by:
getHandlers
in classEvent
-
getHandlerList
@NotNull public static @NotNull HandlerList getHandlerList()
-
-