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.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import xyz.alexcrea.cuanvil.gui.config.openable.BasicConfigGui; 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.EnchantCostConfigGui;
import xyz.alexcrea.cuanvil.gui.config.openable.EnchantLimitConfigGui; import xyz.alexcrea.cuanvil.gui.config.openable.EnchantLimitConfigGui;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
@ -72,17 +73,26 @@ public class MainConfigGui extends ChestGui {
GuiItem enchantCostItem = GuiGlobalItems.goToGuiItem(enchantCostItemstack, EnchantCostConfigGui.INSTANCE); GuiItem enchantCostItem = GuiGlobalItems.goToGuiItem(enchantCostItemstack, EnchantCostConfigGui.INSTANCE);
pane.bindItem('3', enchantCostItem); 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 // WIP configuration items
ItemStack wipItemstack = new ItemStack(Material.BARRIER); ItemStack wipItemstack = new ItemStack(Material.BARRIER);
ItemMeta wipMeta = wipItemstack.getItemMeta(); ItemMeta wipMeta = wipItemstack.getItemMeta();
wipMeta.setDisplayName("\u00A7cWIP"); wipMeta.setDisplayName("\u00A7cWIP");
wipItemstack.setItemMeta(wipMeta); wipItemstack.setItemMeta(wipMeta);
GuiItem wip4 = new GuiItem(wipItemstack, GuiGlobalActions.stayInPlace, CustomAnvil.instance);
GuiItem wip5 = 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); GuiItem wip6 = new GuiItem(wipItemstack, GuiGlobalActions.stayInPlace, CustomAnvil.instance);
pane.bindItem('4', wip4);
pane.bindItem('5', wip5); pane.bindItem('5', wip5);
pane.bindItem('6', wip6); 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.gui.type.util.Gui;
import com.github.stefvanschie.inventoryframework.pane.Orientable; import com.github.stefvanschie.inventoryframework.pane.Orientable;
import com.github.stefvanschie.inventoryframework.pane.OutlinePane; 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 io.delilaheve.CustomAnvil;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import xyz.alexcrea.cuanvil.gui.MainConfigGui; import xyz.alexcrea.cuanvil.gui.MainConfigGui;
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui; import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
import xyz.alexcrea.cuanvil.gui.config.settings.AbstractSettingGui; import xyz.alexcrea.cuanvil.gui.config.settings.AbstractSettingGui;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant; import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
import java.util.ArrayList; import java.util.ArrayList;
@ -24,49 +20,22 @@ import java.util.List;
*/ */
public abstract class AbstractEnchantConfigGui<T extends AbstractSettingGui.SettingGuiFactory> extends ValueUpdatableGui { 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. * Constructor for a gui displaying available enchantment to edit a enchantment setting.
* @param title Title of the gui. * @param title Title of the gui.
*/ */
protected AbstractEnchantConfigGui(String title){ protected AbstractEnchantConfigGui(String title){
this(title, MainConfigGui.INSTANCE); super(6, title, CustomAnvil.instance);
} }
PatternPane backgroundItems; private OutlinePane filledEnchant;
OutlinePane filledEnchant;
// Why is called like it is rn
/** /**
* Initialise value updatable gui pattern * Initialise value updatable gui pattern
*/ */
protected void init(){ protected void init(){
// Back item panel // Back item panel
Pattern pattern = new Pattern( addPane(GuiSharedConstant.BACK_TO_MAIN_MENU_BIG_LIST_DISPLAY_BACKGROUND_PANE);
"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);
// enchant item panel // enchant item panel
this.filledEnchant = new OutlinePane(0, 0, 9, 5); this.filledEnchant = new OutlinePane(0, 0, 9, 5);

View file

@ -1,6 +1,5 @@
package xyz.alexcrea.cuanvil.gui.config; 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.GuiItem;
import com.github.stefvanschie.inventoryframework.gui.type.ChestGui; import com.github.stefvanschie.inventoryframework.gui.type.ChestGui;
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui; 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 org.jetbrains.annotations.NotNull;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
@ -39,13 +39,14 @@ public class ConfirmActionGui extends ChestGui {
CONFIRM_ITEM.setItemMeta(meta); 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); super(3, title, CustomAnvil.instance);
Pattern pattern = new Pattern( Pattern pattern = new Pattern(
"000000000", GuiSharedConstant.EMPTY_GUI_FULL_LINE,
"00B0I0S00", "00B0I0S00",
"000000000" GuiSharedConstant.EMPTY_GUI_FULL_LINE
); );
PatternPane pane = new PatternPane(0, 0, pattern.getLength(), pattern.getHeight(), pattern); PatternPane pane = new PatternPane(0, 0, pattern.getLength(), pattern.getHeight(), pattern);
addPane(pane); 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.config.settings.IntSettingsGui;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
import java.util.Collections; import java.util.Collections;
@ -44,7 +45,7 @@ public class BasicConfigGui extends ValueUpdatableGui {
*/ */
private void init(){ private void init(){
Pattern pattern = new Pattern( Pattern pattern = new Pattern(
"000000000", GuiSharedConstant.EMPTY_GUI_FULL_LINE,
"012345670", "012345670",
"B00000000" "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 // Get item properties
int itemCost = factory.getConfiguredValue(); int itemCost = factory.getConfiguredValue();
int bookCost = factory.getConfiguredBookValue(); int bookCost = factory.getConfiguredBookValue();
StringBuilder itemName = new StringBuilder("\u00A7a").append(factory.getTitle()); String itemName = "\u00A7a" + factory.getTitle();
// Create item // Create item
ItemStack item = new ItemStack(Material.ENCHANTED_BOOK); ItemStack item = new ItemStack(Material.ENCHANTED_BOOK);
ItemMeta itemMeta = item.getItemMeta(); ItemMeta itemMeta = item.getItemMeta();
// Edit name and lore // Edit name and lore
itemMeta.setDisplayName(itemName.toString()); itemMeta.setDisplayName(itemName);
itemMeta.setLore(Arrays.asList( itemMeta.setLore(Arrays.asList(
"\u00A77Item Cost: " + itemCost, "\u00A77Item Cost: " + itemCost,
"\u00A77Book Cost: " + bookCost)); "\u00A77Book Cost: " + bookCost));

View file

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

View file

@ -48,11 +48,11 @@ public class EnchantSelectSettingGui extends AbstractSettingGui{
@Override @Override
protected Pattern getGuiPattern() { protected Pattern getGuiPattern() {
return new Pattern( return new Pattern(
"000000000", GuiSharedConstant.EMPTY_GUI_FULL_LINE,
"000000000", GuiSharedConstant.EMPTY_GUI_FULL_LINE,
"000000000", GuiSharedConstant.EMPTY_GUI_FULL_LINE,
"000000000", GuiSharedConstant.EMPTY_GUI_FULL_LINE,
"000000000", GuiSharedConstant.EMPTY_GUI_FULL_LINE,
"B1111111S" "B1111111S"
); );
} }

View file

@ -47,11 +47,11 @@ public class GroupSelectSettingGui extends AbstractSettingGui{
@Override @Override
protected Pattern getGuiPattern() { protected Pattern getGuiPattern() {
return new Pattern( return new Pattern(
"000000000", GuiSharedConstant.EMPTY_GUI_FULL_LINE,
"000000000", GuiSharedConstant.EMPTY_GUI_FULL_LINE,
"000000000", GuiSharedConstant.EMPTY_GUI_FULL_LINE,
"000000000", GuiSharedConstant.EMPTY_GUI_FULL_LINE,
"000000000", GuiSharedConstant.EMPTY_GUI_FULL_LINE,
"B1111111S" "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; package xyz.alexcrea.cuanvil.gui.util;
import com.github.stefvanschie.inventoryframework.gui.GuiItem; 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.Material;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import xyz.alexcrea.cuanvil.gui.MainConfigGui;
import java.util.Arrays; import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
@ -11,6 +15,7 @@ import java.util.List;
public class GuiSharedConstant { public class GuiSharedConstant {
public static final List<Enchantment> SORTED_ENCHANTMENT_LIST; public static final List<Enchantment> SORTED_ENCHANTMENT_LIST;
static { static {
SORTED_ENCHANTMENT_LIST = Arrays.asList(Enchantment.values()); SORTED_ENCHANTMENT_LIST = Arrays.asList(Enchantment.values());
SORTED_ENCHANTMENT_LIST.sort(Comparator.comparing(ench -> ench.getKey().getKey())); 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 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 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. // 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_SAVE_TO_DISK_EVERY_CHANGE = true;
public static final boolean TEMPORARY_DO_BACKUP_EVERY_SAVE = 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);
}
} }

View file

@ -3,12 +3,18 @@ package xyz.alexcrea.cuanvil.group
import org.bukkit.Material import org.bukkit.Material
import org.bukkit.enchantments.Enchantment import org.bukkit.enchantments.Enchantment
class EnchantConflictGroup(private val cantConflict: AbstractMaterialGroup, private val minBeforeBlock: Int){ class EnchantConflictGroup(
val name: String,
private val cantConflict: AbstractMaterialGroup,
private val minBeforeBlock: Int){
private val enchantments = HashSet<Enchantment>() private val enchantments = HashSet<Enchantment>()
fun addEnchantment(ench: Enchantment){ fun addEnchantment(enchant: Enchantment){
enchantments.add(ench) enchantments.add(enchant)
}
fun removeEnchantment(enchant: Enchantment){
enchantments.remove(enchant)
} }
fun allowed(enchants: Set<Enchantment>, mat: Material) : Boolean{ fun allowed(enchants: Set<Enchantment>, mat: Material) : Boolean{
if(enchantments.size < minBeforeBlock){ if(enchantments.size < minBeforeBlock){

View file

@ -10,11 +10,11 @@ class EnchantConflictManager {
companion object { companion object {
// Path for the enchantments list // Path for the enchantments list
private const val ENCH_LIST_PATH = "enchantments" const val ENCH_LIST_PATH = "enchantments"
// Path for group list related to the conflict // Path for group list related to the conflict
private const val CONFLICT_GROUP_PATH = "notAffectedGroups" const val CONFLICT_GROUP_PATH = "notAffectedGroups"
// Path for the maximum number of enchantment before validating the conflict // Path for the maximum number of enchantment before validating the conflict
private const val ENCH_MAX_PATH = "maxEnchantmentBeforeConflict" const val ENCH_MAX_PATH = "maxEnchantmentBeforeConflict"
// Path for a flag: if the enchantment will be used in the last supported version // Path for a flag: if the enchantment will be used in the last supported version
// TODO maybe replace this system by a list of "future" enchantment. // TODO maybe replace this system by a list of "future" enchantment.
private const val FUTURE_USE_PATH = "useInFuture" private const val FUTURE_USE_PATH = "useInFuture"
@ -25,10 +25,12 @@ class EnchantConflictManager {
} }
private lateinit var conflictMap: HashMap<Enchantment, ArrayList<EnchantConflictGroup>> private lateinit var conflictMap: HashMap<Enchantment, ArrayList<EnchantConflictGroup>>
lateinit var conflictList: ArrayList<EnchantConflictGroup>
// Read and prepare all conflict // Read and prepare all conflict
fun prepareConflicts(config: ConfigurationSection, itemManager: ItemGroupManager){ fun prepareConflicts(config: ConfigurationSection, itemManager: ItemGroupManager){
conflictMap = HashMap() conflictMap = HashMap()
conflictList = ArrayList()
val keys = config.getKeys(false) val keys = config.getKeys(false)
for (key in keys) { for (key in keys) {
@ -36,6 +38,7 @@ class EnchantConflictManager {
val conflict = createConflict(section,itemManager,key) val conflict = createConflict(section,itemManager,key)
if(conflict != null){ if(conflict != null){
addToMap(conflict) addToMap(conflict)
conflictList.add(conflict)
} }
} }
@ -45,11 +48,19 @@ class EnchantConflictManager {
// Add the conflict to the map // Add the conflict to the map
private fun addToMap(conflict: EnchantConflictGroup){ private fun addToMap(conflict: EnchantConflictGroup){
conflict.getEnchants().forEach{ enchant -> conflict.getEnchants().forEach{ enchant ->
addConflictToConflictMap(enchant, conflict);
}
}
fun addConflictToConflictMap(enchant: Enchantment, conflict: EnchantConflictGroup){
if(!conflictMap.containsKey(enchant)){ if(!conflictMap.containsKey(enchant)){
conflictMap[enchant] = ArrayList() conflictMap[enchant] = ArrayList()
} }
conflictMap[enchant]!!.add(conflict) conflictMap[enchant]!!.add(conflict)
} }
fun removeConflictFromMap(enchant: Enchantment, conflict: EnchantConflictGroup): Boolean{
return conflictMap[enchant]!!.remove(conflict)
} }
// create and read a conflict from a yaml section // create and read a conflict from a yaml section
@ -107,7 +118,7 @@ class EnchantConflictManager {
} }
} }
// Return conflict // Return conflict
return EnchantConflictGroup(finalGroup, minBeforeBlock) return EnchantConflictGroup(conflictName, finalGroup, minBeforeBlock)
} }
private fun findGroup(groupName: String, itemManager: ItemGroupManager, conflictName: String): AbstractMaterialGroup { private fun findGroup(groupName: String, itemManager: ItemGroupManager, conflictName: String): AbstractMaterialGroup {