mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
Progress on config GUI:
- Finished GroupConfigSubSettingGui. - Progress on MaterialSelectSettingGui
This commit is contained in:
parent
257a3b4696
commit
8523044613
15 changed files with 359 additions and 38 deletions
|
|
@ -6,7 +6,6 @@ import com.github.stefvanschie.inventoryframework.pane.PatternPane;
|
|||
import com.github.stefvanschie.inventoryframework.pane.util.Pattern;
|
||||
import io.delilaheve.CustomAnvil;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import xyz.alexcrea.cuanvil.gui.config.global.*;
|
||||
|
|
@ -87,7 +86,7 @@ public class MainConfigGui extends ChestGui {
|
|||
ItemStack groupItemstack = new ItemStack(Material.CHEST);
|
||||
|
||||
ItemMeta groupMeta = groupItemstack.getItemMeta();
|
||||
groupMeta.setDisplayName("\u00A7aMaterial Groups");
|
||||
groupMeta.setDisplayName("\u00A7aGroups");
|
||||
groupMeta.setLore(Collections.singletonList("\u00A77Click here to open material group menu"));
|
||||
groupItemstack.setItemMeta(groupMeta);
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ public interface SelectGroupContainer {
|
|||
groupLore.add("\u00A77Allow you to select a list of \u00A73Groups \u00A77that this " + containerType + " should " + groupAction);
|
||||
Set<AbstractMaterialGroup> grouos = container.getSelectedGroups();
|
||||
if (grouos.isEmpty()) {
|
||||
groupLore.add("\u00A77There is no "+groupAction+"d groups for this "+containerType+".");
|
||||
groupLore.add("\u00A77There is no "+groupAction+"d group for this "+containerType+".");
|
||||
} else {
|
||||
groupLore.add("\u00A77List of "+groupAction+"d groups for this "+containerType+":");
|
||||
Iterator<AbstractMaterialGroup> groupIterator = grouos.iterator();
|
||||
|
|
|
|||
|
|
@ -1,8 +1,11 @@
|
|||
package xyz.alexcrea.cuanvil.gui.config;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import xyz.alexcrea.cuanvil.group.AbstractMaterialGroup;
|
||||
import xyz.alexcrea.cuanvil.gui.config.list.elements.GroupConfigSubSettingGui;
|
||||
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.*;
|
||||
|
||||
public interface SelectMaterialContainer {
|
||||
|
||||
|
|
@ -12,4 +15,30 @@ public interface SelectMaterialContainer {
|
|||
|
||||
EnumSet<Material> illegalMaterials();
|
||||
|
||||
static List<String> getMaterialLore(SelectMaterialContainer container, String containerType, String action){
|
||||
// Prepare material lore
|
||||
ArrayList<String> groupLore = new ArrayList<>();
|
||||
groupLore.add("\u00A77Allow you to select a list of \u00A7ematerials \u00A77that this " + containerType + " should " + action);
|
||||
Set<Material> materialSet = container.getSelectedMaterials();
|
||||
if (materialSet.isEmpty()) {
|
||||
groupLore.add("\u00A77There is no "+action+"d material for this "+containerType+".");
|
||||
} else {
|
||||
groupLore.add("\u00A77List of "+action+"d materials for this "+containerType+":");
|
||||
Iterator<Material> materialIterator = materialSet.iterator();
|
||||
|
||||
boolean greaterThanMax = materialSet.size() > 5;
|
||||
int maxindex = (greaterThanMax ? 4 : materialSet.size());
|
||||
for (int i = 0; i < maxindex; i++) {
|
||||
// format string like "- Stone Sword"
|
||||
String formattedName = CasedStringUtil.snakeToUpperSpacedCase(materialIterator.next().name().toLowerCase());
|
||||
groupLore.add("\u00A77- \u00A7e" + formattedName);
|
||||
|
||||
}
|
||||
if (greaterThanMax) {
|
||||
groupLore.add("\u00A77And " + (materialSet.size() - 4) + " more...");
|
||||
}
|
||||
}
|
||||
return groupLore;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
|
|||
import java.util.Arrays;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class SelectItemTypeGui extends AbstractAskGui {
|
||||
|
||||
|
|
|
|||
|
|
@ -34,7 +34,14 @@ public abstract class ElementListConfigGui< T > extends ValueUpdatableGui {
|
|||
this.namePrefix = title;
|
||||
|
||||
// Back item panel
|
||||
Pattern pattern = new Pattern(
|
||||
Pattern pattern = getBackgroundPattern();
|
||||
this.backgroundPane = new PatternPane(0, 0, 9, 6, Pane.Priority.LOW, pattern);
|
||||
GuiGlobalItems.addBackItem(this.backgroundPane, MainConfigGui.INSTANCE);
|
||||
|
||||
}
|
||||
|
||||
protected Pattern getBackgroundPattern(){
|
||||
return new Pattern(
|
||||
GuiSharedConstant.EMPTY_GUI_FULL_LINE,
|
||||
GuiSharedConstant.EMPTY_GUI_FULL_LINE,
|
||||
GuiSharedConstant.EMPTY_GUI_FULL_LINE,
|
||||
|
|
@ -42,12 +49,8 @@ public abstract class ElementListConfigGui< T > extends ValueUpdatableGui {
|
|||
GuiSharedConstant.EMPTY_GUI_FULL_LINE,
|
||||
"B11L1R11C"
|
||||
);
|
||||
this.backgroundPane = new PatternPane(0, 0, 9, 6, Pane.Priority.LOW, pattern);
|
||||
GuiGlobalItems.addBackItem(this.backgroundPane, MainConfigGui.INSTANCE);
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected OutlinePane firstPage;
|
||||
protected ArrayList<OutlinePane> pages;
|
||||
protected HashMap<UUID, Integer> pageMap;
|
||||
|
|
@ -103,7 +106,10 @@ public abstract class ElementListConfigGui< T > extends ValueUpdatableGui {
|
|||
viewer.setItemOnCursor(cursor);
|
||||
}, CustomAnvil.instance);
|
||||
|
||||
this.backgroundPane.bindItem('C', prepareCreateNewItem());
|
||||
GuiItem createNew = prepareCreateNewItem();
|
||||
if(createNew != null){
|
||||
this.backgroundPane.bindItem('C', createNew);
|
||||
}
|
||||
}
|
||||
protected void reloadValues(){
|
||||
this.firstPage.clear();
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
|||
import io.delilaheve.CustomAnvil;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.alexcrea.cuanvil.gui.config.list.elements.ElementMappedToListGui;
|
||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
|
||||
|
||||
import java.util.Locale;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,181 @@
|
|||
package xyz.alexcrea.cuanvil.gui.config.list;
|
||||
|
||||
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
|
||||
import com.github.stefvanschie.inventoryframework.pane.util.Pattern;
|
||||
import io.delilaheve.CustomAnvil;
|
||||
import io.delilaheve.util.ConfigOptions;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.alexcrea.cuanvil.gui.config.SelectMaterialContainer;
|
||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
|
||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
||||
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class MaterialSelectSettingGui extends MappedElementListConfigGui<Material, GuiItem> {
|
||||
|
||||
private final SelectMaterialContainer selector;
|
||||
private final List<Material> defaultMaterials;
|
||||
private final int defaultMaterialHash;
|
||||
private int nowMaterialHash;
|
||||
|
||||
public MaterialSelectSettingGui(
|
||||
@NotNull SelectMaterialContainer selector,
|
||||
@NotNull String title,
|
||||
@NotNull Gui backGui) {
|
||||
super(title);
|
||||
this.selector = selector;
|
||||
this.defaultMaterials = new ArrayList<>(this.selector.getSelectedMaterials());
|
||||
|
||||
this.defaultMaterialHash = hashFromMaterialList(this.defaultMaterials);
|
||||
this.nowMaterialHash = this.defaultMaterialHash;
|
||||
|
||||
init();
|
||||
|
||||
// Change back item
|
||||
this.backgroundPane.bindItem('B', GuiGlobalItems.backItem(backGui));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Pattern getBackgroundPattern(){
|
||||
return new Pattern(
|
||||
GuiSharedConstant.EMPTY_GUI_FULL_LINE,
|
||||
GuiSharedConstant.EMPTY_GUI_FULL_LINE,
|
||||
GuiSharedConstant.EMPTY_GUI_FULL_LINE,
|
||||
GuiSharedConstant.EMPTY_GUI_FULL_LINE,
|
||||
GuiSharedConstant.EMPTY_GUI_FULL_LINE,
|
||||
"BT1LAR11S"
|
||||
);
|
||||
}
|
||||
|
||||
private GuiItem saveItem;
|
||||
private GuiItem noChangeItem;
|
||||
|
||||
@Override
|
||||
protected void prepareStaticValues() {
|
||||
super.prepareStaticValues();
|
||||
|
||||
// Temporary leave item
|
||||
GuiItem temporaryLeave = GuiGlobalItems.temporaryCloseGuiToSelectItem(Material.YELLOW_TERRACOTTA, this);
|
||||
this.backgroundPane.bindItem('T', temporaryLeave);
|
||||
|
||||
// Select new mat item
|
||||
ItemStack selectItem = new ItemStack(Material.LIME_STAINED_GLASS_PANE);
|
||||
ItemMeta selectMeta = selectItem.getItemMeta();
|
||||
|
||||
selectMeta.setDisplayName("aaaaaaa");
|
||||
|
||||
selectItem.setItemMeta(selectMeta);
|
||||
|
||||
this.backgroundPane.bindItem('A', new GuiItem(selectItem, setItemAsCursor(), CustomAnvil.instance));
|
||||
|
||||
// Save item
|
||||
this.saveItem = GuiGlobalItems.noChangeItem();
|
||||
|
||||
this.noChangeItem = GuiGlobalItems.noChangeItem();
|
||||
this.backgroundPane.bindItem('S', this.noChangeItem);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A consumer to update the current setting's value.
|
||||
*/
|
||||
protected Consumer<InventoryClickEvent> setItemAsCursor() {
|
||||
return event -> {
|
||||
event.setCancelled(true);
|
||||
|
||||
HumanEntity player = event.getWhoClicked();
|
||||
ItemStack cursor = player.getItemOnCursor();
|
||||
|
||||
if(cursor.getType().isAir()) return;
|
||||
|
||||
Material cursorMat = cursor.getType();
|
||||
if(!this.elementGuiMap.containsKey(cursorMat)){
|
||||
updateValueForGeneric(cursorMat, true);
|
||||
this.nowMaterialHash ^= cursorMat.hashCode();
|
||||
|
||||
testCanSave();
|
||||
}
|
||||
|
||||
update();
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemStack createItemForGeneric(Material material) {
|
||||
return new ItemStack(material); //this is temp TODO the function
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Material> getEveryDisplayableInstanceOfGeneric() {
|
||||
return this.defaultMaterials;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateElement(Material generic, GuiItem element) {
|
||||
if(ConfigOptions.INSTANCE.getDebugLog()){
|
||||
CustomAnvil.instance.getLogger().log(Level.INFO,
|
||||
"Call that should not happen happened...",
|
||||
new IllegalStateException());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GuiItem newElementRequested(Material generic, GuiItem newItem) {
|
||||
newItem.setAction(GuiGlobalActions.stayInPlace); //TODO ask to remove the item on click (or instant remove)
|
||||
return newItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GuiItem findItemFromElement(Material generic, GuiItem element) {
|
||||
return element;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GuiItem findGuiItemForRemoval(Material generic, GuiItem element) {
|
||||
return element;
|
||||
}
|
||||
|
||||
private static int hashFromMaterialList(List<Material> materialList){
|
||||
int defaultMaterialHash = 0;
|
||||
for (Material material : materialList) {
|
||||
defaultMaterialHash ^= material.hashCode();
|
||||
}
|
||||
return defaultMaterialHash;
|
||||
}
|
||||
|
||||
private void testCanSave() {
|
||||
if(this.defaultMaterialHash == this.nowMaterialHash){
|
||||
this.backgroundPane.bindItem('S', this.noChangeItem);
|
||||
}else{
|
||||
this.backgroundPane.bindItem('S', this.saveItem);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Unused functions.
|
||||
@Override
|
||||
protected GuiItem prepareCreateNewItem() {// Not used
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
protected Consumer<String> prepareCreateItemConsumer(HumanEntity player) {// Not used
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String genericDisplayedName() {// Not Used
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -12,6 +12,7 @@ import org.jetbrains.annotations.NotNull;
|
|||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||
import xyz.alexcrea.cuanvil.gui.config.ask.SelectItemTypeGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.global.UnitRepairConfigGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.list.elements.ElementMappedToListGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.settings.DoubleSettingGui;
|
||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
||||
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package xyz.alexcrea.cuanvil.gui.config.list;
|
||||
package xyz.alexcrea.cuanvil.gui.config.list.elements;
|
||||
|
||||
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
|
||||
|
|
@ -14,8 +14,10 @@ import org.jetbrains.annotations.NotNull;
|
|||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||
import xyz.alexcrea.cuanvil.group.*;
|
||||
import xyz.alexcrea.cuanvil.gui.config.SelectGroupContainer;
|
||||
import xyz.alexcrea.cuanvil.gui.config.SelectMaterialContainer;
|
||||
import xyz.alexcrea.cuanvil.gui.config.ask.ConfirmActionGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.global.GroupConfigGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.list.MaterialSelectSettingGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.settings.GroupSelectSettingGui;
|
||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
|
||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
||||
|
|
@ -26,7 +28,7 @@ import java.util.*;
|
|||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implements SelectGroupContainer {
|
||||
public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implements SelectGroupContainer, SelectMaterialContainer {
|
||||
|
||||
private final GroupConfigGui parent;
|
||||
private final IncludeGroup group;
|
||||
|
|
@ -36,7 +38,8 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
|
|||
@NotNull GroupConfigGui parent,
|
||||
@NotNull IncludeGroup group,
|
||||
@NotNull GuiItem item) {
|
||||
super(item, 3, group.getName());
|
||||
super(item, 3,
|
||||
CasedStringUtil.snakeToUpperSpacedCase(group.getName()) + " Config");
|
||||
this.parent = parent;
|
||||
this.group = group;
|
||||
|
||||
|
|
@ -71,12 +74,17 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
|
|||
this.materialSelection = new GuiItem(new ItemStack(Material.DIAMOND_SWORD), (event) -> {
|
||||
event.setCancelled(true);
|
||||
|
||||
MaterialSelectSettingGui selectGui = new MaterialSelectSettingGui(this,
|
||||
CasedStringUtil.snakeToUpperSpacedCase(group.getName()) + " Materials"
|
||||
, this);
|
||||
selectGui.show(event.getWhoClicked());
|
||||
|
||||
}, CustomAnvil.instance);
|
||||
|
||||
this.groupSelection = new GuiItem(new ItemStack(Material.CHEST), (event) -> {
|
||||
event.setCancelled(true);
|
||||
GroupSelectSettingGui enchantGui = new GroupSelectSettingGui(
|
||||
"\u00A7e" + CasedStringUtil.snakeToUpperSpacedCase(this.group.toString()) + " \u00A7rGroups",
|
||||
CasedStringUtil.snakeToUpperSpacedCase(this.group.getName()) + " Groups",
|
||||
this, this, 0);
|
||||
enchantGui.show(event.getWhoClicked());
|
||||
}, CustomAnvil.instance);
|
||||
|
|
@ -193,15 +201,18 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
|
|||
|
||||
@Override
|
||||
public void updateLocal() {
|
||||
// Prepare material lore
|
||||
List<String> matLore = SelectMaterialContainer.getMaterialLore(this, "group", "include");
|
||||
|
||||
// Prepare group lore
|
||||
List<String> groupLore = SelectGroupContainer.getGroupLore(this, "group", "include");
|
||||
|
||||
// Configure enchant setting item
|
||||
// Configure included material setting item
|
||||
ItemStack matSelectItem = this.materialSelection.getItem();
|
||||
ItemMeta matSelectMeta = matSelectItem.getItemMeta();
|
||||
|
||||
matSelectMeta.setDisplayName("\u00A7aSelect included \u00A7eMaterials \u00A7aSettings");
|
||||
matSelectMeta.setLore(Collections.emptyList()); // temporary
|
||||
matSelectMeta.setLore(matLore);
|
||||
matSelectMeta.addItemFlags(ItemFlag.values());
|
||||
|
||||
matSelectItem.setItemMeta(matSelectMeta);
|
||||
|
|
@ -226,7 +237,7 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
|
|||
}
|
||||
|
||||
// ----------------------------
|
||||
// SelectGroupContainer methods
|
||||
// SelectGroupContainer related methods
|
||||
// ----------------------------
|
||||
|
||||
@Override
|
||||
|
|
@ -259,22 +270,12 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
|
|||
groupNames[index++] = otherGroup.getName();
|
||||
}
|
||||
|
||||
ConfigHolder.ITEM_GROUP_HOLDER.getConfig().set(this.group.getName()+"."+ItemGroupManager.GROUP_LIST_PATH, groupNames);
|
||||
ConfigHolder.ITEM_GROUP_HOLDER.getConfig().set(group.getName()+"."+ItemGroupManager.GROUP_LIST_PATH, groupNames);
|
||||
|
||||
// Try to update referencing group. kind of expensive operation in some case.
|
||||
for (AbstractMaterialGroup otherGroup : ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager().getGroupMap().values()) {
|
||||
if(otherGroup.getGroups().contains(group)){
|
||||
Set<AbstractMaterialGroup> groupClone = new HashSet<>(otherGroup.getGroups());
|
||||
updateGroup(otherGroup, groupClone);
|
||||
}
|
||||
}
|
||||
updateDirectReferencingGroups(group);
|
||||
|
||||
// Update parent & local by extension
|
||||
if(group instanceof IncludeGroup){
|
||||
this.parent.updateValueForGeneric((IncludeGroup) group, true);
|
||||
}
|
||||
|
||||
// We assume a backup & save call we be done soon after
|
||||
// We assume a backup & save call will be done soon after
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -290,4 +291,94 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
|
|||
|
||||
return illegal;
|
||||
}
|
||||
|
||||
// ----------------------------
|
||||
// End of SelectGroupContainer related methods
|
||||
// SelectGroupContainer related methods
|
||||
// ----------------------------
|
||||
|
||||
@Override
|
||||
public EnumSet<Material> getSelectedMaterials() {
|
||||
return this.group.getNonGroupInheritedMaterials();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setSelectedMaterials(EnumSet<Material> materials) {
|
||||
this.group.setNonGroupInheritedMaterials(materials);
|
||||
|
||||
// Write to file configuration
|
||||
String[] groupNames = new String[materials.size()];
|
||||
int index = 0;
|
||||
for (Material otherGroup : materials) {
|
||||
groupNames[index++] = otherGroup.name().toLowerCase();
|
||||
}
|
||||
|
||||
ConfigHolder.ITEM_GROUP_HOLDER.getConfig().set(this.group.getName()+"."+ItemGroupManager.MATERIAL_LIST_PATH, groupNames);
|
||||
|
||||
// update referencing groups
|
||||
updateDirectReferencingGroups(this.group);
|
||||
|
||||
// Save file configuration to disk
|
||||
if (GuiSharedConstant.TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE) {
|
||||
return ConfigHolder.CONFLICT_HOLDER.saveToDisk(GuiSharedConstant.TEMPORARY_DO_BACKUP_EVERY_SAVE);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumSet<Material> illegalMaterials() {
|
||||
return EnumSet.noneOf(Material.class);
|
||||
}
|
||||
|
||||
// ----------------------------
|
||||
// End of SelectGroupContainer related methods
|
||||
// ----------------------------
|
||||
|
||||
private void updateDirectReferencingGroups(AbstractMaterialGroup referenceTo){
|
||||
Collection<AbstractMaterialGroup> everyStoredGroups = ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager().getGroupMap().values();
|
||||
List<EnchantConflictGroup> everyConflicts = ConfigHolder.CONFLICT_HOLDER.getConflictManager().getConflictList();
|
||||
|
||||
HashSet<AbstractMaterialGroup> toUpdate = new HashSet<>();
|
||||
HashSet<AbstractMaterialGroup> updateFuture = new HashSet<>();
|
||||
HashSet<AbstractMaterialGroup> conflictGroupPlanned = new HashSet<>();
|
||||
|
||||
updateFuture.add(referenceTo);
|
||||
while (!updateFuture.isEmpty()){
|
||||
HashSet<AbstractMaterialGroup> temp = updateFuture;
|
||||
updateFuture = toUpdate;
|
||||
updateFuture.clear();
|
||||
toUpdate = temp;
|
||||
|
||||
for (AbstractMaterialGroup testGroup : toUpdate) {
|
||||
// Update other stored group
|
||||
for (AbstractMaterialGroup otherGroup : everyStoredGroups) {
|
||||
if(otherGroup.getGroups().contains(testGroup)){
|
||||
otherGroup.updateMaterials();
|
||||
toUpdate.add(otherGroup);
|
||||
}
|
||||
}
|
||||
|
||||
// plan update for conflict groups
|
||||
for (EnchantConflictGroup everyConflict : everyConflicts) {
|
||||
AbstractMaterialGroup conflictGroup = everyConflict.getCantConflictGroup();
|
||||
if(conflictGroup.getGroups().contains(testGroup)){
|
||||
conflictGroupPlanned.add(conflictGroup);
|
||||
}
|
||||
}
|
||||
|
||||
// Update parent & local by extension
|
||||
if(testGroup instanceof IncludeGroup){
|
||||
this.parent.updateValueForGeneric((IncludeGroup) testGroup, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.parent.update();
|
||||
|
||||
// Update conflict group
|
||||
for (AbstractMaterialGroup conflictGroup : conflictGroupPlanned) {
|
||||
conflictGroup.updateMaterials();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
|
|||
import io.delilaheve.CustomAnvil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.list.ElementMappedToListGui;
|
||||
|
||||
public abstract class MappedToListSubSettingGui extends ValueUpdatableGui implements ElementMappedToListGui {
|
||||
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ public class ItemSettingGui extends AbstractSettingGui {
|
|||
/**
|
||||
* @return A consumer to update the current setting's value.
|
||||
*/
|
||||
protected Consumer<InventoryClickEvent> setItemAsCursor() { //TODO redo consumer
|
||||
protected Consumer<InventoryClickEvent> setItemAsCursor() {
|
||||
return event -> {
|
||||
event.setCancelled(true);
|
||||
|
||||
|
|
|
|||
|
|
@ -92,4 +92,6 @@ abstract class AbstractMaterialGroup(private val name: String) {
|
|||
return Material.PAPER
|
||||
}
|
||||
|
||||
abstract fun updateMaterials()
|
||||
|
||||
}
|
||||
|
|
@ -47,6 +47,15 @@ class ExcludeGroup(name: String) : AbstractMaterialGroup(name) {
|
|||
return includedGroup
|
||||
}
|
||||
|
||||
override fun updateMaterials() {
|
||||
groupItems.clear()
|
||||
groupItems.addAll(includedMaterial)
|
||||
|
||||
includedGroup.forEach { group ->
|
||||
groupItems.addAll(group.getMaterials())
|
||||
}
|
||||
}
|
||||
|
||||
override fun getMaterials(): EnumSet<Material> {
|
||||
return groupItems
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,15 @@ class IncludeGroup(name: String) : AbstractMaterialGroup(name) {
|
|||
|
||||
override fun setNonGroupInheritedMaterials(materials: EnumSet<Material>) {
|
||||
super.setNonGroupInheritedMaterials(materials)
|
||||
// Update group items
|
||||
|
||||
updateMaterials()
|
||||
}
|
||||
|
||||
override fun getGroups(): MutableSet<AbstractMaterialGroup> {
|
||||
return includedGroup
|
||||
}
|
||||
|
||||
override fun updateMaterials() {
|
||||
groupItems.clear()
|
||||
groupItems.addAll(includedMaterial)
|
||||
|
||||
|
|
@ -54,10 +62,6 @@ class IncludeGroup(name: String) : AbstractMaterialGroup(name) {
|
|||
}
|
||||
}
|
||||
|
||||
override fun getGroups(): MutableSet<AbstractMaterialGroup> {
|
||||
return includedGroup
|
||||
}
|
||||
|
||||
override fun getMaterials(): EnumSet<Material> {
|
||||
return groupItems
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue