Start to create Enchantment sub setting gui & enchantment conflict gui

This commit is contained in:
alexcrea 2024-03-22 00:07:56 +01:00
parent dc35d59077
commit 814a8a2c89
13 changed files with 297 additions and 65 deletions

View file

@ -9,6 +9,7 @@ import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import xyz.alexcrea.cuanvil.gui.config.openable.BasicConfigGui;
import xyz.alexcrea.cuanvil.gui.config.openable.EnchantConflictGui;
import xyz.alexcrea.cuanvil.gui.config.openable.EnchantCostConfigGui;
import xyz.alexcrea.cuanvil.gui.config.openable.EnchantLimitConfigGui;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
@ -72,17 +73,26 @@ public class MainConfigGui extends ChestGui {
GuiItem enchantCostItem = GuiGlobalItems.goToGuiItem(enchantCostItemstack, EnchantCostConfigGui.INSTANCE);
pane.bindItem('3', enchantCostItem);
// Enchantment Conflicts
ItemStack EnchantConflictItemstack = new ItemStack(Material.EXPERIENCE_BOTTLE);
ItemMeta enchantConflictMeta = EnchantConflictItemstack.getItemMeta();
enchantConflictMeta.setDisplayName("\u00A7aEnchantment Conflict");
enchantConflictMeta.setLore(Collections.singletonList("\u00A77Click here to open enchantment conflict menu"));
EnchantConflictItemstack.setItemMeta(enchantConflictMeta);
GuiItem enchantConflictItem = GuiGlobalItems.goToGuiItem(EnchantConflictItemstack, EnchantConflictGui.INSTANCE);
pane.bindItem('4', enchantConflictItem);
// WIP configuration items
ItemStack wipItemstack = new ItemStack(Material.BARRIER);
ItemMeta wipMeta = wipItemstack.getItemMeta();
wipMeta.setDisplayName("\u00A7cWIP");
wipItemstack.setItemMeta(wipMeta);
GuiItem wip4 = new GuiItem(wipItemstack, GuiGlobalActions.stayInPlace, CustomAnvil.instance);
GuiItem wip5 = new GuiItem(wipItemstack, GuiGlobalActions.stayInPlace, CustomAnvil.instance);
GuiItem wip6 = new GuiItem(wipItemstack, GuiGlobalActions.stayInPlace, CustomAnvil.instance);
pane.bindItem('4', wip4);
pane.bindItem('5', wip5);
pane.bindItem('6', wip6);

View file

@ -4,15 +4,11 @@ import com.github.stefvanschie.inventoryframework.gui.GuiItem;
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
import com.github.stefvanschie.inventoryframework.pane.Orientable;
import com.github.stefvanschie.inventoryframework.pane.OutlinePane;
import com.github.stefvanschie.inventoryframework.pane.Pane;
import com.github.stefvanschie.inventoryframework.pane.PatternPane;
import com.github.stefvanschie.inventoryframework.pane.util.Pattern;
import io.delilaheve.CustomAnvil;
import org.bukkit.enchantments.Enchantment;
import xyz.alexcrea.cuanvil.gui.MainConfigGui;
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
import xyz.alexcrea.cuanvil.gui.config.settings.AbstractSettingGui;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
import java.util.ArrayList;
@ -24,49 +20,22 @@ import java.util.List;
*/
public abstract class AbstractEnchantConfigGui<T extends AbstractSettingGui.SettingGuiFactory> extends ValueUpdatableGui {
private final Gui backGui;
/**
* Constructor for a gui displaying available enchantment to edit a enchantment setting.
* @param title Title of the gui.
* @param backGui Gui to go back on click on the "back" button.
*/
protected AbstractEnchantConfigGui(String title, Gui backGui){
super(6, title, CustomAnvil.instance);
this.backGui = backGui;
}
/**
* Constructor for a gui displaying available enchantment to edit a enchantment setting.
* @param title Title of the gui.
*/
protected AbstractEnchantConfigGui(String title){
this(title, MainConfigGui.INSTANCE);
super(6, title, CustomAnvil.instance);
}
PatternPane backgroundItems;
OutlinePane filledEnchant;
private OutlinePane filledEnchant;
// Why is called like it is rn
/**
* Initialise value updatable gui pattern
*/
protected void init(){
// Back item panel
Pattern pattern = new Pattern(
"000000000",
"000000000",
"000000000",
"000000000",
"000000000",
"B11111111"
);
this.backgroundItems = new PatternPane(0, 0, 9, 6, Pane.Priority.LOW, pattern);
addPane(this.backgroundItems);
GuiGlobalItems.addBackItem(this.backgroundItems, this.backGui);
GuiGlobalItems.addBackgroundItem(this.backgroundItems);
this.backgroundItems.bindItem('1', GuiSharedConstant.SECONDARY_BACKGROUND_ITEM);
addPane(GuiSharedConstant.BACK_TO_MAIN_MENU_BIG_LIST_DISPLAY_BACKGROUND_PANE);
// enchant item panel
this.filledEnchant = new OutlinePane(0, 0, 9, 5);

View file

@ -1,6 +1,5 @@
package xyz.alexcrea.cuanvil.gui.config;
import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder;
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
import com.github.stefvanschie.inventoryframework.gui.type.ChestGui;
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
@ -14,6 +13,7 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
import java.util.Arrays;
import java.util.Collections;
@ -39,13 +39,14 @@ public class ConfirmActionGui extends ChestGui {
CONFIRM_ITEM.setItemMeta(meta);
}
public ConfirmActionGui(@NotNull TextHolder title, String actionDescription, Gui backOnCancel, Gui backOnConfirm, Supplier<Boolean> onConfirm) {
public ConfirmActionGui(@NotNull String title, String actionDescription,
Gui backOnCancel, Gui backOnConfirm, Supplier<Boolean> onConfirm) {
super(3, title, CustomAnvil.instance);
Pattern pattern = new Pattern(
"000000000",
GuiSharedConstant.EMPTY_GUI_FULL_LINE,
"00B0I0S00",
"000000000"
GuiSharedConstant.EMPTY_GUI_FULL_LINE
);
PatternPane pane = new PatternPane(0, 0, pattern.getLength(), pattern.getHeight(), pattern);
addPane(pane);

View file

@ -16,6 +16,7 @@ import xyz.alexcrea.cuanvil.gui.config.settings.BoolSettingsGui;
import xyz.alexcrea.cuanvil.gui.config.settings.IntSettingsGui;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
import java.util.Collections;
@ -44,7 +45,7 @@ public class BasicConfigGui extends ValueUpdatableGui {
*/
private void init(){
Pattern pattern = new Pattern(
"000000000",
GuiSharedConstant.EMPTY_GUI_FULL_LINE,
"012345670",
"B00000000"
);

View file

@ -0,0 +1,75 @@
package xyz.alexcrea.cuanvil.gui.config.openable;
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
import com.github.stefvanschie.inventoryframework.gui.type.ChestGui;
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
import com.github.stefvanschie.inventoryframework.pane.Orientable;
import com.github.stefvanschie.inventoryframework.pane.OutlinePane;
import io.delilaheve.CustomAnvil;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import xyz.alexcrea.cuanvil.config.ConfigHolder;
import xyz.alexcrea.cuanvil.group.EnchantConflictGroup;
import xyz.alexcrea.cuanvil.gui.MainConfigGui;
import xyz.alexcrea.cuanvil.gui.config.settings.subsetting.EnchantConflictSubSettingGui;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
import java.util.HashMap;
public class EnchantConflictGui extends ChestGui {
public final static EnchantConflictGui INSTANCE = new EnchantConflictGui();
private final HashMap<EnchantConflictGroup, EnchantConflictSubSettingGui> conflictGuiMap;
static {
INSTANCE.init();
}
private EnchantConflictGui() {
super(6, "§eConflict Config", CustomAnvil.instance);
this.conflictGuiMap = new HashMap<>();
}
private OutlinePane filledEnchant;
private void init(){
// Back item panel
addPane(GuiSharedConstant.BACK_TO_MAIN_MENU_BIG_LIST_DISPLAY_BACKGROUND_PANE);
// enchant item panel
this.filledEnchant = new OutlinePane(0, 0, 9, 5);
this.filledEnchant.align(OutlinePane.Alignment.BEGIN);
this.filledEnchant.setOrientation(Orientable.Orientation.HORIZONTAL);
addPane(this.filledEnchant);
reloadValues();
}
public void reloadValues(){
this.conflictGuiMap.forEach((conflict, gui) -> gui.cleanUnused());
this.conflictGuiMap.clear();
this.filledEnchant.clear();
// Create new sub setting gui
for (EnchantConflictGroup conflict : ConfigHolder.CONFLICT_HOLDER.getConflictManager().getConflictList()) {
EnchantConflictSubSettingGui conflictGui = new EnchantConflictSubSettingGui(this, conflict);
// Temporaire, il faut faire un item avec le conflict et donc un generateur arbitraire
ItemStack item = new ItemStack(Material.ENCHANTED_BOOK);
filledEnchant.addItem(new GuiItem(item, GuiGlobalActions.openGuiAction(conflictGui), CustomAnvil.instance));
}
}
public void updateValueForConflict(EnchantConflictGroup conflict){
}
public void removeConflict(EnchantConflictGroup conflict){
}
}

View file

@ -59,13 +59,13 @@ public class EnchantCostConfigGui extends AbstractEnchantConfigGui<EnchantCostSe
// Get item properties
int itemCost = factory.getConfiguredValue();
int bookCost = factory.getConfiguredBookValue();
StringBuilder itemName = new StringBuilder("\u00A7a").append(factory.getTitle());
String itemName = "\u00A7a" + factory.getTitle();
// Create item
ItemStack item = new ItemStack(Material.ENCHANTED_BOOK);
ItemMeta itemMeta = item.getItemMeta();
// Edit name and lore
itemMeta.setDisplayName(itemName.toString());
itemMeta.setDisplayName(itemName);
itemMeta.setLore(Arrays.asList(
"\u00A77Item Cost: " + itemCost,
"\u00A77Book Cost: " + bookCost));

View file

@ -46,7 +46,7 @@ public class BoolSettingsGui extends AbstractSettingGui{
@Override
public Pattern getGuiPattern() {
return new Pattern(
"000000000",
GuiSharedConstant.EMPTY_GUI_FULL_LINE,
"D0-0v0+00",
"B0000000S"
);

View file

@ -48,11 +48,11 @@ public class EnchantSelectSettingGui extends AbstractSettingGui{
@Override
protected Pattern getGuiPattern() {
return new Pattern(
"000000000",
"000000000",
"000000000",
"000000000",
"000000000",
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,
"B1111111S"
);
}

View file

@ -47,11 +47,11 @@ public class GroupSelectSettingGui extends AbstractSettingGui{
@Override
protected Pattern getGuiPattern() {
return new Pattern(
"000000000",
"000000000",
"000000000",
"000000000",
"000000000",
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,
"B1111111S"
);
}

View file

@ -0,0 +1,133 @@
package xyz.alexcrea.cuanvil.gui.config.settings.subsetting;
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
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.enchantments.Enchantment;
import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull;
import xyz.alexcrea.cuanvil.config.ConfigHolder;
import xyz.alexcrea.cuanvil.group.EnchantConflictGroup;
import xyz.alexcrea.cuanvil.group.EnchantConflictManager;
import xyz.alexcrea.cuanvil.gui.MainConfigGui;
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
import xyz.alexcrea.cuanvil.gui.config.ConfirmActionGui;
import xyz.alexcrea.cuanvil.gui.config.openable.EnchantConflictGui;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
import java.util.Collections;
import java.util.function.Supplier;
public class EnchantConflictSubSettingGui extends ValueUpdatableGui {
private final EnchantConflictGui parent;
private final EnchantConflictGroup enchantConflict;
private final PatternPane pane;
private boolean canOpen = true;
public EnchantConflictSubSettingGui(
@NotNull EnchantConflictGui parent,
@NotNull EnchantConflictGroup enchantConflict) {
super(3, "\u00A7aConfig for \u00A7e" + CasedStringUtil.snakeToUpperSpacedCase(enchantConflict.getName()), CustomAnvil.instance);
this.parent = parent;
this.enchantConflict = enchantConflict;
Pattern pattern = new Pattern(
GuiSharedConstant.EMPTY_GUI_FULL_LINE,
"00EGM000D",
"B00000000"
);
this.pane = new PatternPane(0, 0, 9, 3, pattern);
addPane(this.pane);
prepareStaticValues();
//updateGuiValues();
}
private void prepareStaticValues() {
GuiGlobalItems.addBackItem(pane, MainConfigGui.INSTANCE);
GuiGlobalItems.addBackgroundItem(pane);
// Delete item
ItemStack deleteItem = new ItemStack(Material.RED_TERRACOTTA);
ItemMeta deleteMeta = deleteItem.getItemMeta();
deleteMeta.setDisplayName("\u00A74DELETE CONFLICT");
deleteMeta.setLore(Collections.singletonList("\u00A7cCaution with this button !"));
deleteItem.setItemMeta(deleteMeta);
pane.bindItem('D', new GuiItem(deleteItem, GuiGlobalActions.openGuiAction(createDeleteGui()), CustomAnvil.instance));
}
private ConfirmActionGui createDeleteGui() {
Supplier<Boolean> deleteSupplier = () ->{
EnchantConflictManager manager = ConfigHolder.CONFLICT_HOLDER.getConflictManager();
// Remove from manager
for (Enchantment enchantment : enchantConflict.getEnchants()) {
manager.removeConflictFromMap(enchantment, enchantConflict);
}
manager.conflictList.remove(enchantConflict);
// Update config file storage
ConfigHolder.CONFLICT_HOLDER.getConfig().set(enchantConflict.getName(), null);
// Save
boolean success = true;
if(GuiSharedConstant.TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE){
success = ConfigHolder.CONFLICT_HOLDER.saveToDisk(GuiSharedConstant.TEMPORARY_DO_BACKUP_EVERY_SAVE);
}
return success;
};
return new ConfirmActionGui("\u00A7cDelete \u00A7e"+CasedStringUtil.snakeToUpperSpacedCase(enchantConflict.getName())+"\u00A7c ?",
"\u00A77Confirm that you want to delete this conflict.",
this, this.parent, deleteSupplier
);
}
@Override
public void updateGuiValues() {
this.parent.updateValueForConflict(this.enchantConflict);
// Parent should call updateLocal
}
public void updateLocal(){
if(!this.canOpen) return;
}
public void cleanUnused(){
for (HumanEntity viewer : getViewers()) {
this.parent.show(viewer);
}
this.canOpen = false;
// Just in case something is extremely wrong
GuiItem background = GuiGlobalItems.backgroundItem();
pane.bindItem('E', background);
pane.bindItem('G', background);
pane.bindItem('M', background);
pane.bindItem('D', background);
}
@Override
public void show(@NotNull HumanEntity humanEntity) {
if(this.canOpen){
super.show(humanEntity);
}else{
parent.show(humanEntity);
}
}
}

View file

@ -1,8 +1,12 @@
package xyz.alexcrea.cuanvil.gui.util;
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
import com.github.stefvanschie.inventoryframework.pane.Pane;
import com.github.stefvanschie.inventoryframework.pane.PatternPane;
import com.github.stefvanschie.inventoryframework.pane.util.Pattern;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import xyz.alexcrea.cuanvil.gui.MainConfigGui;
import java.util.Arrays;
import java.util.Comparator;
@ -11,6 +15,7 @@ import java.util.List;
public class GuiSharedConstant {
public static final List<Enchantment> SORTED_ENCHANTMENT_LIST;
static {
SORTED_ENCHANTMENT_LIST = Arrays.asList(Enchantment.values());
SORTED_ENCHANTMENT_LIST.sort(Comparator.comparing(ench -> ench.getKey().getKey()));
@ -19,8 +24,29 @@ public class GuiSharedConstant {
public static final Material SECONDARY_BACKGROUND_MATERIAL = Material.BLACK_STAINED_GLASS_PANE;
public static final GuiItem SECONDARY_BACKGROUND_ITEM = GuiGlobalItems.backgroundItem(GuiSharedConstant.SECONDARY_BACKGROUND_MATERIAL);
public static final String EMPTY_GUI_FULL_LINE = "000000000";
// Temporary values, until I get something better.
public static final boolean TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE = true;
public static final boolean TEMPORARY_DO_BACKUP_EVERY_SAVE = true;
public static final PatternPane BACK_TO_MAIN_MENU_BIG_LIST_DISPLAY_BACKGROUND_PANE;
static {
Pattern pattern = 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,
"B11111111"
);
BACK_TO_MAIN_MENU_BIG_LIST_DISPLAY_BACKGROUND_PANE = new PatternPane(0, 0, 9, 6, Pane.Priority.LOW, pattern);
GuiGlobalItems.addBackItem(BACK_TO_MAIN_MENU_BIG_LIST_DISPLAY_BACKGROUND_PANE, MainConfigGui.INSTANCE);
GuiGlobalItems.addBackgroundItem(BACK_TO_MAIN_MENU_BIG_LIST_DISPLAY_BACKGROUND_PANE);
BACK_TO_MAIN_MENU_BIG_LIST_DISPLAY_BACKGROUND_PANE.bindItem('1', GuiSharedConstant.SECONDARY_BACKGROUND_ITEM);
}
}