Added BlockSpread, BlockForm and BlockFade events.

By: EvilSeph <evilseph@unaligned.org>
This commit is contained in:
Bukkit/Spigot 2011-06-17 14:46:01 -04:00
parent 5d515f5a85
commit c3373081e2
6 changed files with 193 additions and 1 deletions

View file

@ -376,6 +376,24 @@ public abstract class Event implements Serializable {
* @see org.bukkit.event.block.SnowFormEvent
*/
SNOW_FORM (Category.BLOCK),
/**
* Called when a block is formed based on world conditions
*
* @see org.bukkit.event.block.BlockFormEvent
*/
BLOCK_FORM (Category.BLOCK),
/**
* Called when a block spreads based on world conditions
*
* @see org.bukkit.event.block.BlockSpreadEvent
*/
BLOCK_SPREAD (Category.BLOCK),
/**
* Called when a block fades, melts or disappears based on world conditions
*
* @see org.bukkit.event.block.BlockFadeEvent
*/
BLOCK_FADE (Category.BLOCK),
/**
* INVENTORY EVENTS

View file

@ -0,0 +1,48 @@
package org.bukkit.event.block;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.event.Cancellable;
/**
*Called when a block fades, melts or disappears based on world conditions
*/
public class BlockFadeEvent extends BlockEvent implements Cancellable {
private boolean cancelled;
private BlockState newState;
public BlockFadeEvent(Block block, BlockState newState) {
super(Type.BLOCK_FADE, block);
this.newState = newState;
this.cancelled = false;
}
/**
* Gets the state of the block that will be fading
*
* @return the block state
*/
public BlockState getNewState() {
return newState;
}
/**
* Gets the cancellation state of this event. A cancelled event will not
* be executed in the server, but will still pass to other plugins
*
* @return true if this event is cancelled
*/
public boolean isCancelled() {
return cancelled;
}
/**
* Sets the cancellation state of this event. A cancelled event will not
* be executed in the server, but will still pass to other plugins
*
* @param cancel true if you wish to cancel snow from forming during a ice formation
*/
public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}
}

View file

@ -0,0 +1,56 @@
package org.bukkit.event.block;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.event.Cancellable;
/**
* Called when a block is formed or spreads based on world conditions
*/
public class BlockFormEvent extends BlockEvent implements Cancellable {
private boolean cancelled;
private BlockState newState;
public BlockFormEvent(Block block, BlockState newState) {
super(Type.BLOCK_FORM, block);
this.block = block;
this.newState = newState;
this.cancelled = false;
}
public BlockFormEvent(Type type, Block block, BlockState newState) {
super(type, block);
this.block = block;
this.newState = newState;
this.cancelled = false;
}
/**
* Gets the state of the block where it will form or spread to
*
* @return the block state
*/
public BlockState getNewState() {
return newState;
}
/**
* Gets the cancellation state of this event. A cancelled event will not
* be executed in the server, but will still pass to other plugins
*
* @return true if this event is cancelled
*/
public boolean isCancelled() {
return cancelled;
}
/**
* Sets the cancellation state of this event. A cancelled event will not
* be executed in the server, but will still pass to other plugins
*
* @param cancel true if you wish to cancel snow from forming during a ice formation
*/
public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}
}

View file

@ -103,9 +103,32 @@ public class BlockListener implements Listener {
* Called when a world is attempting to place a block during a snowfall
*
* @param event Relevant event details
* @deprecated be prepared to use onBlockForm instead as it will be replacing this event after the RB
*/
@Deprecated
public void onSnowForm(SnowFormEvent event) {}
/**
* Called when a block is formed based on world conditions
*
* @param event Relevant event details
*/
public void onBlockForm(BlockFormEvent event) {}
/**
* Called when a block spreads based on world conditions
*
* @param event Relevant event details
*/
public void onBlockSpread(BlockSpreadEvent event) {}
/**
* Called when a block fades, melts or disappears based on world conditions
*
* @param event Relevant event details
*/
public void onBlockFade(BlockFadeEvent event) {}
/**
* Called when a block is dispensing an item
*

View file

@ -0,0 +1,25 @@
package org.bukkit.event.block;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
/**
*Represents any event that spreads blocks
*/
public class BlockSpreadEvent extends BlockFormEvent {
private Block source;
public BlockSpreadEvent(Block block, Block source, BlockState newState) {
super(Type.BLOCK_SPREAD, block, newState);
this.source = source;
}
/**
* Gets the source block
*
* @return the block state
*/
public Block getSource() {
return source;
}
}

View file

@ -490,6 +490,28 @@ public final class JavaPluginLoader implements PluginLoader {
}
};
case BLOCK_FORM:
return new EventExecutor() {
public void execute(Listener listener, Event event) {
((BlockListener) listener).onBlockForm((BlockFormEvent) event);
}
};
case BLOCK_SPREAD:
return new EventExecutor() {
public void execute(Listener listener, Event event) {
((BlockListener) listener).onBlockSpread((BlockSpreadEvent) event);
}
};
case BLOCK_FADE:
return new EventExecutor() {
public void execute(Listener listener, Event event) {
((BlockListener) listener).onBlockFade((BlockFadeEvent) event);
}
};
case BLOCK_DISPENSE:
return new EventExecutor() {
public void execute(Listener listener, Event event) {
@ -526,7 +548,7 @@ public final class JavaPluginLoader implements PluginLoader {
((WorldListener) listener).onChunkLoad((ChunkLoadEvent) event);
}
};
case CHUNK_POPULATED:
return new EventExecutor() {
public void execute(Listener listener, Event event) {