mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
Optimized list gui mapped to gui initialisation
This commit is contained in:
parent
36e26d762d
commit
e36f3a1694
13 changed files with 119 additions and 66 deletions
|
|
@ -9,6 +9,7 @@ import org.jetbrains.annotations.NotNull;
|
||||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||||
import xyz.alexcrea.cuanvil.dependency.DependencyManager;
|
import xyz.alexcrea.cuanvil.dependency.DependencyManager;
|
||||||
import xyz.alexcrea.cuanvil.gui.config.global.UnitRepairConfigGui;
|
import xyz.alexcrea.cuanvil.gui.config.global.UnitRepairConfigGui;
|
||||||
|
import xyz.alexcrea.cuanvil.gui.config.list.MappedGuiListConfigGui;
|
||||||
import xyz.alexcrea.cuanvil.gui.config.list.UnitRepairElementListGui;
|
import xyz.alexcrea.cuanvil.gui.config.list.UnitRepairElementListGui;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
@ -94,9 +95,9 @@ public class UnitRepairApi {
|
||||||
// Add to gui
|
// Add to gui
|
||||||
UnitRepairConfigGui repairConfigGui = UnitRepairConfigGui.getCurrentInstance();
|
UnitRepairConfigGui repairConfigGui = UnitRepairConfigGui.getCurrentInstance();
|
||||||
if(repairConfigGui != null) {
|
if(repairConfigGui != null) {
|
||||||
UnitRepairElementListGui elementGui = repairConfigGui.getInstanceOrCreate(unit);
|
UnitRepairElementListGui elementGui = repairConfigGui.getInstanceOrCreate(unit).getStored();
|
||||||
|
|
||||||
elementGui.updateValueForGeneric(repairableName, true);
|
if(elementGui != null) elementGui.updateValueForGeneric(repairableName, true);
|
||||||
repairConfigGui.updateValueForGeneric(unit, true);
|
repairConfigGui.updateValueForGeneric(unit, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -124,14 +125,15 @@ public class UnitRepairApi {
|
||||||
boolean lastValue = false;
|
boolean lastValue = false;
|
||||||
if(config.isConfigurationSection(unitName.toLowerCase())) {
|
if(config.isConfigurationSection(unitName.toLowerCase())) {
|
||||||
ConfigurationSection section = config.getConfigurationSection(unitName.toLowerCase());
|
ConfigurationSection section = config.getConfigurationSection(unitName.toLowerCase());
|
||||||
if(section.getKeys(false).isEmpty()) {
|
|
||||||
|
if(section != null && section.getKeys(false).isEmpty()) {
|
||||||
lastValue = true;
|
lastValue = true;
|
||||||
config.set(unitName.toLowerCase(), null);
|
config.set(unitName.toLowerCase(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (config.isConfigurationSection(unitName.toUpperCase())) {
|
} else if (config.isConfigurationSection(unitName.toUpperCase())) {
|
||||||
ConfigurationSection section = config.getConfigurationSection(unitName.toUpperCase());
|
ConfigurationSection section = config.getConfigurationSection(unitName.toUpperCase());
|
||||||
if(section.getKeys(false).isEmpty()) {
|
if(section != null && section.getKeys(false).isEmpty()) {
|
||||||
lastValue = true;
|
lastValue = true;
|
||||||
config.set(unitName.toUpperCase(), null);
|
config.set(unitName.toUpperCase(), null);
|
||||||
}
|
}
|
||||||
|
|
@ -146,9 +148,9 @@ public class UnitRepairApi {
|
||||||
// Remove from gui
|
// Remove from gui
|
||||||
UnitRepairConfigGui repairConfigGui = UnitRepairConfigGui.getCurrentInstance();
|
UnitRepairConfigGui repairConfigGui = UnitRepairConfigGui.getCurrentInstance();
|
||||||
if(repairConfigGui != null) {
|
if(repairConfigGui != null) {
|
||||||
UnitRepairElementListGui elementGui = repairConfigGui.getInstanceOrCreate(unit);
|
UnitRepairElementListGui elementGui = repairConfigGui.getInstanceOrCreate(unit).getStored();
|
||||||
|
|
||||||
elementGui.removeGeneric(repairableName);
|
if(elementGui != null) elementGui.removeGeneric(repairableName);
|
||||||
if(lastValue){
|
if(lastValue){
|
||||||
repairConfigGui.removeGeneric(unit);
|
repairConfigGui.removeGeneric(unit);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,8 @@ import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
public class CustomRecipeConfigGui extends MappedGuiListConfigGui<AnvilCustomRecipe, CustomRecipeSubSettingGui> {
|
public class CustomRecipeConfigGui extends MappedGuiListConfigGui<AnvilCustomRecipe,
|
||||||
|
MappedGuiListConfigGui.LazyElement<CustomRecipeSubSettingGui>> {
|
||||||
|
|
||||||
|
|
||||||
private static CustomRecipeConfigGui INSTANCE = new CustomRecipeConfigGui();
|
private static CustomRecipeConfigGui INSTANCE = new CustomRecipeConfigGui();
|
||||||
|
|
@ -44,15 +45,15 @@ public class CustomRecipeConfigGui extends MappedGuiListConfigGui<AnvilCustomRec
|
||||||
protected ItemStack createItemForGeneric(AnvilCustomRecipe recipe) {
|
protected ItemStack createItemForGeneric(AnvilCustomRecipe recipe) {
|
||||||
// Get base item to display
|
// Get base item to display
|
||||||
ItemStack craftResultItem = recipe.getResultItem();
|
ItemStack craftResultItem = recipe.getResultItem();
|
||||||
ItemStack displaydItem;
|
ItemStack displayedItem;
|
||||||
if(craftResultItem == null){
|
if(craftResultItem == null){
|
||||||
displaydItem = new ItemStack(Material.BARRIER);
|
displayedItem = new ItemStack(Material.BARRIER);
|
||||||
}else{
|
}else{
|
||||||
displaydItem = craftResultItem.clone();
|
displayedItem = craftResultItem.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
// edit displayed item
|
// edit displayed item
|
||||||
ItemMeta meta = displaydItem.getItemMeta();
|
ItemMeta meta = displayedItem.getItemMeta();
|
||||||
assert meta != null;
|
assert meta != null;
|
||||||
|
|
||||||
meta.setDisplayName("§e" + CasedStringUtil.snakeToUpperSpacedCase(recipe.toString()) + " §fCustom recipe");
|
meta.setDisplayName("§e" + CasedStringUtil.snakeToUpperSpacedCase(recipe.toString()) + " §fCustom recipe");
|
||||||
|
|
@ -67,13 +68,13 @@ public class CustomRecipeConfigGui extends MappedGuiListConfigGui<AnvilCustomRec
|
||||||
|
|
||||||
));
|
));
|
||||||
|
|
||||||
displaydItem.setItemMeta(meta);
|
displayedItem.setItemMeta(meta);
|
||||||
return displaydItem;
|
return displayedItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected CustomRecipeSubSettingGui newInstanceOfGui(AnvilCustomRecipe generic, GuiItem item) {
|
protected LazyElement<CustomRecipeSubSettingGui> newInstanceOfGui(AnvilCustomRecipe generic, GuiItem item) {
|
||||||
return new CustomRecipeSubSettingGui(this, generic, item);
|
return new LazyElement<>(item, () -> new CustomRecipeSubSettingGui(this, generic));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,8 @@ import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
public class EnchantConflictGui extends MappedGuiListConfigGui<EnchantConflictGroup, EnchantConflictSubSettingGui> {
|
public class EnchantConflictGui extends MappedGuiListConfigGui<EnchantConflictGroup,
|
||||||
|
MappedGuiListConfigGui.LazyElement<EnchantConflictSubSettingGui>> {
|
||||||
|
|
||||||
private static EnchantConflictGui INSTANCE;
|
private static EnchantConflictGui INSTANCE;
|
||||||
|
|
||||||
|
|
@ -86,8 +87,8 @@ public class EnchantConflictGui extends MappedGuiListConfigGui<EnchantConflictGr
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected EnchantConflictSubSettingGui newInstanceOfGui(EnchantConflictGroup conflict, GuiItem item) {
|
protected LazyElement<EnchantConflictSubSettingGui> newInstanceOfGui(EnchantConflictGroup conflict, GuiItem item) {
|
||||||
return new EnchantConflictSubSettingGui(this, conflict, item);
|
return new LazyElement<>(item, () -> new EnchantConflictSubSettingGui(this, conflict));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -15,12 +15,13 @@ import xyz.alexcrea.cuanvil.group.ItemGroupManager;
|
||||||
import xyz.alexcrea.cuanvil.gui.config.list.MappedGuiListConfigGui;
|
import xyz.alexcrea.cuanvil.gui.config.list.MappedGuiListConfigGui;
|
||||||
import xyz.alexcrea.cuanvil.gui.config.list.elements.GroupConfigSubSettingGui;
|
import xyz.alexcrea.cuanvil.gui.config.list.elements.GroupConfigSubSettingGui;
|
||||||
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
||||||
|
import xyz.alexcrea.cuanvil.util.LazyValue;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
public class GroupConfigGui extends MappedGuiListConfigGui<IncludeGroup, GroupConfigSubSettingGui> {
|
public class GroupConfigGui extends MappedGuiListConfigGui<IncludeGroup, MappedGuiListConfigGui.LazyElement<GroupConfigSubSettingGui>> {
|
||||||
|
|
||||||
private static GroupConfigGui INSTANCE;
|
private static GroupConfigGui INSTANCE;
|
||||||
|
|
||||||
|
|
@ -73,8 +74,8 @@ public class GroupConfigGui extends MappedGuiListConfigGui<IncludeGroup, GroupCo
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected GroupConfigSubSettingGui newInstanceOfGui(IncludeGroup group, GuiItem item) {
|
protected LazyElement<GroupConfigSubSettingGui> newInstanceOfGui(IncludeGroup group, GuiItem item) {
|
||||||
return new GroupConfigSubSettingGui(this, group, item);
|
return new LazyElement<>(item, () -> new GroupConfigSubSettingGui(this, group));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,8 @@ import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
public class UnitRepairConfigGui extends MappedGuiListConfigGui<Material, UnitRepairElementListGui> {
|
public class UnitRepairConfigGui extends
|
||||||
|
MappedGuiListConfigGui<Material, MappedGuiListConfigGui.LazyElement<UnitRepairElementListGui>> {
|
||||||
|
|
||||||
private static UnitRepairConfigGui INSTANCE;
|
private static UnitRepairConfigGui INSTANCE;
|
||||||
|
|
||||||
|
|
@ -41,10 +42,12 @@ public class UnitRepairConfigGui extends MappedGuiListConfigGui<Material, UnitRe
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected UnitRepairElementListGui newInstanceOfGui(Material material, GuiItem item) {
|
protected LazyElement<UnitRepairElementListGui> newInstanceOfGui(Material material, GuiItem item) {
|
||||||
UnitRepairElementListGui element = new UnitRepairElementListGui(material, this, item);
|
return new LazyElement<>(item, () -> {
|
||||||
|
UnitRepairElementListGui element = new UnitRepairElementListGui(material, this);
|
||||||
element.init();
|
element.init();
|
||||||
return element;
|
return element;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -115,7 +118,7 @@ public class UnitRepairConfigGui extends MappedGuiListConfigGui<Material, UnitRe
|
||||||
updateValueForGeneric(type, true);
|
updateValueForGeneric(type, true);
|
||||||
|
|
||||||
// Display material edit setting
|
// Display material edit setting
|
||||||
this.elementGuiMap.get(type).getMappedGui().show(player);
|
this.elementGuiMap.get(type).get().getMappedGui().show(player);
|
||||||
},
|
},
|
||||||
true
|
true
|
||||||
).show(clickEvent.getWhoClicked());
|
).show(clickEvent.getWhoClicked());
|
||||||
|
|
@ -123,8 +126,8 @@ public class UnitRepairConfigGui extends MappedGuiListConfigGui<Material, UnitRe
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public UnitRepairElementListGui getInstanceOrCreate(Material mat){
|
public LazyElement<UnitRepairElementListGui> getInstanceOrCreate(Material mat){
|
||||||
UnitRepairElementListGui element = this.elementGuiMap.get(mat);
|
LazyElement<UnitRepairElementListGui> element = this.elementGuiMap.get(mat);
|
||||||
if(element == null){
|
if(element == null){
|
||||||
updateValueForGeneric(mat, false);
|
updateValueForGeneric(mat, false);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,15 +3,19 @@ package xyz.alexcrea.cuanvil.gui.config.list;
|
||||||
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||||
import io.delilaheve.CustomAnvil;
|
import io.delilaheve.CustomAnvil;
|
||||||
import org.bukkit.entity.HumanEntity;
|
import org.bukkit.entity.HumanEntity;
|
||||||
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import xyz.alexcrea.cuanvil.gui.config.list.elements.ElementMappedToListGui;
|
import xyz.alexcrea.cuanvil.gui.config.list.elements.ElementMappedToListGui;
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
|
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
|
||||||
|
import xyz.alexcrea.cuanvil.util.LazyValue;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public abstract class MappedGuiListConfigGui< T, S extends ElementMappedToListGui> extends MappedElementListConfigGui< T, S > {
|
public abstract class MappedGuiListConfigGui< T, S extends MappedGuiListConfigGui.LazyElement<?>>
|
||||||
|
extends MappedElementListConfigGui< T, S > {
|
||||||
|
|
||||||
protected MappedGuiListConfigGui(@NotNull String title) {
|
protected MappedGuiListConfigGui(@NotNull String title) {
|
||||||
super(title);
|
super(title);
|
||||||
|
|
@ -20,7 +24,10 @@ public abstract class MappedGuiListConfigGui< T, S extends ElementMappedToListGu
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reloadValues() {
|
public void reloadValues() {
|
||||||
this.elementGuiMap.forEach((conflict, gui) -> gui.cleanAndBeUnusable());
|
this.elementGuiMap.forEach((conflict, element) -> {
|
||||||
|
ElementMappedToListGui gui = element.getStored();
|
||||||
|
if(gui != null) gui.cleanAndBeUnusable();
|
||||||
|
});
|
||||||
this.elementGuiMap.clear();
|
this.elementGuiMap.clear();
|
||||||
|
|
||||||
super.reloadValues();
|
super.reloadValues();
|
||||||
|
|
@ -30,23 +37,24 @@ public abstract class MappedGuiListConfigGui< T, S extends ElementMappedToListGu
|
||||||
protected S newElementRequested(T generic, GuiItem newItem) {
|
protected S newElementRequested(T generic, GuiItem newItem) {
|
||||||
S element = newInstanceOfGui(generic, newItem);
|
S element = newInstanceOfGui(generic, newItem);
|
||||||
|
|
||||||
newItem.setAction(GuiGlobalActions.openGuiAction(element.getMappedGui()));
|
newItem.setAction(element.openAction());
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected GuiItem findItemFromElement(T generic, S element) {
|
protected GuiItem findItemFromElement(T generic, S element) {
|
||||||
return element.getParentItemForThisGui();
|
return element.getParentItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void updateElement(T generic, S element) {
|
protected void updateElement(T generic, S element) {
|
||||||
element.updateLocal();
|
ElementMappedToListGui gui = element.getStored();
|
||||||
|
if(gui != null) gui.updateLocal();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected GuiItem findGuiItemForRemoval(T generic, S element) {
|
protected GuiItem findGuiItemForRemoval(T generic, S element) {
|
||||||
return element.getParentItemForThisGui();
|
return element.getParentItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -90,7 +98,7 @@ public abstract class MappedGuiListConfigGui< T, S extends ElementMappedToListGu
|
||||||
updateValueForGeneric(generic, true);
|
updateValueForGeneric(generic, true);
|
||||||
|
|
||||||
// show the new conflict config to the player
|
// show the new conflict config to the player
|
||||||
this.elementGuiMap.get(generic).getMappedGui().show(player);
|
this.elementGuiMap.get(generic).get().getMappedGui().show(player);
|
||||||
|
|
||||||
update();
|
update();
|
||||||
};
|
};
|
||||||
|
|
@ -105,4 +113,28 @@ public abstract class MappedGuiListConfigGui< T, S extends ElementMappedToListGu
|
||||||
|
|
||||||
protected abstract T createAndSaveNewEmptyGeneric(String name);
|
protected abstract T createAndSaveNewEmptyGeneric(String name);
|
||||||
|
|
||||||
|
public static class LazyElement<T extends ElementMappedToListGui> extends LazyValue<T> {
|
||||||
|
|
||||||
|
private final GuiItem parentItem;
|
||||||
|
private final LazyValue<Consumer<InventoryClickEvent>> lazyOpenConsumer;
|
||||||
|
public LazyElement(GuiItem parentItem, Supplier<T> valueSupplier) {
|
||||||
|
super(valueSupplier);
|
||||||
|
this.parentItem = parentItem;
|
||||||
|
|
||||||
|
this.lazyOpenConsumer = new LazyValue<>(() ->
|
||||||
|
GuiGlobalActions.openGuiAction(this.get().getMappedGui()))
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GuiItem getParentItem() {
|
||||||
|
return parentItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public Consumer<InventoryClickEvent> openAction(){
|
||||||
|
return event -> lazyOpenConsumer.get().accept(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,17 +26,14 @@ import java.util.function.Consumer;
|
||||||
|
|
||||||
public class UnitRepairElementListGui extends SettingGuiListConfigGui<String, DoubleSettingGui.DoubleSettingFactory> implements ElementMappedToListGui {
|
public class UnitRepairElementListGui extends SettingGuiListConfigGui<String, DoubleSettingGui.DoubleSettingFactory> implements ElementMappedToListGui {
|
||||||
|
|
||||||
private final GuiItem parentItem;
|
|
||||||
private final Material parentMaterial;
|
private final Material parentMaterial;
|
||||||
private final UnitRepairConfigGui parentGui;
|
private final UnitRepairConfigGui parentGui;
|
||||||
private final String materialName;
|
private final String materialName;
|
||||||
|
|
||||||
private boolean shouldWork = true;
|
private boolean shouldWork = true;
|
||||||
public UnitRepairElementListGui(@NotNull Material parentMaterial,
|
public UnitRepairElementListGui(@NotNull Material parentMaterial,
|
||||||
@NotNull UnitRepairConfigGui parentGui,
|
@NotNull UnitRepairConfigGui parentGui) {
|
||||||
@NotNull GuiItem parentItem) {
|
|
||||||
super("§e" + CasedStringUtil.snakeToUpperSpacedCase(parentMaterial.name().toLowerCase()) + " §rUnit repair");
|
super("§e" + CasedStringUtil.snakeToUpperSpacedCase(parentMaterial.name().toLowerCase()) + " §rUnit repair");
|
||||||
this.parentItem = parentItem;
|
|
||||||
this.parentMaterial = parentMaterial;
|
this.parentMaterial = parentMaterial;
|
||||||
this.parentGui = parentGui;
|
this.parentGui = parentGui;
|
||||||
this.materialName = CasedStringUtil.snakeToUpperSpacedCase(parentMaterial.name().toLowerCase());
|
this.materialName = CasedStringUtil.snakeToUpperSpacedCase(parentMaterial.name().toLowerCase());
|
||||||
|
|
@ -165,11 +162,6 @@ public class UnitRepairElementListGui extends SettingGuiListConfigGui<String, Do
|
||||||
|
|
||||||
// ElementMappedToListGui methods
|
// ElementMappedToListGui methods
|
||||||
|
|
||||||
@Override
|
|
||||||
public GuiItem getParentItemForThisGui() {
|
|
||||||
return this.parentItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override // Not used in this implementation
|
@Override // Not used in this implementation
|
||||||
public void updateLocal() {}
|
public void updateLocal() {}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,9 +35,8 @@ public class CustomRecipeSubSettingGui extends MappedToListSubSettingGui {
|
||||||
|
|
||||||
public CustomRecipeSubSettingGui(
|
public CustomRecipeSubSettingGui(
|
||||||
@NotNull CustomRecipeConfigGui parent,
|
@NotNull CustomRecipeConfigGui parent,
|
||||||
@NotNull AnvilCustomRecipe anvilRecipe,
|
@NotNull AnvilCustomRecipe anvilRecipe) {
|
||||||
@NotNull GuiItem parentItemForThisGui) {
|
super(3, "§e" + CasedStringUtil.snakeToUpperSpacedCase(anvilRecipe.toString()) + " §8Config");
|
||||||
super(parentItemForThisGui, 3, "§e" + CasedStringUtil.snakeToUpperSpacedCase(anvilRecipe.toString()) + " §8Config");
|
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.anvilRecipe = anvilRecipe;
|
this.anvilRecipe = anvilRecipe;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,9 @@
|
||||||
package xyz.alexcrea.cuanvil.gui.config.list.elements;
|
package xyz.alexcrea.cuanvil.gui.config.list.elements;
|
||||||
|
|
||||||
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
|
||||||
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
|
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
|
||||||
|
|
||||||
public interface ElementMappedToListGui {
|
public interface ElementMappedToListGui {
|
||||||
|
|
||||||
GuiItem getParentItemForThisGui();
|
|
||||||
|
|
||||||
void updateLocal();
|
void updateLocal();
|
||||||
|
|
||||||
void cleanAndBeUnusable();
|
void cleanAndBeUnusable();
|
||||||
|
|
|
||||||
|
|
@ -39,10 +39,8 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl
|
||||||
|
|
||||||
public EnchantConflictSubSettingGui(
|
public EnchantConflictSubSettingGui(
|
||||||
@NotNull EnchantConflictGui parent,
|
@NotNull EnchantConflictGui parent,
|
||||||
@NotNull EnchantConflictGroup enchantConflict,
|
@NotNull EnchantConflictGroup enchantConflict) {
|
||||||
@NotNull GuiItem parentItemForThisGui) {
|
super(3,
|
||||||
super(parentItemForThisGui,
|
|
||||||
3,
|
|
||||||
"§e" + CasedStringUtil.snakeToUpperSpacedCase(enchantConflict.toString()) + " §8Config");
|
"§e" + CasedStringUtil.snakeToUpperSpacedCase(enchantConflict.toString()) + " §8Config");
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.enchantConflict = enchantConflict;
|
this.enchantConflict = enchantConflict;
|
||||||
|
|
|
||||||
|
|
@ -37,9 +37,8 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
|
||||||
|
|
||||||
public GroupConfigSubSettingGui(
|
public GroupConfigSubSettingGui(
|
||||||
@NotNull GroupConfigGui parent,
|
@NotNull GroupConfigGui parent,
|
||||||
@NotNull IncludeGroup group,
|
@NotNull IncludeGroup group) {
|
||||||
@NotNull GuiItem item) {
|
super(3,
|
||||||
super(item, 3,
|
|
||||||
CasedStringUtil.snakeToUpperSpacedCase(group.getName()) + " Config");
|
CasedStringUtil.snakeToUpperSpacedCase(group.getName()) + " Config");
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.group = group;
|
this.group = group;
|
||||||
|
|
|
||||||
|
|
@ -9,18 +9,10 @@ import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
||||||
|
|
||||||
public abstract class MappedToListSubSettingGui extends ChestGui implements ValueUpdatableGui, ElementMappedToListGui {
|
public abstract class MappedToListSubSettingGui extends ChestGui implements ValueUpdatableGui, ElementMappedToListGui {
|
||||||
|
|
||||||
private final GuiItem item;
|
|
||||||
protected MappedToListSubSettingGui(
|
protected MappedToListSubSettingGui(
|
||||||
GuiItem item,
|
|
||||||
int rows,
|
int rows,
|
||||||
@NotNull String title) {
|
@NotNull String title) {
|
||||||
super(rows, title, CustomAnvil.instance);
|
super(rows, title, CustomAnvil.instance);
|
||||||
this.item = item;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public GuiItem getParentItemForThisGui() {
|
|
||||||
return item;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
36
src/main/java/xyz/alexcrea/cuanvil/util/LazyValue.java
Normal file
36
src/main/java/xyz/alexcrea/cuanvil/util/LazyValue.java
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
package xyz.alexcrea.cuanvil.util;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
public class LazyValue<T> {
|
||||||
|
|
||||||
|
private final Supplier<T> valueSupplier;
|
||||||
|
private T storedValue;
|
||||||
|
|
||||||
|
public LazyValue(Supplier<T> valueSupplier) {
|
||||||
|
this.valueSupplier = valueSupplier;
|
||||||
|
this.storedValue = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public T getStored(){
|
||||||
|
return storedValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public T get(){
|
||||||
|
if (storedValue != null) return storedValue;
|
||||||
|
|
||||||
|
synchronized(this) {
|
||||||
|
if(storedValue == null) {
|
||||||
|
storedValue = valueSupplier.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return storedValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue