mirror of
https://github.com/songoda/UltimateStacker.git
synced 2025-01-27 01:31:20 +01:00
Add StackedItemSpawnEvent
This commit is contained in:
parent
a5642e701c
commit
e55f4622d2
@ -0,0 +1,61 @@
|
||||
package com.craftaro.ultimatestacker.api.events.entity;
|
||||
|
||||
import com.craftaro.ultimatestacker.api.stack.entity.EntityStack;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
* Called before we spawn a stacked items
|
||||
*/
|
||||
public class StackedItemSpawnEvent extends Event implements Cancellable {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private final ItemStack item;
|
||||
private final long amount;
|
||||
private boolean cancelled = false;
|
||||
|
||||
public StackedItemSpawnEvent(ItemStack item, long amount) {
|
||||
this.item = item;
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the item that will be spawned
|
||||
*
|
||||
* @return ItemStack
|
||||
*/
|
||||
public ItemStack getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the amount of items that will be spawned
|
||||
*
|
||||
* @return amount
|
||||
*/
|
||||
public long getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean b) {
|
||||
this.cancelled = true;
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package com.craftaro.ultimatestacker.stackable.item;
|
||||
|
||||
import com.craftaro.core.compatibility.ServerVersion;
|
||||
import com.craftaro.ultimatestacker.UltimateStacker;
|
||||
import com.craftaro.ultimatestacker.api.events.entity.StackedItemSpawnEvent;
|
||||
import com.craftaro.ultimatestacker.api.stack.item.ItemMergeCallback;
|
||||
import com.craftaro.ultimatestacker.api.stack.item.StackedItem;
|
||||
import com.craftaro.ultimatestacker.api.stack.item.StackedItemManager;
|
||||
@ -33,6 +34,10 @@ public class StackedItemManagerImpl implements StackedItemManager {
|
||||
if (item.getType() == Material.AIR) return null;
|
||||
World world = location.getWorld();
|
||||
if (world == null) return null;
|
||||
StackedItemSpawnEvent event = new StackedItemSpawnEvent(item, amount);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) return null;
|
||||
|
||||
Item dropped = world.dropItem(location, item);
|
||||
if (dropped.getItemStack().getType() == Material.AIR) return null;
|
||||
return new StackedItemImpl(dropped, amount);
|
||||
|
Loading…
Reference in New Issue
Block a user