Search in sources :

Example 71 with Listener

use of org.spongepowered.api.event.Listener 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 72 with Listener

use of org.spongepowered.api.event.Listener 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)

Example 73 with Listener

use of org.spongepowered.api.event.Listener in project RedProtect by FabioZumbi12.

the class RPBlockListener method onBlockStartBurn.

/*
    @Listener
    public void onFrameBrake(HangingBreakEvent e) {
    	if (e.isCancelled()){
    		return;
    	}
    	RedProtect.get().logger.debug("Is BlockListener - HangingBreakEvent event");
    	Entity ent = e.getEntity();
    	Location l = e.getEntity().getLocation();		
    	
    	if ((ent instanceof ItemFrame || ent instanceof Painting) && (e.getCause().toPlain().equals("EXPLOSION"))) {
    		Region r = RedProtect.get().rm.getTopRegion(l);
    		if (r != null && !r.canFire()){
    			e.setCancelled(true);
        		return;
    		}
        }    
    }
    */
@Listener(order = Order.FIRST, beforeModifications = true)
public void onBlockStartBurn(IgniteEntityEvent e) {
    Entity b = e.getTargetEntity();
    Cause ignit = e.getCause();
    if (b == null) {
        return;
    }
    RedProtect.get().logger.debug("blocks", "Is BlockIgniteEvent event. Canceled? " + e.isCancelled());
    Region r = RedProtect.get().rm.getTopRegion(b.getLocation());
    if (r != null && !r.canFire()) {
        if (ignit.first(Player.class).isPresent()) {
            Player p = ignit.first(Player.class).get();
            if (!r.canBuild(p)) {
                RPLang.sendMessage(p, "blocklistener.region.cantplace");
                e.setCancelled(true);
                return;
            }
        } else {
            e.setCancelled(true);
            return;
        }
        if (ignit.first(BlockSnapshot.class).isPresent() && (ignit.first(BlockSnapshot.class).get().getState().getType().equals(BlockTypes.FIRE) || ignit.first(BlockSnapshot.class).get().getState().getType().getName().contains("lava"))) {
            e.setCancelled(true);
            return;
        }
        if (ignit.first(Lightning.class).isPresent() || ignit.first(Explosion.class).isPresent() || ignit.first(Fireball.class).isPresent()) {
            e.setCancelled(true);
        }
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.living.player.Player) Explosion(org.spongepowered.api.world.explosion.Explosion) Lightning(org.spongepowered.api.entity.weather.Lightning) Cause(org.spongepowered.api.event.cause.Cause) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) Listener(org.spongepowered.api.event.Listener)

Example 74 with Listener

use of org.spongepowered.api.event.Listener in project RedProtect by FabioZumbi12.

the class RPBlockListener method onLightning.

@Listener(order = Order.FIRST, beforeModifications = true)
public void onLightning(LightningEvent.Pre e, @First Lightning light) {
    RedProtect.get().logger.debug("blocks", "Is LightningStrikeEvent event");
    Location<World> l = light.getLocation();
    Region r = RedProtect.get().rm.getTopRegion(l);
    if (r != null && !r.canFire()) {
        e.setCancelled(true);
    }
}
Also used : Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) World(org.spongepowered.api.world.World) Listener(org.spongepowered.api.event.Listener)

Example 75 with Listener

use of org.spongepowered.api.event.Listener in project RedProtect by FabioZumbi12.

the class RPBlockListener method onInteractBlock.

@Listener(order = Order.FIRST, beforeModifications = true)
public void onInteractBlock(InteractBlockEvent event, @First Player p) {
    BlockSnapshot b = event.getTargetBlock();
    Location<World> l = null;
    RedProtect.get().logger.debug("player", "RPBlockListener - Is InteractBlockEvent event");
    if (!b.getState().getType().equals(BlockTypes.AIR)) {
        l = b.getLocation().get();
        RedProtect.get().logger.debug("player", "RPBlockListener - Is InteractBlockEvent event. The block is " + b.getState().getType().getName());
    } else {
        l = p.getLocation();
    }
    Region r = RedProtect.get().rm.getTopRegion(l);
    if (r != null) {
        ItemType itemInHand = ItemTypes.NONE;
        if (p.getItemInHand(HandTypes.MAIN_HAND).isPresent()) {
            itemInHand = p.getItemInHand(HandTypes.MAIN_HAND).get().getItem();
        } else if (p.getItemInHand(HandTypes.OFF_HAND).isPresent()) {
            itemInHand = p.getItemInHand(HandTypes.OFF_HAND).get().getItem();
        }
        if (itemInHand.equals(ItemTypes.ARMOR_STAND) && !r.canBuild(p)) {
            RPLang.sendMessage(p, "blocklistener.region.cantbuild");
            event.setCancelled(true);
        }
    }
}
Also used : ItemType(org.spongepowered.api.item.ItemType) 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

Listener (org.spongepowered.api.event.Listener)360 Player (org.spongepowered.api.entity.living.player.Player)118 World (org.spongepowered.api.world.World)97 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)65 Entity (org.spongepowered.api.entity.Entity)58 Region (br.net.fabiozumbi12.RedProtect.Sponge.Region)46 Text (org.spongepowered.api.text.Text)46 ItemStack (org.spongepowered.api.item.inventory.ItemStack)45 Location (org.spongepowered.api.world.Location)45 Sponge (org.spongepowered.api.Sponge)22 BlockType (org.spongepowered.api.block.BlockType)22 Task (org.spongepowered.api.scheduler.Task)17 IOException (java.io.IOException)16 Optional (java.util.Optional)16 Living (org.spongepowered.api.entity.living.Living)15 ItemType (org.spongepowered.api.item.ItemType)15 UUID (java.util.UUID)14 Monster (org.spongepowered.api.entity.living.monster.Monster)14 ItemStackSnapshot (org.spongepowered.api.item.inventory.ItemStackSnapshot)14 Map (java.util.Map)13