Reimplemented BlockFlow to use multiple BlockFromToEvents

By: durron597 <martin.jared@gmail.com>
This commit is contained in:
Bukkit/Spigot 2010-12-31 21:17:16 -05:00
parent 7d88f00839
commit 1ec5689002
3 changed files with 15 additions and 87 deletions

View file

@ -1,85 +0,0 @@
package org.bukkit.event.block;
import java.util.HashSet;
import java.util.List;
import org.bukkit.Block;
import org.bukkit.BlockFace;
import org.bukkit.event.Event;
/**
* Holds information for events with a source block and a destination block
*/
public class BlockFlowEvent extends BlockEvent {
protected final HashSet<BlockFlow> faceList;
public BlockFlowEvent(final Event.Type type, final Block block, BlockFace... faces) {
super(type, block);
this.faceList = new HashSet<BlockFlow>();
if (faces != null && faces.length > 0) {
for (BlockFace theFace : faces) {
faceList.add(new BlockFlow(theFace));
}
}
}
public BlockFlowEvent(final Event.Type type, final Block block, List<BlockFace> faces) {
super(type, block);
this.faceList = new HashSet<BlockFlow>();
if (faces != null && faces.size() > 0) {
for (BlockFace theFace : faces) {
faceList.add(new BlockFlow(theFace));
}
}
}
/**
* We don't want plugins changing the eligible flowing faces
* therefore give them a new HashSet instance
*
* @return Block the block is event originated from
*/
public HashSet<BlockFlow> getFaces() {
return new HashSet<BlockFlow>(faceList);
}
/**
* Class that represents a flow direction and whether it's cancelled
*/
public class BlockFlow {
private final BlockFace flowDirection;
private boolean cancelled;
public BlockFlow(BlockFace flowDirection) {
this.flowDirection = flowDirection;
cancelled = false;
}
public BlockFace getFlowDirection() {
return flowDirection;
}
public boolean isCancelled() {
return cancelled;
}
public void setCancelled(boolean cancel) {
cancelled = cancel;
}
@Override
public boolean equals(Object o) {
if (!(o instanceof BlockFlow)) return false;
return equals((BlockFlow) o);
}
public boolean equals(BlockFlow flow) {
return flowDirection.equals(flow.flowDirection);
}
@Override
public int hashCode() {
return flowDirection.hashCode();
}
}
}

View file

@ -2,12 +2,13 @@ package org.bukkit.event.block;
import org.bukkit.Block;
import org.bukkit.BlockFace;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
/**
* Holds information for events with a source block and a destination block
*/
public class BlockFromToEvent extends BlockEvent {
public class BlockFromToEvent extends BlockEvent implements Cancellable {
protected Block from;
protected BlockFace face;
@ -34,4 +35,16 @@ public class BlockFromToEvent extends BlockEvent {
public Block getFromBlock() {
return from;
}
@Override
public boolean isCancelled() {
// TODO Auto-generated method stub
return false;
}
@Override
public void setCancelled(boolean cancel) {
// TODO Auto-generated method stub
}
}

View file

@ -27,7 +27,7 @@ public class BlockListener implements Listener {
*
* @param event Relevant event details
*/
public void onBlockFlow(BlockFlowEvent event) {
public void onBlockFlow(BlockFromToEvent event) {
}
/**