Search in sources :

Example 96 with BlockSnapshot

use of org.spongepowered.api.block.BlockSnapshot in project RedProtect by FabioZumbi12.

the class RPBlockListener method onPistonEvent.

// TODO Test events
/*
    @Listener
    public void onListenEvent(TargetLivingEvent event) {    	
    	RedProtect.get().logger.severe("Event: "+ event.toString());
    }
    
    */
/*
	@Listener
	public void onVehicleBreak(DamageEntityEvent e){
		if (e.isCancelled()){
    		return;
    	}
		if (!(e.getAttacker() instanceof Player)){
			return;
		}
		Vehicle cart = e.getVehicle();
		Player p = (Player) e.getAttacker();
		Region r = RedProtect.get().rm.getTopRegion(cart.getLocation());
		if (r == null){
			return;
		}
		
		if (!r.canMinecart(p)){
			RPLang.sendMessage(p, "blocklistener.region.cantbreak");
			e.setCancelled(true);
			return;
		}
	}
	*/
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPistonEvent(ChangeBlockEvent.Pre e) {
    Location<World> piston = null;
    Location<World> block = null;
    boolean antih = RedProtect.get().cfgs.getBool("region-settings.anti-hopper");
    if (RedProtect.get().getPVHelper().checkCause(e.getCause(), "PISTON_EXTEND")) {
        if (RedProtect.get().cfgs.getBool("performance.disable-PistonEvent-handler")) {
            return;
        }
        List<Location<World>> locs = e.getLocations();
        for (Location<World> loc : locs) {
            if (piston == null) {
                piston = loc;
                continue;
            }
            block = loc;
        }
    }
    if (RedProtect.get().getPVHelper().checkCause(e.getCause(), "PISTON_RETRACT")) {
        if (RedProtect.get().cfgs.getBool("performance.disable-PistonEvent-handler")) {
            return;
        }
        List<Location<World>> locs = e.getLocations();
        for (Location<World> loc : locs) {
            if (piston == null) {
                piston = loc;
                continue;
            }
            block = loc;
        }
    }
    // process
    if (piston != null && block != null) {
        Region rPi = RedProtect.get().rm.getTopRegion(piston);
        Region rB = RedProtect.get().rm.getTopRegion(block);
        if (rPi == null && rB != null || (rPi != null && rB != null && rPi != rB && !rPi.sameLeaders(rB))) {
            e.setCancelled(true);
            return;
        }
        if (antih) {
            BlockSnapshot ib = block.add(0, 1, 0).createSnapshot();
            if (!cont.canWorldBreak(ib) || !cont.canWorldBreak(block.createSnapshot())) {
                e.setCancelled(true);
            }
        }
    }
}
Also used : BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) World(org.spongepowered.api.world.World) Location(org.spongepowered.api.world.Location) Listener(org.spongepowered.api.event.Listener)

Example 97 with BlockSnapshot

use of org.spongepowered.api.block.BlockSnapshot in project RedProtect by FabioZumbi12.

the class RPBlockListener method onFlow.

/*
    @Listener
    public void onBlockBurn(NotifyNeighborBlockEvent e, @First BlockSnapshot source){
    	
    	RedProtect.get().logger.debug("Is ChangeBlockEvent.Modify event");
    	Map<Direction, BlockState> dirs = e.getNeighbors();
    	    	
    	for (Direction dir:dirs.keySet()){
    		BlockSnapshot b = source.getLocation().get().getRelative(dir).createSnapshot();
    		BlockState bstate = source.getState();
        	Region r = RedProtect.get().rm.getTopRegion(b.getLocation().get());        	
        	
        	if ((bstate.getType().equals(BlockTypes.FIRE) || bstate.getType().getName().contains("LAVA")) && r != null && !r.canFire()){
    			e.setCancelled(true);
    			return;
    		}
        	
        	if (!cont.canWorldBreak(b)){
        		e.setCancelled(true);
        		return;
        	}
    	}
    	return;
    }
    */
@Listener(order = Order.FIRST, beforeModifications = true)
public void onFlow(ChangeBlockEvent.Place e, @First BlockSnapshot source) {
    BlockSnapshot bto = e.getTransactions().get(0).getOriginal();
    RedProtect.get().logger.debug("blocks", "Is BlockFromToEvent.Place event is to " + source.getState().getType().getName() + " from " + bto.getState().getType().getName());
    Region rto = RedProtect.get().rm.getTopRegion(bto.getLocation().get());
    if (rto != null && (source.getState().getType().equals(BlockTypes.WATER) || source.getState().getType().equals(BlockTypes.LAVA) || source.getState().getType().equals(BlockTypes.FLOWING_LAVA) || source.getState().getType().equals(BlockTypes.FLOWING_WATER))) {
        if (!rto.canFlow()) {
            e.setCancelled(true);
            return;
        }
        String bfType = bto.getState().getType().getName();
        if (!rto.FlowDamage() && !bto.getState().getType().equals(BlockTypes.AIR) && !bfType.contains("water") && !bfType.contains("lava")) {
            e.setCancelled(true);
            return;
        }
    }
    for (Direction dir : Arrays.asList(Direction.EAST, Direction.NORTH, Direction.SOUTH, Direction.WEST)) {
        Location<World> locFrom = bto.getLocation().get().getBlockRelative(dir);
        Region rfrom = RedProtect.get().rm.getTopRegion(locFrom);
        if (rfrom != null && !rfrom.canFlow()) {
            e.setCancelled(true);
            return;
        }
        if (rfrom != null && rto != null && rfrom != rto && !rfrom.sameLeaders(rto)) {
            e.setCancelled(true);
            return;
        }
        if (rfrom == null && rto != null) {
            e.setCancelled(true);
            return;
        }
    }
}
Also used : BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) World(org.spongepowered.api.world.World) Direction(org.spongepowered.api.util.Direction) Listener(org.spongepowered.api.event.Listener)

