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.
@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.
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.
this.filterManager.registerFilter(new NameFilter());
Copy link
On this page
Step 1
Step 2
Step 3