# Filter

With zAuctionHouseV3 you can create your own filter for the `/ah search` command. First you need to read the Filter page which gives you all the information about how filters work.

## Step 1

First you will need to retrieve the FilterManager class.

```java
@Override
public void onEnable() {
	FilterManager filterManagerManager = getProvider(FilterManager.class);
}

private <T> T getProvider(Class<T> classz) {
	RegisteredServiceProvider<T> provider = getServer().getServicesManager().getRegistration(classz);
	if (provider == null) 
		return null;
	return provider.getProvider() != null ? (T) provider.getProvider() : null;
}
```

## Step 2

You need to create a class that will extend the `Filter` class.

```java
package fr.maxlego08.zauctionhouse.filter.filters;

import org.bukkit.ChatColor;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import fr.maxlego08.zauctionhouse.api.AuctionItem;
import fr.maxlego08.zauctionhouse.api.enums.FilterType;
import fr.maxlego08.zauctionhouse.api.filter.Filter;

public class NameFilter extends Filter {

	public NameFilter() {
		# Name of the filter that will be used in the command
		super("name");
	}

	@Override
	public boolean perform(AuctionItem auctionItem, FilterType filterType, String string) {
	
		# We retrieve the list of items present in the auctionItem object.	
		for (ItemStack itemStack : this.getItems(auctionItem)) {

			ItemMeta itemMeta = itemStack.getItemMeta();
			if (!itemMeta.hasDisplayName())
				continue;

			String name = ChatColor.stripColor(itemMeta.getDisplayName());

			# We make a switch on the type of filter
			switch (filterType) {
			case CONTAINS:
				return name.toLowerCase().contains(string.toLowerCase());
			case EQUALS:
				return name.equals(string);
			case EQUALSIGNORECASE:
				return name.equalsIgnoreCase(string);
			default:
				break;
			}
		}
		return false;
	}

}
```

## Step 3

All you have to do is save the filter.

```java
this.filterManager.registerFilter(new NameFilter());
```


---

# Agent Instructions: 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://zauctionhouse.groupez.dev/development-portal/filter-impl.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.
