Search in sources :

Example 51 with Region

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

the class RPBlockListener method onPistonExtend.

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

Example 52 with Region

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

the class RPBlockListener method onFrameBrake.

@EventHandler
public void onFrameBrake(HangingBreakEvent e) {
    RedProtect.get().logger.debug("Is BlockListener - HangingBreakEvent event");
    if (e.isCancelled()) {
        return;
    }
    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);
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) ItemFrame(org.bukkit.entity.ItemFrame) Location(org.bukkit.Location) Painting(org.bukkit.entity.Painting) EventHandler(org.bukkit.event.EventHandler)

Example 53 with Region

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

the class RPBlockListener method onEntityExplode.

@EventHandler(priority = EventPriority.LOWEST)
public void onEntityExplode(EntityExplodeEvent e) {
    RedProtect.get().logger.debug("Is BlockListener - EntityExplodeEvent event");
    List<Block> toRemove = new ArrayList<>();
    if (e.getEntity() == null) {
        return;
    }
    Region or = RedProtect.get().rm.getTopRegion(e.getEntity().getLocation());
    for (Block b : e.blockList()) {
        if (b == null) {
            continue;
        }
        RedProtect.get().logger.debug("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("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);
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) ArrayList(java.util.ArrayList) Block(org.bukkit.block.Block) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 54 with Region

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

the class RPBlockListener method onBlockBreakGeneric.

@Listener(order = Order.FIRST, beforeModifications = true)
public void onBlockBreakGeneric(ChangeBlockEvent.Break e) {
    if (e.getCause().root().toString().contains("minecraft:fire")) {
        BlockSnapshot b = e.getTransactions().get(0).getOriginal();
        Region r = RedProtect.get().rm.getTopRegion(b.getLocation().get());
        if (r != null && !r.canFire() && !b.getState().getType().equals(BlockTypes.FIRE)) {
            e.setCancelled(true);
            RedProtect.get().logger.debug("blocks", "Tryed to break from FIRE!");
        }
    }
}
Also used : BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) Listener(org.spongepowered.api.event.Listener)

Example 55 with Region

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

the class RPBlockListener method onBlockBreak.

@Listener(order = Order.FIRST, beforeModifications = true)
public void onBlockBreak(ChangeBlockEvent.Break e, @First Player p) {
    RedProtect.get().logger.debug("blocks", "BlockListener - Is ChangeBlockEvent.Break event!");
    BlockSnapshot b = e.getTransactions().get(0).getOriginal();
    Location<World> bloc = b.getLocation().get();
    World w = bloc.getExtent();
    Boolean antih = RedProtect.get().cfgs.getBool("region-settings.anti-hopper");
    Region r = RedProtect.get().rm.getTopRegion(bloc);
    if (!RedProtect.get().ph.hasPerm(p, "redprotect.bypass")) {
        int x = bloc.getBlockX();
        int y = bloc.getBlockY();
        int z = bloc.getBlockZ();
        BlockSnapshot ib = w.createSnapshot(x, y + 1, z);
        if ((antih && !cont.canBreak(p, ib)) || !cont.canBreak(p, b)) {
            RPLang.sendMessage(p, "blocklistener.container.breakinside");
            e.setCancelled(true);
            return;
        }
    }
    if (r == null && RedProtect.get().cfgs.getGlobalFlagList(p.getWorld().getName(), "if-build-false", "break-blocks").contains(b.getState().getType().getName())) {
        return;
    }
    if (r != null && b.getState().getType().equals(BlockTypes.MOB_SPAWNER) && r.allowSpawner(p)) {
        return;
    }
    if (r != null && !r.canBuild(p) && !r.canTree(b) && !r.canMining(b) && !r.canCrops(b) && !r.canBreak(b)) {
        RPLang.sendMessage(p, "blocklistener.region.cantbuild");
        e.setCancelled(true);
    }
}
Also used : BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) World(org.spongepowered.api.world.World) Listener(org.spongepowered.api.event.Listener)

Aggregations

Region (br.net.fabiozumbi12.RedProtect.Bukkit.Region)113 EventHandler (org.bukkit.event.EventHandler)92 Player (org.bukkit.entity.Player)69 Region (br.net.fabiozumbi12.RedProtect.Sponge.Region)47 Listener (org.spongepowered.api.event.Listener)46 Location (org.bukkit.Location)43 World (org.spongepowered.api.world.World)30 Block (org.bukkit.block.Block)26 MyPetPlayer (de.Keyle.MyPet.api.player.MyPetPlayer)20 PvPlayer (me.NoChance.PvPManager.PvPlayer)20 Entity (org.bukkit.entity.Entity)20 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)19 Entity (org.spongepowered.api.entity.Entity)19 LivingEntity (org.bukkit.entity.LivingEntity)16 Player (org.spongepowered.api.entity.living.player.Player)16 World (org.bukkit.World)10 Monster (org.bukkit.entity.Monster)10 Material (org.bukkit.Material)9 ClanPlayer (net.sacredlabyrinth.phaed.simpleclans.ClanPlayer)8 OfflinePlayer (org.bukkit.OfflinePlayer)8