📖
zAuctionHouse
DiscordGroupeZServeur Minecraft Vote
  • â„šī¸Informations
    • 🍾Getting started
    • 🔌Installing zAuctionHouse
    • ❓Why i need zMenu ?
  • Configurations
    • 🏤Official Configurations
    • Multi servers
    • 🚉Statistics
    • 📔Commands and Permissions
    • đŸĒ§PlaceHolders
    • âšī¸Buttons
    • 💲Economy
    • 🎊Convert
    • 🔍Search / Filter
    • Messages
    • 💱Prices
    • 👨‍đŸ’ŧWhitelist
    • 🛑Blacklist
    • 🚖Tax
    • Categories
    • 🇨đŸ‡ĩItem Translation
  • đŸ—ƒī¸Plugins files
    • Config.yml
    • 💲Economies.yml
    • Inventories
    • Patterns
    • Blacklist.yml
    • Prices.yml
    • Taxs.yml
    • Whitelist.yml
  • Development Portal
    • â„šī¸Informations
    • 🌆Events
    • đŸŦCustom storage
    • Filter
    • 🛑Blacklist
    • 💸Custom economy
  • 👴Old Configurations
    • Items
    • Buttons
    • Placeholder buttons
Powered by GitBook
On this page
  • Step 1
  • Step 2
  • Step 3

Was this helpful?

  1. Development Portal

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());
PreviousCustom storageNextBlacklist

Last updated 6 months ago

Was this helpful?