add list gui filter

This commit is contained in:
alexcrea 2026-06-27 08:26:54 +02:00
parent 82099277da
commit f1b89e9c93
Signed by: alexcrea
GPG key ID: E346CD16413450E3
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,6 +49,10 @@ public abstract class ElementListConfigGui< T > extends ChestGui implements Valu
} }
public void setFilter(Predicate<T> filter) {
this.filter = filter;
}
protected Pattern getBackgroundPattern() { protected Pattern getBackgroundPattern() {
return new Pattern( return new Pattern(
GuiSharedConstant.UPPER_FILLER_FULL_PLANE, GuiSharedConstant.UPPER_FILLER_FULL_PLANE,
@ -117,12 +124,13 @@ public abstract class ElementListConfigGui< T > extends ChestGui implements Valu
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);
} }
@ -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;
} }