Skip to content

Commit

Permalink
Log BlockFormEvent by fluids
Browse files Browse the repository at this point in the history
  • Loading branch information
Brokkonaut committed Aug 29, 2018
1 parent 76fce15 commit 1cbc192
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/main/java/de/diddiz/LogBlock/listeners/FluidFlowLogging.java
Expand Up @@ -15,6 +15,7 @@
import org.bukkit.block.data.Waterlogged;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockFormEvent;
import org.bukkit.event.block.BlockFromToEvent;

import static de.diddiz.LogBlock.config.Config.getWorldConfig;
Expand Down Expand Up @@ -95,9 +96,25 @@ public void onBlockFromTo(BlockFromToEvent event) {
}
}

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockForm(BlockFormEvent event) {
final WorldConfig wcfg = getWorldConfig(event.getBlock().getWorld());
if (wcfg != null && (wcfg.isLogging(Logging.WATERFLOW) || wcfg.isLogging(Logging.LAVAFLOW))) {
if (wcfg.isLogging(Logging.LAVAFLOW) && event.getBlock().getType() == Material.WATER && event.getNewState().getType() == Material.COBBLESTONE) {
consumer.queueBlockReplace(new Actor("LavaFlow"), event.getBlock().getBlockData(), event.getNewState());
}
if (wcfg.isLogging(Logging.WATERFLOW) && event.getBlock().getType() == Material.LAVA) {
consumer.queueBlockReplace(new Actor("WaterFlow"), event.getBlock().getBlockData(), event.getNewState());
}
if (wcfg.isLogging(Logging.WATERFLOW) && BukkitUtils.isConcreteBlock(event.getNewState().getType())) {
consumer.queueBlockReplace(new Actor("WaterFlow"), event.getBlock().getBlockData(), event.getNewState());
}
}
}

private static boolean isSurroundedByWater(Block block) {
for (final BlockFace face : new BlockFace[]{BlockFace.NORTH, BlockFace.WEST, BlockFace.EAST, BlockFace.SOUTH}) {
if(block.getRelative(face).getType() == Material.WATER) {
for (final BlockFace face : new BlockFace[] { BlockFace.NORTH, BlockFace.WEST, BlockFace.EAST, BlockFace.SOUTH }) {
if (block.getRelative(face).getType() == Material.WATER) {
return true;
}
}
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/de/diddiz/util/BukkitUtils.java
Expand Up @@ -47,6 +47,7 @@ public class BukkitUtils {
private static final EnumSet<Material> pressurePlates;
private static final EnumSet<Material> woodenDoors;
private static final EnumSet<Material> slabs;
private static final EnumSet<Material> concreteBlocks;

static {
pressurePlates = EnumSet.noneOf(Material.class);
Expand Down Expand Up @@ -352,6 +353,24 @@ public class BukkitUtils {
bedBlocks.add(Material.RED_BED);
bedBlocks.add(Material.WHITE_BED);
bedBlocks.add(Material.YELLOW_BED);

concreteBlocks = EnumSet.noneOf(Material.class);
concreteBlocks.add(Material.BLACK_CONCRETE);
concreteBlocks.add(Material.BLUE_CONCRETE);
concreteBlocks.add(Material.LIGHT_GRAY_CONCRETE);
concreteBlocks.add(Material.BROWN_CONCRETE);
concreteBlocks.add(Material.CYAN_CONCRETE);
concreteBlocks.add(Material.GRAY_CONCRETE);
concreteBlocks.add(Material.GREEN_CONCRETE);
concreteBlocks.add(Material.LIGHT_BLUE_CONCRETE);
concreteBlocks.add(Material.MAGENTA_CONCRETE);
concreteBlocks.add(Material.LIME_CONCRETE);
concreteBlocks.add(Material.ORANGE_CONCRETE);
concreteBlocks.add(Material.PINK_CONCRETE);
concreteBlocks.add(Material.PURPLE_CONCRETE);
concreteBlocks.add(Material.RED_CONCRETE);
concreteBlocks.add(Material.WHITE_CONCRETE);
concreteBlocks.add(Material.YELLOW_CONCRETE);
}

private static final BlockFace[] relativeBlockFaces = new BlockFace[]{
Expand Down Expand Up @@ -494,6 +513,10 @@ public static Set<Material> getContainerBlocks() {
return containerBlocks;
}

public static boolean isConcreteBlock(Material m) {
return concreteBlocks.contains(m);
}

public static String entityName(Entity entity) {
if (entity instanceof Player) {
return ((Player) entity).getName();
Expand Down

0 comments on commit 1cbc192

Please sign in to comment.