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

The following examples show how to use br.net.fabiozumbi12.RedProtect.Bukkit.Region#canFire() . 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: McMMOHook.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onPlayerExperience(McMMOPlayerXpGainEvent event) {
    if (event.isCancelled()) {
        return;
    }

    RedProtect.get().logger.debug(LogLevel.DEFAULT, "McMMO McMMOPlayerXpGainEvent event. Skill " + event.getSkill().name());

    Player player = event.getPlayer();
    Region region = RedProtect.get().rm.getTopRegion(player.getLocation());
    if (region == null) {
        return;
    }

    if (!region.canSkill(player)) {
        event.setCancelled(true);
    }

    if (RedProtect.get().config.configRoot().hooks.mcmmo.fix_acrobatics_fire_leveling && event.getSkill().equals(PrimarySkillType.ACROBATICS) && (!region.canFire() || !region.canDeath())) {
        event.setCancelled(true);
    }
}
 
Example 2
Source File: Compat18.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onBlockExplode(BlockExplodeEvent e) {
    RedProtect.get().logger.debug(LogLevel.DEFAULT, "Is BlockListener - BlockExplodeEvent event");
    List<Block> toRemove = new ArrayList<>();
    for (Block b : e.blockList()) {
        Region r = RedProtect.get().rm.getTopRegion(b.getLocation());
        if (!cont.canWorldBreak(b)) {
            toRemove.add(b);
            continue;
        }
        if (r != null && !r.canFire()) {
            toRemove.add(b);
        }
    }
    if (!toRemove.isEmpty()) {
        e.blockList().removeAll(toRemove);
    }
}
 
Example 3
Source File: BlockListener.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onBlockBurn(BlockBurnEvent e) {
    RedProtect.get().logger.debug(LogLevel.BLOCKS, "BlockListener - Is BlockBurnEvent event");

    Block b = e.getBlock();

    Region r = RedProtect.get().rm.getTopRegion(b.getLocation());
    if (r != null && !r.canFire()) {
        e.setCancelled(true);
        return;
    }

    if (!cont.canWorldBreak(b)) {
        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(priority = EventPriority.LOWEST)
public void onEntityExplode(EntityExplodeEvent e) {
    RedProtect.get().logger.debug(LogLevel.BLOCKS, "Is BlockListener - EntityExplodeEvent event");
    List<Block> toRemove = new ArrayList<>();

    Region or = RedProtect.get().rm.getTopRegion(e.getEntity().getLocation());
    for (Block b : e.blockList()) {
        if (b == null) {
            continue;
        }
        RedProtect.get().logger.debug(LogLevel.BLOCKS, "Blocks: " + b.getType().name());
        Location l = b.getLocation();
        Region r = RedProtect.get().rm.getTopRegion(l);
        if (r != null && !r.canFire() || !cont.canWorldBreak(b)) {
            RedProtect.get().logger.debug(LogLevel.BLOCKS, "canWorldBreak Called!");
            //e.setCancelled(true);
            toRemove.add(b);
            continue;
        }

        if (r == null) {
            continue;
        }

        if (r != or) {
            toRemove.add(b);
            continue;
        }

        if (e.getEntity() instanceof LivingEntity && !r.canMobLoot()) {
            toRemove.add(b);
        }
    }
    if (!toRemove.isEmpty()) {
        e.blockList().removeAll(toRemove);
    }
}
 
Example 5
Source File: BlockListener.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onFrameBrake(HangingBreakEvent e) {
    RedProtect.get().logger.debug(LogLevel.BLOCKS, "Is BlockListener - HangingBreakEvent event");

    Entity ent = e.getEntity();
    Location l = e.getEntity().getLocation();

    if ((ent instanceof ItemFrame || ent instanceof Painting) && (e.getCause().toString().equals("EXPLOSION"))) {
        Region r = RedProtect.get().rm.getTopRegion(l);
        if (r != null && !r.canFire()) {
            e.setCancelled(true);
        }
    }
}
 
Example 6
Source File: BlockListener.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onBlockStartBurn(BlockIgniteEvent e) {
    RedProtect.get().logger.debug(LogLevel.BLOCKS, "BlockListener - Is BlockIgniteEvent event");

    Block b = e.getBlock();
    Block bignit = e.getIgnitingBlock();
    if (b == null) {
        return;
    }

    Region r = RedProtect.get().rm.getTopRegion(b.getLocation());
    if (r != null && !r.canFire()) {
        if (e.getIgnitingEntity() != null) {
            if (e.getIgnitingEntity() instanceof Player) {
                Player p = (Player) e.getIgnitingEntity();
                if (!r.canBuild(p)) {
                    RedProtect.get().lang.sendMessage(p, "blocklistener.region.cantplace");
                    e.setCancelled(true);
                    return;
                }
            } else {
                e.setCancelled(true);
                return;
            }
        }

        if (bignit != null && (bignit.getType().equals(Material.FIRE) || bignit.getType().name().contains("LAVA"))) {
            e.setCancelled(true);
            return;
        }
        if (e.getCause().equals(IgniteCause.LIGHTNING) || e.getCause().equals(IgniteCause.EXPLOSION) || e.getCause().equals(IgniteCause.FIREBALL)) {
            e.setCancelled(true);
        }
    }
}
 
Example 7
Source File: BlockListener.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onLightning(LightningStrikeEvent e) {
    RedProtect.get().logger.debug(LogLevel.BLOCKS, "BlockListener - Is LightningStrikeEvent event");
    Location l = e.getLightning().getLocation();
    Region r = RedProtect.get().rm.getTopRegion(l);
    if (r != null && !r.canFire()) {
        e.setCancelled(true);
    }
}
 
Example 8
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);
    }
}