mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-08-28 08:25:56 +02:00
add list gui filter
This commit is contained in:
parent
4c3b3b09ad
commit
a79e341ea8
10 changed files with 35 additions and 24 deletions
|
|
@ -5,7 +5,6 @@ import com.github.stefvanschie.inventoryframework.pane.util.Pattern;
|
|||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantment;
|
||||
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.settings.SettingGui;
|
||||
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
|
||||
|
|
@ -37,7 +36,7 @@ public abstract class AbstractEnchantConfigGui<T extends SettingGui.SettingGuiFa
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Collection<CAEnchantment> getEveryDisplayableInstanceOfGeneric() {
|
||||
protected Collection<CAEnchantment> getEveryInstanceOfGeneric() {
|
||||
return CAEnchantmentRegistry.getInstance().getNameSortedEnchantments();
|
||||
}
|
||||
|
||||
|
|
@ -73,7 +72,7 @@ public abstract class AbstractEnchantConfigGui<T extends SettingGui.SettingGuiFa
|
|||
this.pages.clear();
|
||||
this.pages.add(this.firstPage);
|
||||
|
||||
for (CAEnchantment enchantment : getEveryDisplayableInstanceOfGeneric()) {
|
||||
for (CAEnchantment enchantment : getDisplayableInstanceOfGeneric()) {
|
||||
GuiItem item = this.guiItemMap.get(enchantment);
|
||||
|
||||
if(item == null) {
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ public class CustomRecipeConfigGui extends MappedGuiListConfigGui<AnvilCustomRec
|
|||
|
||||
|
||||
@Override
|
||||
protected Collection<AnvilCustomRecipe> getEveryDisplayableInstanceOfGeneric() {
|
||||
protected Collection<AnvilCustomRecipe> getEveryInstanceOfGeneric() {
|
||||
return ConfigHolder.CUSTOM_RECIPE_HOLDER.getRecipeManager().getRecipeList();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ public class EnchantConflictGui extends MappedGuiListConfigGui<EnchantConflictGr
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Collection<EnchantConflictGroup> getEveryDisplayableInstanceOfGeneric() {
|
||||
protected Collection<EnchantConflictGroup> getEveryInstanceOfGeneric() {
|
||||
return ConfigHolder.CONFLICT_HOLDER.getConflictManager().getConflictList();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ public class GroupConfigGui extends MappedGuiListConfigGui<IncludeGroup, MappedG
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Collection<IncludeGroup> getEveryDisplayableInstanceOfGeneric() {
|
||||
protected Collection<IncludeGroup> getEveryInstanceOfGeneric() {
|
||||
ArrayList<IncludeGroup> includeGroups = new ArrayList<>();
|
||||
|
||||
for (AbstractMaterialGroup group : ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager().getGroupMap().values()) {
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ public class UnitRepairConfigGui extends
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Collection<Material> getEveryDisplayableInstanceOfGeneric() {
|
||||
protected Collection<Material> getEveryInstanceOfGeneric() {
|
||||
ArrayList<Material> materials = new ArrayList<>();
|
||||
|
||||
for (String matName : ConfigHolder.UNIT_REPAIR_HOLDER.getConfig().getKeys(false)) {
|
||||
|
|
|
|||
|
|
@ -23,18 +23,21 @@ import java.util.ArrayList;
|
|||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public abstract class ElementListConfigGui< T > extends ChestGui implements ValueUpdatableGui {
|
||||
|
||||
private final String namePrefix;
|
||||
|
||||
protected PatternPane backgroundPane;
|
||||
public abstract class ElementListConfigGui<T> extends ChestGui implements ValueUpdatableGui {
|
||||
|
||||
public static final int LIST_FILLER_START_X = 1;
|
||||
public static final int LIST_FILLER_START_Y = 1;
|
||||
public static final int LIST_FILLER_LENGTH = 7;
|
||||
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) {
|
||||
super(6, title, CustomAnvil.instance);
|
||||
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(
|
||||
GuiSharedConstant.UPPER_FILLER_FULL_PLANE,
|
||||
GuiSharedConstant.EMPTY_FILLER_FULL_LINE,
|
||||
|
|
@ -81,7 +88,7 @@ public abstract class ElementListConfigGui< T > extends ChestGui implements Valu
|
|||
protected GuiItem goLeftItem;
|
||||
protected GuiItem goRightItem;
|
||||
|
||||
protected void prepareStaticValues(){
|
||||
protected void prepareStaticValues() {
|
||||
// Left item creation for consumer & bind
|
||||
this.goLeftItem = new GuiItem(new ItemStack(Material.RED_STAINED_GLASS_PANE), event -> {
|
||||
HumanEntity viewer = event.getWhoClicked();
|
||||
|
|
@ -113,16 +120,17 @@ public abstract class ElementListConfigGui< T > extends ChestGui implements Valu
|
|||
}, CustomAnvil.instance);
|
||||
|
||||
GuiItem createNew = prepareCreateNewItem();
|
||||
if(createNew != null){
|
||||
if (createNew != null) {
|
||||
this.backgroundPane.bindItem('C', createNew);
|
||||
}
|
||||
}
|
||||
protected void reloadValues(){
|
||||
|
||||
protected void reloadValues() {
|
||||
this.firstPage.clear();
|
||||
this.pages.clear();
|
||||
this.pages.add(this.firstPage);
|
||||
|
||||
for (T generic : getEveryDisplayableInstanceOfGeneric()) {
|
||||
for (T generic : getDisplayableInstanceOfGeneric()) {
|
||||
updateValueForGeneric(generic, false);
|
||||
}
|
||||
|
||||
|
|
@ -247,7 +255,7 @@ public abstract class ElementListConfigGui< T > extends ChestGui implements Valu
|
|||
// set title
|
||||
StringBuilder title = new StringBuilder(this.namePrefix);
|
||||
int pagesSize = this.pages.size();
|
||||
if(pagesSize > 1){
|
||||
if (pagesSize > 1) {
|
||||
title.append(" (").append(pageID + 1).append('/').append(pagesSize).append(')');
|
||||
}
|
||||
setTitle(title.toString());
|
||||
|
|
@ -288,7 +296,7 @@ public abstract class ElementListConfigGui< T > extends ChestGui implements Valu
|
|||
|
||||
public void removeGeneric(T generic) {
|
||||
GuiItem item = findGuiItemForRemoval(generic);
|
||||
if(item == null) return;
|
||||
if (item == null) return;
|
||||
removeFromPage(item);
|
||||
|
||||
update();
|
||||
|
|
@ -300,7 +308,11 @@ public abstract class ElementListConfigGui< T > extends ChestGui implements Valu
|
|||
|
||||
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
|
||||
public void updateGuiValues() {
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ public abstract class MappedGuiListConfigGui< T, S extends MappedGuiListConfigGu
|
|||
|
||||
// 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.
|
||||
for (T generic : getEveryDisplayableInstanceOfGeneric()) {
|
||||
for (T generic : getDisplayableInstanceOfGeneric()) {
|
||||
if (generic.toString().equalsIgnoreCase(message)) {
|
||||
player.sendMessage("§cPlease enter a "+genericDisplayedName()+" name that do not already exist...");
|
||||
// wait next message.
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@ public class UnitRepairElementListGui extends SettingGuiListConfigGui<String, Do
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Collection<String> getEveryDisplayableInstanceOfGeneric() {
|
||||
protected Collection<String> getEveryInstanceOfGeneric() {
|
||||
ArrayList<String> keys = new ArrayList<>();
|
||||
if(!this.shouldWork){
|
||||
return keys;
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ public class EnchantSelectSettingGui extends SettingGuiListConfigGui<CAEnchantme
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Collection<CAEnchantment> getEveryDisplayableInstanceOfGeneric() {
|
||||
protected Collection<CAEnchantment> getEveryInstanceOfGeneric() {
|
||||
Stream<CAEnchantment> toDisplayStream;
|
||||
if(this.displayUnselected){
|
||||
toDisplayStream = CAEnchantmentRegistry.getInstance().getNameSortedEnchantments().stream();
|
||||
|
|
|
|||
|
|
@ -217,7 +217,7 @@ public class MaterialSelectSettingGui extends MappedElementListConfigGui<Namespa
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Collection<NamespacedKey> getEveryDisplayableInstanceOfGeneric() {
|
||||
protected Collection<NamespacedKey> getEveryInstanceOfGeneric() {
|
||||
return this.defaultMaterials;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue