Reputation: 969
Ok, so I'm making a Bukkit plugin, that should detect cobblestone generators, keep in mind, that I don't want to prevent players from making cobblestone generators, I just want to get the block from the event, so I can do other stuff with that cobblestone.
What I've tried so far:
What I want to do:
Can you please at least point me in the right direction? I've been pulling out my hair for almost 3 hours already.
Thanks to everyone for the help!
EDIT: Solution in the picture below, will retype if requested!
Upvotes: 2
Views: 2868
Reputation:
There are specific events that can catch up with when Cobble is created. Mine Events, Crafting events, Pickup events. Each of these events should let you fetch which block was broken and check if it was an instance or material of Cobblestone.
Upvotes: 0
Reputation: 7143
Good answer from FireBlast709 at Bukkit Forums
This will cancel any cobblestone generation. Basically, if you want to manipulate the cobblestone, you change the cancel line (indicated) to whatever you need.
@EventHandler
public void onFromTo(BlockFromToEvent event){
Material type = event.getBlock().getType();
if (type == Material.WATER || type == Material.STATIONARY_WATER || type == Material.LAVA || type == Material.STATIONARY_LAVA){
Block b = event.getToBlock();
if (b.getType() == Material.AIR){
if (generatesCobble(type, b)){
/* DO WHATEVER YOU NEED WITH THE COBBLE */
event.setCancelled(true);
}
}
}
}
private final BlockFace[] faces = new BlockFace[]{
BlockFace.SELF,
BlockFace.UP,
BlockFace.DOWN,
BlockFace.NORTH,
BlockFace.EAST,
BlockFace.SOUTH,
BlockFace.WEST
};
public boolean generatesCobble(Material type, Block b){
Material mirrorID1 = (type == Material.WATER || type == Material.STATIONARY_WATER ? Material.LAVA : Material.WATER);
Material mirrorID2 = (type == Material.WATER || type == Material.STATIONARY_WATER ? Material.STATIONARY_LAVA : Material.STATIONARY_WATER);
for (BlockFace face : faces){
Block r = b.getRelative(face, 1);
if (r.getType() == mirrorID1 || r.getType() == mirrorID2){
return true;
}
}
return false;
}
Upvotes: 4
Reputation: 69
I think you have to use the BlockFromToEvent and do something like
if ((
(event.getBlock().getType()==Material.LAVA)||
(event.getBlock().getType()==Material.WATER)||
(event.getBlock().getType()==Material.STATIONARY_LAVA)||
(event.getBlock().getType()==Material.STATIONARY_WATER)
) && event.getToBlock().getType()==Material.COBBLESTONE) {
//do what you want
}
Upvotes: 0