Search in sources :

Example 1 with MultiBlockCarrier

use of org.spongepowered.api.item.inventory.MultiBlockCarrier 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)

Aggregations

BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)1 TileEntityCarrier (org.spongepowered.api.block.tileentity.carrier.TileEntityCarrier)1 Listener (org.spongepowered.api.event.Listener)1 MultiBlockCarrier (org.spongepowered.api.item.inventory.MultiBlockCarrier)1 World (org.spongepowered.api.world.World)1