> For the complete documentation index, see [llms.txt](https://thisistails.gitbook.io/tailslib/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://thisistails.gitbook.io/tailslib/custom-blocks/block-manager.md).

# Block manager

## About manager

Custom block manager is similar to custom items manager so for more info read [Item manager](/tailslib/custom-items/item-manager.md#about-manager)

## Access the manager

```java
Managers.getCustomBlockManager();
// or
CustomBlockManager.getManager();
```

## Get registered custom block

```java
CustomBlockManager manager = CustomBlockManager.getManager();

manager.customBlock("ID").ifPresent(block -> {
    // CODE
});
// OR
CustomBlock block = manager.customBlock("ID").orElse(null);
```

## Get all registered blocks

```java
CustomBlockManager manager = CustomBlockManager.getManager();
List<CustomBlock> blocks = manager.registeredCustomBlocks();
```

## Register a block

```java
CustomBlockManager manager = CustomBlockManager.getManager();
manager.register(new MyBlock());
```

## Removing a custom block at position

```java
CustomBlockManager manager = CustomBlockManager.getManager();
manager.removeAt(Block or Location);
// or | and
manager.removeAt(Block or Location, force?);
```

In the second method we see argument "force". Force means that this block will be deleted without notification AKA `destroyRequest` event will not fire for this instance of block.

## Get a block at location

```java
CustomBlockManager manager = CustomBlockManager.getManager();
manager.placedAt(Location).ifPresent((runtime) -> {
    // code
});
// OR
CustomBlockRuntime runtime = manager.placedAt(Location).orElse(null);
```

## Get all blocks

```java
CustomBlockManager manager = CustomBlockManager.getManager();
List<CustomBlockRuntime> blocks = manager.allBlocksPlaced();
```

### All block placed by someone

{% hint style="info" %}
This operation is may be slow since this method need to search through all blocks.
{% endhint %}

```java
CustomBlockManager manager = CustomBlockManager.getManager();
List<CustomBlockRuntime> blocks = manager.allBlocksPlaced(Player.getUniqueId());
```

### All block placed in area

{% hint style="info" %}
This operation may be slow since this method need to search through all blocks.
{% endhint %}

```java
CustomBlockManager manager = CustomBlockManager.getManager();
List<CustomBlockRuntime> blocks = manager.allBlockPlaced(Location 1, Location 2);
```

## Place a block

```java
CustomBlockManager manager = CustomBlockManager.getManager();
PlaceBlockOptions options = PlaceBlockOptions.builder()
    .block(CustomBlock) // REQUIRED
    .location(Location) // REQUIRED
    .owner(UUID) // Optional
    .replace(Boolean) // Optional
    .build();
manager.placeBlock(options).ifPresent((runtime) -> {
    // code
});
// OR
CustomBlockRuntime placedBlock = manager.placeBlock(options).orElse(null);
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://thisistails.gitbook.io/tailslib/custom-blocks/block-manager.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
