Search in sources :

Example 51 with BlockSnapshot

use of org.spongepowered.api.block.BlockSnapshot in project modules-extra by CubeEngine.

the class PlaceBlockReport method showReport.

@Override
public void showReport(List<Action> actions, Receiver receiver) {
    Action action = actions.get(0);
    Optional<BlockSnapshot> orig = action.getCached(BLOCKS_ORIG, Recall::origSnapshot);
    Optional<BlockSnapshot> repl = action.getCached(BLOCKS_REPL, Recall::replSnapshot);
    if (!repl.isPresent()) {
        throw new IllegalStateException();
    }
    showReport(actions, receiver, action, orig, repl.get());
}
Also used : Action(org.cubeengine.module.vigil.report.Action) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Recall(org.cubeengine.module.vigil.report.Recall)

Example 52 with BlockSnapshot

use of org.spongepowered.api.block.BlockSnapshot in project modules-extra by CubeEngine.

the class Observe method cause.

public static Map<String, Object> cause(Object cause, boolean doRecursion) {
    if (cause instanceof EntityDamageSource) {
        Entity source = ((EntityDamageSource) cause).getSource();
        Map<String, Object> sourceCause = Observe.cause(source);
        Map<String, Object> indirectCause = null;
        if (cause instanceof IndirectEntityDamageSource) {
            indirectCause = Observe.cause(((IndirectEntityDamageSource) cause).getIndirectSource());
            if (sourceCause == null) {
                return indirectCause;
            }
        }
        // TODO indirectCause
        return sourceCause;
    } else if (cause instanceof BlockDamageSource) {
        return Observe.cause(((BlockDamageSource) cause).getBlockSnapshot());
    } else if (cause instanceof DamageSource) {
        return Observe.damageCause(((DamageSource) cause));
    }
    if (cause instanceof Player) {
        return playerCause(((Player) cause));
    } else if (cause instanceof BlockSnapshot) {
        return blockCause(((BlockSnapshot) cause));
    } else if (cause instanceof PrimedTNT) {
        return tntCause(((PrimedTNT) cause));
    } else if (cause instanceof Entity) {
        return entityCause(((Entity) cause), doRecursion);
    }
    // TODO other causes that interest us
    return null;
}
Also used : PrimedTNT(org.spongepowered.api.entity.explosive.PrimedTNT) Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.living.player.Player) EntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource) DamageSource(org.spongepowered.api.event.cause.entity.damage.source.DamageSource) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource) BlockDamageSource(org.spongepowered.api.event.cause.entity.damage.source.BlockDamageSource) BlockDamageSource(org.spongepowered.api.event.cause.entity.damage.source.BlockDamageSource) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource) EntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource)

Example 53 with BlockSnapshot

use of org.spongepowered.api.block.BlockSnapshot in project modules-extra by CubeEngine.

the class ItemDuctListener method onBreak.

@Listener
public void onBreak(ChangeBlockEvent.Break event) {
    for (Transaction<BlockSnapshot> trans : event.getTransactions()) {
        if (!trans.getOriginal().getLocation().isPresent()) {
            continue;
        }
        BlockType type = trans.getOriginal().getState().getType();
        Location<World> loc = trans.getOriginal().getLocation().get();
        if (isEndPointType(type)) {
            Direction dir = trans.getOriginal().get(Keys.DIRECTION).orElse(Direction.NONE);
            Optional<DuctData> data = loc.getRelative(dir).get(DuctData.class);
            if (data.isPresent()) {
                data.get().remove(dir.getOpposite());
                if (data.get().getFilters().isEmpty()) {
                    loc.getRelative(dir).remove(DuctData.class);
                } else {
                    loc.getRelative(dir).offer(data.get());
                }
            }
        }
    }
}
Also used : BlockType(org.spongepowered.api.block.BlockType) IDuctData(org.cubeengine.module.itemduct.data.IDuctData) DuctData(org.cubeengine.module.itemduct.data.DuctData) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) World(org.spongepowered.api.world.World) Direction(org.spongepowered.api.util.Direction) Listener(org.spongepowered.api.event.Listener)

Example 54 with BlockSnapshot

use of org.spongepowered.api.block.BlockSnapshot in project modules-extra by CubeEngine.

the class MarketSignListener method onBlockBreak.

@Listener
public void onBlockBreak(ChangeBlockEvent.Break event, @First Player player) {
    for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
        BlockSnapshot orig = transaction.getOriginal();
        BlockType type = orig.getState().getType();
        if (type == STANDING_SIGN || type == WALL_SIGN) {
            Optional<ImmutableMarketSignData> signData = orig.get(ImmutableMarketSignData.class);
            if (signData.isPresent()) {
                if (signData.get().getSignType() != null) {
                    event.setCancelled(true);
                    return;
                }
            }
        }
        Location<World> origLoc = orig.getLocation().get();
        for (Direction blockFace : BlockUtil.BLOCK_FACES) {
            if (blockFace == DOWN) {
                continue;
            }
            Location<World> relative = origLoc.getRelative(blockFace);
            if (!relative.get(MarketSignData.class).isPresent()) {
                continue;
            }
            if (blockFace == UP) {
                if (relative.getBlockType() == STANDING_SIGN) {
                    event.setCancelled(true);
                    return;
                }
            } else {
                if (relative.getBlockType() == WALL_SIGN && relative.get(Keys.DIRECTION).get() == blockFace) {
                    event.setCancelled(true);
                    return;
                }
            }
        }
    }
}
Also used : ImmutableMarketSignData(org.cubeengine.module.signmarket.data.ImmutableMarketSignData) BlockType(org.spongepowered.api.block.BlockType) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) World(org.spongepowered.api.world.World) Direction(org.spongepowered.api.util.Direction) Listener(org.spongepowered.api.event.Listener)

Example 55 with BlockSnapshot

use of org.spongepowered.api.block.BlockSnapshot in project modules-extra by CubeEngine.

the class MarketSignListener method onSignPlace.

@Listener(order = Order.POST)
public void onSignPlace(ChangeBlockEvent.Place event, @First Player player) {
    if (event.getTransactions().size() > 1 || !module.getEditModeCommand().hasUser(player)) {
        return;
    }
    for (Transaction<BlockSnapshot> trans : event.getTransactions()) {
        BlockType type = trans.getFinal().getState().getType();
        if (// placed sign
        type == BlockTypes.STANDING_SIGN || type == BlockTypes.WALL_SIGN) {
            if (!player.hasPermission(module.perms().EDIT_USE.getId())) {
                event.setCancelled(true);
                i18n.send(player, NEGATIVE, "You are not allowed to create market signs!");
                return;
            }
            MarketSignData data = new MarketSignData();
            data.setID(UUID.randomUUID());
            data.setOwner(player.getUniqueId());
            Location<World> loc = trans.getFinal().getLocation().get();
            loc.offer(data);
            manager.setSign(loc, player);
            Sponge.getCauseStackManager().pushCause(player);
            player.closeInventory();
        }
    }
}
Also used : BlockType(org.spongepowered.api.block.BlockType) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) MarketSignData(org.cubeengine.module.signmarket.data.MarketSignData) ImmutableMarketSignData(org.cubeengine.module.signmarket.data.ImmutableMarketSignData) World(org.spongepowered.api.world.World) 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