Search in sources :

Example 46 with BlockSnapshot

use of org.spongepowered.api.block.BlockSnapshot in project AdamantineShield by Karanum.

the class PlayerInspectListener method onBlockSecondaryInteract.

@Listener
public void onBlockSecondaryInteract(InteractBlockEvent.Secondary.MainHand e, @First Player p) {
    if (!plugin.getInspectManager().isInspector(p))
        return;
    e.setCancelled(true);
    BlockSnapshot block = e.getTargetBlock();
    if (!block.getLocation().isPresent())
        return;
    Location<World> loc = block.getLocation().get();
    p.sendMessage(Text.of(TextColors.BLUE, "Querying database, please wait..."));
    Runnable task = null;
    if (loc.getTileEntity().isPresent()) {
        if (loc.getTileEntity().get() instanceof MultiBlockCarrier) {
            task = () -> {
                MultiBlockCarrier carrier = (MultiBlockCarrier) loc.getTileEntity().get();
                plugin.getInspectManager().inspectContainer(p, block.getWorldUniqueId(), carrier.getLocation().getBlockPosition());
            };
        } else if (loc.getTileEntity().get() instanceof TileEntityCarrier) {
            task = () -> plugin.getInspectManager().inspectContainer(p, block.getWorldUniqueId(), loc.getBlockPosition());
        }
    } else {
        task = () -> plugin.getInspectManager().inspect(p, block.getWorldUniqueId(), loc.getBlockPosition().add(e.getTargetSide().asBlockOffset()));
    }
    if (task != null)
        plugin.getThreadPool().execute(task);
}
Also used : BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) TileEntityCarrier(org.spongepowered.api.block.tileentity.carrier.TileEntityCarrier) World(org.spongepowered.api.world.World) MultiBlockCarrier(org.spongepowered.api.item.inventory.MultiBlockCarrier) Listener(org.spongepowered.api.event.Listener)

Example 47 with BlockSnapshot

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

the class BlockReport method report.

protected void report(ChangeBlockEvent event) {
    UUID multi = UUID.randomUUID();
    for (Map.Entry<Vector3i, List<Transaction<BlockSnapshot>>> entry : event.getTransactions().stream().collect(Collectors.groupingBy(t -> t.getOriginal().getPosition())).entrySet()) {
        // Only get one transaction for one block
        Transaction<BlockSnapshot> trans = entry.getValue().get(0);
        if (!isActive(trans.getOriginal().getLocation().get().getExtent())) {
            continue;
        }
        if (isRedstoneChange(trans.getOriginal().getState(), trans.getFinal().getState())) {
            continue;
        }
        Action action = observe(event);
        action.addData(BLOCK_CHANGES, Observe.transactions(trans));
        action.addData(LOCATION, Observe.location(trans.getOriginal().getLocation().get()));
        if (event.getTransactions().size() > 1) {
            action.addData(MULTIACTION, multi.toString());
        }
        report(action);
    }
}
Also used : Action(org.cubeengine.module.vigil.report.Action) Vector3i(com.flowpowered.math.vector.Vector3i) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) List(java.util.List) UUID(java.util.UUID) Map(java.util.Map)

Example 48 with BlockSnapshot

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

the class BreakBlockReport 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);
    if (!orig.isPresent()) {
        throw new IllegalStateException();
    }
    showReport(actions, receiver, action, orig.get());
}
Also used : Action(org.cubeengine.module.vigil.report.Action) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Recall(org.cubeengine.module.vigil.report.Recall)

Example 49 with BlockSnapshot

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

the class ExplosionReport method showReport.

@Override
public void showReport(List<Action> actions, Receiver receiver) {
    // TODO test
    Action action = actions.get(0);
    BlockSnapshot snap = action.getCached(BLOCKS_ORIG, Recall::origSnapshot).get();
    receiver.sendReport(this, actions, actions.size(), "{txt} made boom {txt}", "{txt} made boom {txt} x{}", Recall.cause(action), name(snap, receiver), actions.size());
}
Also used : Action(org.cubeengine.module.vigil.report.Action) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot)

Example 50 with BlockSnapshot

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

the class ModifyBlockReport 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);
    Text cause = Recall.cause(action);
    if (!repl.isPresent() || !orig.isPresent()) {
        throw new IllegalStateException();
    }
    Optional<MutableBoundedValue<Integer>> growth = repl.get().getValue(Keys.GROWTH_STAGE);
    if (growth.isPresent()) {
        if (growth.get().get().equals(growth.get().getMaxValue())) {
            receiver.sendReport(this, actions, actions.size(), "{txt} let {txt} grow to maturity", "{txt} let {txt} grow to maturity x{}", cause, name(orig.get(), receiver), actions.size());
            return;
        }
        receiver.sendReport(this, actions, actions.size(), "{txt} let {txt} grow", "{txt} let {txt} grow x{}", cause, name(orig.get(), receiver), actions.size());
        return;
    }
    // TODO other modifyables
    receiver.sendReport(this, actions, actions.size(), "{txt} modified {txt}", "{txt} modified {txt} x{}", cause, name(orig.get(), receiver), actions.size());
}
Also used : Action(org.cubeengine.module.vigil.report.Action) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) MutableBoundedValue(org.spongepowered.api.data.value.mutable.MutableBoundedValue) Recall(org.cubeengine.module.vigil.report.Recall) Text(org.spongepowered.api.text.Text)

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