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
3b708302bc
commit
2147384823
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 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) {
|
||||||
|
|
|
||||||
|
|
@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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()) {
|
||||||
|
|
|
||||||
|
|
@ -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)) {
|
||||||
|
|
|
||||||
|
|
@ -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() {
|
||||||
|
|
|
||||||
|
|
@ -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.
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
|
|
@ -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();
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue