add list gui filter

This commit is contained in:
alexcrea 2026-06-27 08:26:54 +02:00
parent 4c3b3b09ad
commit a79e341ea8
Signed by: alexcrea
GPG key ID: E59DF23EE2A2266C
10 changed files with 35 additions and 24 deletions

View file

@ -5,7 +5,6 @@ import com.github.stefvanschie.inventoryframework.pane.util.Pattern;
import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryClickEvent;
import xyz.alexcrea.cuanvil.enchant.CAEnchantment; import xyz.alexcrea.cuanvil.enchant.CAEnchantment;
import xyz.alexcrea.cuanvil.enchant.CAEnchantmentRegistry; import xyz.alexcrea.cuanvil.enchant.CAEnchantmentRegistry;
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
import xyz.alexcrea.cuanvil.gui.config.list.SettingGuiListConfigGui; import xyz.alexcrea.cuanvil.gui.config.list.SettingGuiListConfigGui;
import xyz.alexcrea.cuanvil.gui.config.settings.SettingGui; import xyz.alexcrea.cuanvil.gui.config.settings.SettingGui;
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant; import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
@ -37,7 +36,7 @@ public abstract class AbstractEnchantConfigGui<T extends SettingGui.SettingGuiFa
} }
@Override @Override
protected Collection<CAEnchantment> getEveryDisplayableInstanceOfGeneric() { protected Collection<CAEnchantment> getEveryInstanceOfGeneric() {
return CAEnchantmentRegistry.getInstance().getNameSortedEnchantments(); return CAEnchantmentRegistry.getInstance().getNameSortedEnchantments();
} }
@ -73,7 +72,7 @@ public abstract class AbstractEnchantConfigGui<T extends SettingGui.SettingGuiFa
this.pages.clear(); this.pages.clear();
this.pages.add(this.firstPage); this.pages.add(this.firstPage);
for (CAEnchantment enchantment : getEveryDisplayableInstanceOfGeneric()) { for (CAEnchantment enchantment : getDisplayableInstanceOfGeneric()) {
GuiItem item = this.guiItemMap.get(enchantment); GuiItem item = this.guiItemMap.get(enchantment);
if(item == null) { if(item == null) {

View file

@ -113,7 +113,7 @@ public class CustomRecipeConfigGui extends MappedGuiListConfigGui<AnvilCustomRec
@Override @Override
protected Collection<AnvilCustomRecipe> getEveryDisplayableInstanceOfGeneric() { protected Collection<AnvilCustomRecipe> getEveryInstanceOfGeneric() {
return ConfigHolder.CUSTOM_RECIPE_HOLDER.getRecipeManager().getRecipeList(); return ConfigHolder.CUSTOM_RECIPE_HOLDER.getRecipeManager().getRecipeList();
} }
} }

View file

@ -97,7 +97,7 @@ public class EnchantConflictGui extends MappedGuiListConfigGui<EnchantConflictGr
} }
@Override @Override
protected Collection<EnchantConflictGroup> getEveryDisplayableInstanceOfGeneric() { protected Collection<EnchantConflictGroup> getEveryInstanceOfGeneric() {
return ConfigHolder.CONFLICT_HOLDER.getConflictManager().getConflictList(); return ConfigHolder.CONFLICT_HOLDER.getConflictManager().getConflictList();
} }

View file

@ -62,7 +62,7 @@ public class GroupConfigGui extends MappedGuiListConfigGui<IncludeGroup, MappedG
} }
@Override @Override
protected Collection<IncludeGroup> getEveryDisplayableInstanceOfGeneric() { protected Collection<IncludeGroup> getEveryInstanceOfGeneric() {
ArrayList<IncludeGroup> includeGroups = new ArrayList<>(); ArrayList<IncludeGroup> includeGroups = new ArrayList<>();
for (AbstractMaterialGroup group : ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager().getGroupMap().values()) { for (AbstractMaterialGroup group : ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager().getGroupMap().values()) {

View file

@ -77,7 +77,7 @@ public class UnitRepairConfigGui extends
} }
@Override @Override
protected Collection<Material> getEveryDisplayableInstanceOfGeneric() { protected Collection<Material> getEveryInstanceOfGeneric() {
ArrayList<Material> materials = new ArrayList<>(); ArrayList<Material> materials = new ArrayList<>();
for (String matName : ConfigHolder.UNIT_REPAIR_HOLDER.getConfig().getKeys(false)) { for (String matName : ConfigHolder.UNIT_REPAIR_HOLDER.getConfig().getKeys(false)) {

View file

@ -23,18 +23,21 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.UUID; import java.util.UUID;
import java.util.function.Predicate;
public abstract class ElementListConfigGui< T > extends ChestGui implements ValueUpdatableGui { public abstract class ElementListConfigGui<T> extends ChestGui implements ValueUpdatableGui {
private final String namePrefix;
protected PatternPane backgroundPane;
public static final int LIST_FILLER_START_X = 1; public static final int LIST_FILLER_START_X = 1;
public static final int LIST_FILLER_START_Y = 1; public static final int LIST_FILLER_START_Y = 1;
public static final int LIST_FILLER_LENGTH = 7; public static final int LIST_FILLER_LENGTH = 7;
public static final int LIST_FILLER_HEIGHT = 4; public static final int LIST_FILLER_HEIGHT = 4;
private final String namePrefix;
protected PatternPane backgroundPane;
private Predicate<T> filter = (t) -> true;
protected ElementListConfigGui(@NotNull String title, Gui parent) { protected ElementListConfigGui(@NotNull String title, Gui parent) {
super(6, title, CustomAnvil.instance); super(6, title, CustomAnvil.instance);
this.namePrefix = title; this.namePrefix = title;
@ -46,7 +49,11 @@ public abstract class ElementListConfigGui< T > extends ChestGui implements Valu
} }
protected Pattern getBackgroundPattern(){ public void setFilter(Predicate<T> filter) {
this.filter = filter;
}
protected Pattern getBackgroundPattern() {
return new Pattern( return new Pattern(
GuiSharedConstant.UPPER_FILLER_FULL_PLANE, GuiSharedConstant.UPPER_FILLER_FULL_PLANE,
GuiSharedConstant.EMPTY_FILLER_FULL_LINE, GuiSharedConstant.EMPTY_FILLER_FULL_LINE,
@ -81,7 +88,7 @@ public abstract class ElementListConfigGui< T > extends ChestGui implements Valu
protected GuiItem goLeftItem; protected GuiItem goLeftItem;
protected GuiItem goRightItem; protected GuiItem goRightItem;
protected void prepareStaticValues(){ protected void prepareStaticValues() {
// Left item creation for consumer & bind // Left item creation for consumer & bind
this.goLeftItem = new GuiItem(new ItemStack(Material.RED_STAINED_GLASS_PANE), event -> { this.goLeftItem = new GuiItem(new ItemStack(Material.RED_STAINED_GLASS_PANE), event -> {
HumanEntity viewer = event.getWhoClicked(); HumanEntity viewer = event.getWhoClicked();
@ -113,16 +120,17 @@ public abstract class ElementListConfigGui< T > extends ChestGui implements Valu
}, CustomAnvil.instance); }, CustomAnvil.instance);
GuiItem createNew = prepareCreateNewItem(); GuiItem createNew = prepareCreateNewItem();
if(createNew != null){ if (createNew != null) {
this.backgroundPane.bindItem('C', createNew); this.backgroundPane.bindItem('C', createNew);
} }
} }
protected void reloadValues(){
protected void reloadValues() {
this.firstPage.clear(); this.firstPage.clear();
this.pages.clear(); this.pages.clear();
this.pages.add(this.firstPage); this.pages.add(this.firstPage);
for (T generic : getEveryDisplayableInstanceOfGeneric()) { for (T generic : getDisplayableInstanceOfGeneric()) {
updateValueForGeneric(generic, false); updateValueForGeneric(generic, false);
} }
@ -247,7 +255,7 @@ public abstract class ElementListConfigGui< T > extends ChestGui implements Valu
// set title // set title
StringBuilder title = new StringBuilder(this.namePrefix); StringBuilder title = new StringBuilder(this.namePrefix);
int pagesSize = this.pages.size(); int pagesSize = this.pages.size();
if(pagesSize > 1){ if (pagesSize > 1) {
title.append(" (").append(pageID + 1).append('/').append(pagesSize).append(')'); title.append(" (").append(pageID + 1).append('/').append(pagesSize).append(')');
} }
setTitle(title.toString()); setTitle(title.toString());
@ -288,7 +296,7 @@ public abstract class ElementListConfigGui< T > extends ChestGui implements Valu
public void removeGeneric(T generic) { public void removeGeneric(T generic) {
GuiItem item = findGuiItemForRemoval(generic); GuiItem item = findGuiItemForRemoval(generic);
if(item == null) return; if (item == null) return;
removeFromPage(item); removeFromPage(item);
update(); update();
@ -300,7 +308,11 @@ public abstract class ElementListConfigGui< T > extends ChestGui implements Valu
protected abstract void updateGeneric(T generic, ItemStack usedItem); protected abstract void updateGeneric(T generic, ItemStack usedItem);
protected abstract Collection<T> getEveryDisplayableInstanceOfGeneric(); protected abstract Collection<T> getEveryInstanceOfGeneric();
protected Collection<T> getDisplayableInstanceOfGeneric() {
return getEveryInstanceOfGeneric().stream().filter(filter).toList();
}
@Override @Override
public void updateGuiValues() { public void updateGuiValues() {

View file

@ -80,7 +80,7 @@ public abstract class MappedGuiListConfigGui< T, S extends MappedGuiListConfigGu
// Try to find if it already exists in a for loop // Try to find if it already exists in a for loop
// Not the most efficient on large number of conflict, but it should not run often. // Not the most efficient on large number of conflict, but it should not run often.
for (T generic : getEveryDisplayableInstanceOfGeneric()) { for (T generic : getDisplayableInstanceOfGeneric()) {
if (generic.toString().equalsIgnoreCase(message)) { if (generic.toString().equalsIgnoreCase(message)) {
player.sendMessage("§cPlease enter a "+genericDisplayedName()+" name that do not already exist..."); player.sendMessage("§cPlease enter a "+genericDisplayedName()+" name that do not already exist...");
// wait next message. // wait next message.

View file

@ -134,7 +134,7 @@ public class UnitRepairElementListGui extends SettingGuiListConfigGui<String, Do
} }
@Override @Override
protected Collection<String> getEveryDisplayableInstanceOfGeneric() { protected Collection<String> getEveryInstanceOfGeneric() {
ArrayList<String> keys = new ArrayList<>(); ArrayList<String> keys = new ArrayList<>();
if(!this.shouldWork){ if(!this.shouldWork){
return keys; return keys;

View file

@ -63,7 +63,7 @@ public class EnchantSelectSettingGui extends SettingGuiListConfigGui<CAEnchantme
} }
@Override @Override
protected Collection<CAEnchantment> getEveryDisplayableInstanceOfGeneric() { protected Collection<CAEnchantment> getEveryInstanceOfGeneric() {
Stream<CAEnchantment> toDisplayStream; Stream<CAEnchantment> toDisplayStream;
if(this.displayUnselected){ if(this.displayUnselected){
toDisplayStream = CAEnchantmentRegistry.getInstance().getNameSortedEnchantments().stream(); toDisplayStream = CAEnchantmentRegistry.getInstance().getNameSortedEnchantments().stream();

View file

@ -217,7 +217,7 @@ public class MaterialSelectSettingGui extends MappedElementListConfigGui<Namespa
} }
@Override @Override
protected Collection<NamespacedKey> getEveryDisplayableInstanceOfGeneric() { protected Collection<NamespacedKey> getEveryInstanceOfGeneric() {
return this.defaultMaterials; return this.defaultMaterials;
} }