Search in sources :

Example 41 with BlockSnapshot

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

the class RPEconomy method getRegionValue.

public static long getRegionValue(Region r) {
    long regionCost = 0;
    World w = RedProtect.get().serv.getWorld(r.getWorld()).get();
    int maxX = r.getMaxMbrX();
    int minX = r.getMinMbrX();
    int maxZ = r.getMaxMbrZ();
    int minZ = r.getMinMbrZ();
    for (int x = minX; x < maxX; x++) {
        for (int y = 0; y < 256; y++) {
            for (int z = minZ; z < maxZ; z++) {
                BlockSnapshot b = w.createSnapshot(x, y, z);
                /*
		      Location<World> loc = new Location<World>(w, x, y, z);		      
		      Collection<Entity> ents = w.getEntities(ent-> ent.getLocation().getBlockPosition().equals(loc.getBlockPosition()));
		      for (Entity ent:ents){
		    	  if (ent instanceof Equipable){
		    		  Equipable equip = (Equipable) ent;
		    		  regionCost += getInvValue(equip.getInventory().slots());
		    	  }
		      }
		      */
                if (b.getState().getType().equals(BlockTypes.AIR)) {
                    continue;
                }
                if (b.getLocation().get().getTileEntity().isPresent()) {
                    TileEntity invTile = b.getLocation().get().getTileEntity().get();
                    if (invTile instanceof TileEntityInventory) {
                        TileEntityInventory<?> inv = (TileEntityInventory<?>) invTile;
                        regionCost += getInvValue(inv.slots());
                    }
                } else {
                    regionCost += RedProtect.get().cfgs.getBlockCost(b.getState().getType().getName());
                }
            }
        }
    }
    r.setValue(regionCost);
    return regionCost;
}
Also used : TileEntity(org.spongepowered.api.block.tileentity.TileEntity) TileEntityInventory(org.spongepowered.api.item.inventory.type.TileEntityInventory) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) World(org.spongepowered.api.world.World)

Example 42 with BlockSnapshot

use of org.spongepowered.api.block.BlockSnapshot 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 43 with BlockSnapshot

use of org.spongepowered.api.block.BlockSnapshot 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 44 with BlockSnapshot

use of org.spongepowered.api.block.BlockSnapshot 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)

Example 45 with BlockSnapshot

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

the class RPBlockListener method onInteractPrimBlock.

@Listener(order = Order.FIRST, beforeModifications = true)
public void onInteractPrimBlock(InteractBlockEvent.Primary event, @First Player p) {
    BlockSnapshot b = event.getTargetBlock();
    RedProtect.get().logger.debug("player", "RPBlockListener - Is InteractBlockEvent.Primary event");
    if (!RedProtect.get().ph.hasPerm(p, "redprotect.bypass")) {
        if (b.getState().getType().getName().contains("sign") && !cont.canBreak(p, b)) {
            RPLang.sendMessage(p, "blocklistener.container.breakinside");
            event.setCancelled(true);
        }
    }
}
Also used : BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Listener(org.spongepowered.api.event.Listener)

Aggregations

BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)144 World (org.spongepowered.api.world.World)64 Listener (org.spongepowered.api.event.Listener)61 Location (org.spongepowered.api.world.Location)27 BlockState (org.spongepowered.api.block.BlockState)21 BlockPos (net.minecraft.util.math.BlockPos)20 Entity (org.spongepowered.api.entity.Entity)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)17 BlockType (org.spongepowered.api.block.BlockType)15 Direction (org.spongepowered.api.util.Direction)15 SpongeBlockSnapshot (org.spongepowered.common.block.SpongeBlockSnapshot)14 Vector3d (com.flowpowered.math.vector.Vector3d)13 ArrayList (java.util.ArrayList)13 ChangeBlockEvent (org.spongepowered.api.event.block.ChangeBlockEvent)13 Player (org.spongepowered.api.entity.living.player.Player)12 User (org.spongepowered.api.entity.living.player.User)11 LocatableBlock (org.spongepowered.api.world.LocatableBlock)11