Example 98 with BlockSnapshot

use of org.spongepowered.api.block.BlockSnapshot in project RedProtect by FabioZumbi12.

the class RPGlobalListener method onBlockBreakGlobal.

@Listener(order = Order.FIRST, beforeModifications = true)
public void onBlockBreakGlobal(ChangeBlockEvent.Break e, @Root Player p) {
    RedProtect.get().logger.debug("default", "RPGlobalListener - Is BlockBreakEvent event! Cancelled? " + e.isCancelled());
    BlockSnapshot bt = e.getTransactions().get(0).getOriginal();
    BlockState b = bt.getState();
    World w = bt.getLocation().get().getExtent();
    Region r = RedProtect.get().rm.getTopRegion(bt.getLocation().get());
    if (r != null) {
        return;
    }
    if (!RPUtil.canBuildNear(p, bt.getLocation().get())) {
        e.setCancelled(true);
        return;
    }
    if (!bypassBuild(p, bt, 2)) {
        e.setCancelled(true);
    }
}
Also used : BlockState(org.spongepowered.api.block.BlockState) 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 99 with BlockSnapshot

use of org.spongepowered.api.block.BlockSnapshot in project RedProtect by FabioZumbi12.

the class RPGlobalListener method onDecay.

@Listener(order = Order.FIRST, beforeModifications = true)
public void onDecay(ChangeBlockEvent.Decay e, @Root BlockSnapshot source) {
    BlockSnapshot bfrom = e.getTransactions().get(0).getOriginal();
    boolean allowDecay = RedProtect.get().cfgs.getGlobalFlag(bfrom.getLocation().get().getExtent().getName(), "allow-changes-of", "leaves-decay");
    if (!allowDecay) {
        e.setCancelled(true);
    }
}
Also used : BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Listener(org.spongepowered.api.event.Listener)

Example 100 with BlockSnapshot

use of org.spongepowered.api.block.BlockSnapshot in project RedProtect by FabioZumbi12.

the class RPGlobalListener method onFlow.

@Listener(order = Order.FIRST, beforeModifications = true)
public void onFlow(ChangeBlockEvent.Place e, @Root BlockSnapshot source) {
    BlockSnapshot bfrom = e.getTransactions().get(0).getOriginal();
    boolean flow = RedProtect.get().cfgs.getGlobalFlag(bfrom.getLocation().get().getExtent().getName(), "liquid-flow");
    boolean allowWater = RedProtect.get().cfgs.getGlobalFlag(bfrom.getLocation().get().getExtent().getName(), "allow-changes-of", "water-flow");
    boolean allowLava = RedProtect.get().cfgs.getGlobalFlag(bfrom.getLocation().get().getExtent().getName(), "allow-changes-of", "lava-flow");
    boolean allowdamage = RedProtect.get().cfgs.getGlobalFlag(bfrom.getLocation().get().getExtent().getName(), "allow-changes-of", "flow-damage");
    Region r = RedProtect.get().rm.getTopRegion(bfrom.getLocation().get());
    if (r != null) {
        return;
    }
    RedProtect.get().logger.debug("blocks", "Is BlockFromToEvent.Place event is to " + source.getState().getType().getName() + " from " + bfrom.getState().getType().getName());
    if (!flow && (source.getState().getType().equals(BlockTypes.WATER) || source.getState().getType().equals(BlockTypes.LAVA) || source.getState().getType().equals(BlockTypes.FLOWING_LAVA) || source.getState().getType().equals(BlockTypes.FLOWING_WATER))) {
        e.setCancelled(true);
        return;
    }
    if (!allowWater && (source.getState().getType().equals(BlockTypes.WATER) || source.getState().getType().equals(BlockTypes.FLOWING_WATER))) {
        e.setCancelled(true);
        return;
    }
    if (!allowLava && (source.getState().getType().equals(BlockTypes.LAVA) || source.getState().getType().equals(BlockTypes.FLOWING_LAVA))) {
        e.setCancelled(true);
        return;
    }
    if (!allowdamage && !source.getState().getType().equals(bfrom.getState().getType()) && !bfrom.getState().getType().equals(BlockTypes.AIR)) {
        e.setCancelled(true);
    }
}
Also used : BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) Listener(org.spongepowered.api.event.Listener)

Aggregations

BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)150 World (org.spongepowered.api.world.World)67 Listener (org.spongepowered.api.event.Listener)66 Location (org.spongepowered.api.world.Location)26 BlockState (org.spongepowered.api.block.BlockState)22 Entity (org.spongepowered.api.entity.Entity)21 BlockPos (net.minecraft.util.math.BlockPos)20 CauseStackManager (org.spongepowered.api.event.CauseStackManager)19 Region (br.net.fabiozumbi12.RedProtect.Sponge.Region)18 IBlockState (net.minecraft.block.state.IBlockState)18 Transaction (org.spongepowered.api.data.Transaction)18 BlockType (org.spongepowered.api.block.BlockType)15 Player (org.spongepowered.api.entity.living.player.Player)15 Direction (org.spongepowered.api.util.Direction)15 ChangeBlockEvent (org.spongepowered.api.event.block.ChangeBlockEvent)14 SpongeBlockSnapshot (org.spongepowered.common.block.SpongeBlockSnapshot)14 Vector3d (com.flowpowered.math.vector.Vector3d)13 ArrayList (java.util.ArrayList)13 User (org.spongepowered.api.entity.living.player.User)11 ItemStack (org.spongepowered.api.item.inventory.ItemStack)11