Search in sources :

Example 11 with RPBlockListener

use of br.net.fabiozumbi12.RedProtect.Bukkit.listeners.RPBlockListener in project RedProtect by FabioZumbi12.

the class RPBlockListener method onLightning.

@EventHandler
public void onLightning(LightningStrikeEvent e) {
    RedProtect.get().logger.debug("RPBlockListener - Is LightningStrikeEvent event");
    Location l = e.getLightning().getLocation();
    Region r = RedProtect.get().rm.getTopRegion(l);
    if (r != null && !r.canFire()) {
        e.setCancelled(true);
    }
}
Also used : Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 12 with RPBlockListener

use of br.net.fabiozumbi12.RedProtect.Bukkit.listeners.RPBlockListener in project RedProtect by FabioZumbi12.

the class RPBlockListener method onBlockGrow.

@EventHandler
public void onBlockGrow(BlockGrowEvent event) {
    RedProtect.get().logger.debug("RPBlockListener - Is BlockGrowEvent event: " + event.getNewState().getType().name());
    if (event.isCancelled()) {
        return;
    }
    Region r = RedProtect.get().rm.getTopRegion(event.getBlock().getLocation());
    if (r != null && !r.canGrow()) {
        event.setCancelled(true);
    }
}
Also used : Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) EventHandler(org.bukkit.event.EventHandler)

Example 13 with RPBlockListener

use of br.net.fabiozumbi12.RedProtect.Bukkit.listeners.RPBlockListener in project RedProtect by FabioZumbi12.

the class RPBlockListener method onLeafDecay.

@EventHandler
public void onLeafDecay(LeavesDecayEvent e) {
    RedProtect.get().logger.debug("RPBlockListener - Is LeavesDecayEvent event");
    if (e.isCancelled()) {
        return;
    }
    Region r = RedProtect.get().rm.getTopRegion(e.getBlock().getLocation());
    if (r != null && !r.leavesDecay()) {
        e.setCancelled(true);
    }
}
Also used : Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) EventHandler(org.bukkit.event.EventHandler)

Example 14 with RPBlockListener

use of br.net.fabiozumbi12.RedProtect.Bukkit.listeners.RPBlockListener in project RedProtect by FabioZumbi12.

the class RPBlockListener method onStructureGrow.

@EventHandler
public void onStructureGrow(StructureGrowEvent e) {
    RedProtect.get().logger.debug("RPBlockListener - Is StructureGrowEvent event");
    if (!RPConfig.getBool("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();
    }
}
Also used : BlockState(org.bukkit.block.BlockState) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) Block(org.bukkit.block.Block) EventHandler(org.bukkit.event.EventHandler)

Example 15 with RPBlockListener

use of br.net.fabiozumbi12.RedProtect.Bukkit.listeners.RPBlockListener in project RedProtect by FabioZumbi12.

the class RPBlockListener method onPistonRetract.

@SuppressWarnings("deprecation")
@EventHandler
public void onPistonRetract(BlockPistonRetractEvent e) {
    RedProtect.get().logger.debug("RPBlockListener - Is BlockPistonRetractEvent event");
    if (RPConfig.getBool("performance.disable-PistonEvent-handler")) {
        return;
    }
    // delay piston
    if (RPConfig.getBool("performance.piston.use-piston-restricter")) {
        if (pistonRetractDelay.contains(e.getBlock().getLocation().toString())) {
            e.setCancelled(true);
            return;
        } else {
            delayRetractPiston(e.getBlock().getLocation().toString());
        }
    }
    World w = e.getBlock().getWorld();
    Boolean antih = RPConfig.getBool("region-settings.anti-hopper");
    Block piston = e.getBlock();
    if (!Bukkit.getBukkitVersion().startsWith("1.8.") && !Bukkit.getBukkitVersion().startsWith("1.9.")) {
        Block b = e.getRetractLocation().getBlock();
        RedProtect.get().logger.debug("BlockPistonRetractEvent not 1.8 event - Block: " + b.getType().name());
        Region pr = RedProtect.get().rm.getTopRegion(piston.getLocation());
        Region br = RedProtect.get().rm.getTopRegion(b.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);
            }
        }
    } else {
        List<Block> blocks = e.getBlocks();
        Region pr = RedProtect.get().rm.getTopRegion(piston.getLocation());
        for (Block b : blocks) {
            RedProtect.get().logger.debug("BlockPistonRetractEvent 1.8 event - Block: " + b.getType().name());
            Region br = RedProtect.get().rm.getTopRegion(b.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;
                }
            }
        }
    }
}
Also used : Block(org.bukkit.block.Block) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) World(org.bukkit.World) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Region (br.net.fabiozumbi12.RedProtect.Bukkit.Region)13 EventHandler (org.bukkit.event.EventHandler)13 Block (org.bukkit.block.Block)7 Listener (org.spongepowered.api.event.Listener)3 Region (br.net.fabiozumbi12.RedProtect.Sponge.Region)2 World (org.bukkit.World)2 BlockState (org.bukkit.block.BlockState)2 Player (org.bukkit.entity.Player)2 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)2 RedProtectAPI (br.net.fabiozumbi12.RedProtect.Bukkit.API.RedProtectAPI)1 MPListener (br.net.fabiozumbi12.RedProtect.Bukkit.hooks.MPListener)1 McMMoListener (br.net.fabiozumbi12.RedProtect.Bukkit.hooks.McMMoListener)1 RPDynmap (br.net.fabiozumbi12.RedProtect.Bukkit.hooks.RPDynmap)1 RPFactions (br.net.fabiozumbi12.RedProtect.Bukkit.hooks.RPFactions)1 RPPlaceHoldersAPI (br.net.fabiozumbi12.RedProtect.Bukkit.hooks.RPPlaceHoldersAPI)1 SkillAPIListener (br.net.fabiozumbi12.RedProtect.Bukkit.hooks.SkillAPIListener)1 RPAddProtection (br.net.fabiozumbi12.RedProtect.Bukkit.listeners.RPAddProtection)1 RPBlockListener (br.net.fabiozumbi12.RedProtect.Bukkit.listeners.RPBlockListener)1 RPCommands (br.net.fabiozumbi12.RedProtect.Bukkit.listeners.RPCommands)1 RPEntityListener (br.net.fabiozumbi12.RedProtect.Bukkit.listeners.RPEntityListener)1