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.
1
@Override
2
public void onEnable() {
3
FilterManager filterManagerManager = getProvider(FilterManager.class);
4
}
5
​
6
private <T> T getProvider(Class<T> classz) {
7
RegisteredServiceProvider<T> provider = getServer().getServicesManager().getRegistration(classz);
8
if (provider == null)
9
return null;
10
return provider.getProvider() != null ? (T) provider.getProvider() : null;
11
}
Copied!

Step 2

You need to create a class that will extend the Filter class.
1
package fr.maxlego08.zauctionhouse.filter.filters;
2
​
3
import org.bukkit.ChatColor;
4
import org.bukkit.inventory.ItemStack;
5
import org.bukkit.inventory.meta.ItemMeta;
6
​
7
import fr.maxlego08.zauctionhouse.api.AuctionItem;
8
import fr.maxlego08.zauctionhouse.api.enums.FilterType;
9
import fr.maxlego08.zauctionhouse.api.filter.Filter;
10
​
11
public class NameFilter extends Filter {
12
​
13
public NameFilter() {
14
# Name of the filter that will be used in the command
15
super("name");
16
}
17
​
18
@Override
19
public boolean perform(AuctionItem auctionItem, FilterType filterType, String string) {
20
21
# We retrieve the list of items present in the auctionItem object.
22
for (ItemStack itemStack : this.getItems(auctionItem)) {
23
​
24
ItemMeta itemMeta = itemStack.getItemMeta();
25
if (!itemMeta.hasDisplayName())
26
continue;
27
​
28
String name = ChatColor.stripColor(itemMeta.getDisplayName());
29
​
30
# We make a switch on the type of filter
31
switch (filterType) {
32
case CONTAINS:
33
return name.toLowerCase().contains(string.toLowerCase());
34
case EQUALS:
35
return name.equals(string);
36
case EQUALSIGNORECASE:
37
return name.equalsIgnoreCase(string);
38
default:
39
break;
40
}
41
}
42
return false;
43
}
44
​
45
}
Copied!

Step 3

All you have to do is save the filter.
1
this.filterManager.registerFilter(new NameFilter());
Copied!
Last modified 8mo ago
Copy link