Search in sources :

Example 16 with RPBlockListener

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

the class RPBlockListener method onBlockForm.

@EventHandler
public void onBlockForm(BlockFormEvent event) {
    RedProtect.get().logger.debug("RPBlockListener - Is Blockform event!");
    if (event.isCancelled()) {
        return;
    }
    BlockState b = event.getNewState();
    if (b == null) {
        return;
    }
    RedProtect.get().logger.debug("Is Blockform event: " + b.getType().name());
    if (b.getType().equals(Material.SNOW) || b.getType().equals(Material.ICE)) {
        Region r = RedProtect.get().rm.getTopRegion(b.getLocation());
        if (r != null && !r.canIceForm()) {
            event.setCancelled(true);
        }
    }
}
Also used : BlockState(org.bukkit.block.BlockState) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) EventHandler(org.bukkit.event.EventHandler)

Example 17 with RPBlockListener

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

the class RPBlockListener method onFlow.

@EventHandler
public void onFlow(BlockFromToEvent e) {
    RedProtect.get().logger.debug("RPBlockListener - Is BlockFromToEvent event");
    if (e.isCancelled()) {
        return;
    }
    Block bto = e.getToBlock();
    Block bfrom = e.getBlock();
    RedProtect.get().logger.debug("RPBlockListener - 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());
    if (rto != null && bfrom.isLiquid() && !rto.canFlow()) {
        e.setCancelled(true);
        return;
    }
    if (rfrom != null && bfrom.isLiquid() && !rfrom.canFlow()) {
        e.setCancelled(true);
        return;
    }
    if (rto != null && !bto.isEmpty() && !rto.FlowDamage()) {
        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);
    }
}
Also used : Block(org.bukkit.block.Block) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) 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