mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-27 23:10:16 +01:00
Added BlockFlowEvent, fixed up BlockFromToEvent, cleaned up
BlockListener By: durron597 <martin.jared@gmail.com>
This commit is contained in:
parent
53b6d54100
commit
ddd950ae40
5 changed files with 100 additions and 18 deletions
|
@ -1,12 +1,13 @@
|
|||
package org.bukkit.event.block;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.Block;
|
||||
|
||||
public class BlockBrokenEvent extends Event {
|
||||
/**
|
||||
* Not implemented yet
|
||||
*/
|
||||
public class BlockBrokenEvent extends BlockEvent {
|
||||
|
||||
public BlockBrokenEvent(Type type) {
|
||||
super(type);
|
||||
// TODO Auto-generated constructor stub
|
||||
public BlockBrokenEvent(Type type, Block block ) {
|
||||
super(type, block);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
72
paper-api/src/org/bukkit/event/block/BlockFlowEvent.java
Normal file
72
paper-api/src/org/bukkit/event/block/BlockFlowEvent.java
Normal file
|
@ -0,0 +1,72 @@
|
|||
package org.bukkit.event.block;
|
||||
|
||||
import java.util.HashSet;
|
||||
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 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the location this player moved to
|
||||
*
|
||||
* @return Block the block is event originated from
|
||||
*/
|
||||
public HashSet<BlockFlow> getFaces() {
|
||||
return 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 flow.flowDirection.equals(flow);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return flowDirection.hashCode();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -23,4 +23,13 @@ public class BlockFromToEvent extends BlockEvent {
|
|||
public BlockFace getFace() {
|
||||
return face;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method for getting the faced block
|
||||
*
|
||||
* @return Block the faced block
|
||||
*/
|
||||
public Block getFacedBlock() {
|
||||
return block.getRelative(face.getModX(), face.getModY(), face.getModZ());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ public class BlockListener implements Listener {
|
|||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onBlockFlow(BlockFromToEvent event) {
|
||||
public void onBlockFlow(BlockFlowEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -54,6 +54,16 @@ public class BlockListener implements Listener {
|
|||
public void onBlockPlaced(BlockPlacedEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when redstone changes
|
||||
* From: the source of the redstone change
|
||||
* To: The redstone dust that changed
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onBlockRedstoneChange(BlockFromToEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player right clicks a block
|
||||
*
|
||||
|
@ -62,13 +72,4 @@ public class BlockListener implements Listener {
|
|||
public void onBlockRightClicked(BlockRightClickedEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when redstone changes
|
||||
* From: the source of the redstone change
|
||||
* To: The redstone dust that changed
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onRedstoneChange(BlockFromToEvent event) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,8 +6,7 @@ package org.bukkit.event.block;
|
|||
import org.bukkit.Block;
|
||||
|
||||
/**
|
||||
* @author jmartin
|
||||
*
|
||||
* Not implemented yet
|
||||
*/
|
||||
public class BlockRightClickedEvent extends BlockEvent {
|
||||
|
||||
|
|
Loading…
Reference in a new issue