Java Code Examples for br.net.fabiozumbi12.RedProtect.Bukkit.Region#sameLeaders()

The following examples show how to use br.net.fabiozumbi12.RedProtect.Bukkit.Region#sameLeaders() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlockListener.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onStructureGrow(StructureGrowEvent e) {
    RedProtect.get().logger.debug(LogLevel.BLOCKS, "BlockListener - Is StructureGrowEvent event");
    if (!RedProtect.get().config.configRoot().region_settings.deny_structure_bypass_regions) {
        return;
    }
    Region rfrom = RedProtect.get().rm.getTopRegion(e.getLocation());
    for (BlockState bstt : e.getBlocks()) {
        Region rto = RedProtect.get().rm.getTopRegion(bstt.getLocation());
        Block bloc = bstt.getLocation().getBlock();
        //deny blocks spread in/out regions
        if (rfrom != null && rto != null && rfrom != rto && !rfrom.sameLeaders(rto)) {
            bstt.setType(bloc.getType());
        }
        if (rfrom == null && rto != null) {
            bstt.setType(bloc.getType());
        }
        if (rfrom != null && rto == null) {
            bstt.setType(bloc.getType());
        }
        bstt.update();
    }
}
 
Example 2
Source File: BlockListener.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onFlow(BlockFromToEvent e) {
    RedProtect.get().logger.debug(LogLevel.BLOCKS, "BlockListener - Is BlockFromToEvent event");

    Block bto = e.getToBlock();
    Block bfrom = e.getBlock();
    RedProtect.get().logger.debug(LogLevel.BLOCKS, "BlockListener - Is BlockFromToEvent event is to " + bto.getType().name() + " from " + bfrom.getType().name());
    Region rto = RedProtect.get().rm.getTopRegion(bto.getLocation());
    Region rfrom = RedProtect.get().rm.getTopRegion(bfrom.getLocation());
    boolean isLiquid = bfrom.isLiquid() || bfrom.getType().name().contains("BUBBLE_COLUMN") || bfrom.getType().name().contains("KELP");
    if (rto != null && isLiquid && !rto.canFlow()) {
        e.setCancelled(true);
        return;
    }
    if (rfrom != null && isLiquid && !rfrom.canFlow()) {
        e.setCancelled(true);
        return;
    }
    if (rto != null && !bto.isEmpty() && !rto.canFlowDamage()) {
        e.setCancelled(true);
        return;
    }

    //deny blocks spread in/out regions
    if (rfrom != null && rto != null && rfrom != rto && !rfrom.sameLeaders(rto)) {
        e.setCancelled(true);
        return;
    }
    if (rfrom == null && rto != null) {
        e.setCancelled(true);
    }
}
 
Example 3
Source File: BlockListener.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onFireSpread(BlockSpreadEvent e) {
    RedProtect.get().logger.debug(LogLevel.BLOCKS, "BlockListener - Is BlockSpreadEvent event");

    Block bfrom = e.getSource();
    Block bto = e.getBlock();
    RedProtect.get().logger.debug(LogLevel.BLOCKS, "Is BlockSpreadEvent event, source is " + bfrom.getType().name());
    Region rfrom = RedProtect.get().rm.getTopRegion(bfrom.getLocation());
    Region rto = RedProtect.get().rm.getTopRegion(bto.getLocation());
    if ((e.getNewState().getType().equals(Material.FIRE) || e.getNewState().getType().name().contains("LAVA")) && rfrom != null && !rfrom.canFire()) {
        e.setCancelled(true);
        return;
    }

    if ((e.getNewState().getType().equals(Material.VINE) ||
            e.getNewState().getType().name().contains("SEAGRASS") ||
            e.getNewState().getType().name().contains("MUSHROOM") ||
            e.getNewState().getType().name().contains("KELP") ||
            e.getNewState().getType().name().contains("BAMBOO") ||
            e.getNewState().getType().name().contains("SUGAR_CANE"))
            && ((rfrom != null && !rfrom.canGrow()) || (rto != null && !rto.canGrow()))) {
        e.setCancelled(true);
        return;
    }

    //deny blocks spread in/out regions
    if (rfrom != null && rto != null && rfrom != rto && !rfrom.sameLeaders(rto)) {
        e.setCancelled(true);
        return;
    }
    if (rfrom == null && rto != null) {
        e.setCancelled(true);
        return;
    }
    if (rfrom != null && rto == null) {
        e.setCancelled(true);
    }
}
 
Example 4
Source File: BlockListener.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onPistonExtend(BlockPistonExtendEvent e) {
    RedProtect.get().logger.debug(LogLevel.BLOCKS, "BlockListener - Is BlockPistonExtendEvent event");
    if (RedProtect.get().config.configRoot().performance.disable_PistonEvent_handler) {
        return;
    }

    Block piston = e.getBlock();
    List<Block> blocks = e.getBlocks();
    Region pr = RedProtect.get().rm.getTopRegion(piston.getLocation());
    Boolean antih = RedProtect.get().config.configRoot().region_settings.anti_hopper;
    World w = e.getBlock().getWorld();
    for (Block b : blocks) {
        RedProtect.get().logger.debug(LogLevel.BLOCKS, "BlockPistonExtendEvent event - Block: " + b.getType().name());
        RedProtect.get().logger.debug(LogLevel.BLOCKS, "BlockPistonExtendEvent event - Relative: " + b.getRelative(e.getDirection()).getType().name());
        Region br = RedProtect.get().rm.getTopRegion(b.getRelative(e.getDirection()).getLocation());
        if (pr == null && br != null || (pr != null && br != null && pr != br && !pr.sameLeaders(br))) {
            e.setCancelled(true);
            return;
        }
        if (antih) {
            int x = b.getX();
            int y = b.getY();
            int z = b.getZ();
            Block ib = w.getBlockAt(x, y + 1, z);
            if (!cont.canWorldBreak(ib) || !cont.canWorldBreak(b)) {
                e.setCancelled(true);
                return;
            }
        }
    }
}