Added dispenser event.
This commit is contained in:
parent
8b13c8827c
commit
b87835c16d
@ -363,6 +363,13 @@ public abstract class Event implements Serializable {
|
||||
*/
|
||||
BLOCK_PLACE (Category.BLOCK),
|
||||
|
||||
/**
|
||||
* Called when a block dispenses something
|
||||
*
|
||||
* @see org.bukkit.event.block.BlockPlaceEvent
|
||||
*/
|
||||
BLOCK_DISPENSE (Category.BLOCK),
|
||||
|
||||
/**
|
||||
* Called when a block is destroyed from being burnt by fire
|
||||
*
|
||||
|
77
src/main/java/org/bukkit/event/block/BlockDispenseEvent.java
Normal file
77
src/main/java/org/bukkit/event/block/BlockDispenseEvent.java
Normal file
@ -0,0 +1,77 @@
|
||||
package org.bukkit.event.block;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
/**
|
||||
* Event called on dispense of an item from a block.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class BlockDispenseEvent extends BlockEvent implements Cancellable {
|
||||
|
||||
private boolean cancelled = false;
|
||||
private ItemStack item;
|
||||
private Vector velocity;
|
||||
|
||||
public BlockDispenseEvent(Block block, ItemStack dispensed, Vector velocity) {
|
||||
super(Type.BLOCK_DISPENSE, block);
|
||||
this.item = dispensed;
|
||||
this.velocity = velocity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the item that is being dispensed. Modifying the returned item
|
||||
* will have no effect.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public ItemStack getItem() {
|
||||
return item.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the item being dispensed.
|
||||
*
|
||||
* @param item
|
||||
*/
|
||||
public void setItem(ItemStack item) {
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the velocity. Modifying the returned Vector will not
|
||||
* change the velocity.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Vector getVelocity() {
|
||||
return velocity.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the velocity.
|
||||
*
|
||||
* @param vel
|
||||
*/
|
||||
public void setVelocity(Vector vel) {
|
||||
velocity = vel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if the event was cancelled.
|
||||
*/
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent dispensing.
|
||||
*/
|
||||
public void setCancelled(boolean cancel) {
|
||||
cancelled = cancel;
|
||||
}
|
||||
|
||||
}
|
@ -116,4 +116,12 @@ public class BlockListener implements Listener {
|
||||
*/
|
||||
public void onSnowForm(SnowFormEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a block is dispensing an item
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onBlockDispense(BlockDispenseEvent event) {
|
||||
}
|
||||
}
|
||||
|
@ -194,6 +194,11 @@ public class ItemStack {
|
||||
return item.getAmount() == getAmount() && item.getTypeId() == getTypeId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack clone() {
|
||||
return new ItemStack(type, amount, durability);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 11;
|
||||
|
@ -438,6 +438,12 @@ public final class JavaPluginLoader implements PluginLoader {
|
||||
((BlockListener) listener).onSnowForm((SnowFormEvent) event);
|
||||
}
|
||||
};
|
||||
case BLOCK_DISPENSE:
|
||||
return new EventExecutor() {
|
||||
public void execute(Listener listener, Event event) {
|
||||
((BlockListener) listener).onBlockDispense((BlockDispenseEvent) event);
|
||||
}
|
||||
};
|
||||
|
||||
// Server Events
|
||||
case PLUGIN_ENABLE:
|
||||
|
Loading…
x
Reference in New Issue
Block a user