mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-08-28 08:25:56 +02:00
per enchant config finished
This commit is contained in:
parent
341dd10e3f
commit
b2561f55ae
9 changed files with 162 additions and 59 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package xyz.alexcrea.cuanvil.gui.config.global;
|
||||
|
||||
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 org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantment;
|
||||
|
|
@ -30,6 +31,10 @@ public abstract class AbstractEnchantConfigGui<T extends SettingGui.SettingGuiFa
|
|||
super(title);
|
||||
}
|
||||
|
||||
protected AbstractEnchantConfigGui(String title, Gui parent) {
|
||||
super(title, parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateGuiValues() { //TODO maybe optimise it.
|
||||
reloadValues();
|
||||
|
|
|
|||
|
|
@ -2,55 +2,53 @@ package xyz.alexcrea.cuanvil.gui.config.global;
|
|||
|
||||
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.PatternPane;
|
||||
import com.github.stefvanschie.inventoryframework.pane.util.Pattern;
|
||||
import io.delilaheve.CustomAnvil;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import xyz.alexcrea.cuanvil.api.EnchantmentApi;
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantment;
|
||||
import xyz.alexcrea.cuanvil.group.EnchantConflictGroup;
|
||||
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.MainConfigGui;
|
||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
|
||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
||||
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
||||
import xyz.alexcrea.cuanvil.util.MaterialUtil;
|
||||
import xyz.alexcrea.cuanvil.util.UnitRepairUtil;
|
||||
|
||||
import java.lang.ref.PhantomReference;
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class EnchantConfigGui extends ChestGui {
|
||||
public class EnchantConfigGui extends ChestGui implements ValueUpdatableGui {
|
||||
|
||||
public EnchantLimitConfigGui enchantLimitConfigGui;
|
||||
public EnchantMergeLimitConfigGui enchantMergeLimitConfigGui;
|
||||
public EnchantCostConfigGui enchantCostConfigGui;
|
||||
public EnchantConflictGui enchantConflictGui;
|
||||
public GroupConfigGui groupConfigGui;
|
||||
private final Set<CAEnchantment> enchantments;
|
||||
private final PatternPane pane;
|
||||
|
||||
private EnchantLimitConfigGui enchantLimitConfigGui;
|
||||
private EnchantMergeLimitConfigGui enchantMergeLimitConfigGui;
|
||||
private EnchantCostConfigGui enchantCostConfigGui;
|
||||
|
||||
private EnchantConflictGui enchantConflictGui;
|
||||
private GroupConfigGui groupConfigGui;
|
||||
|
||||
public EnchantConfigGui(@NotNull Set<CAEnchantment> enchantments) {
|
||||
super(3,
|
||||
"Configuring Enchantments",
|
||||
CustomAnvil.instance);
|
||||
this.enchantments = enchantments;
|
||||
|
||||
Pattern pattern = new Pattern(
|
||||
"0000D0000",
|
||||
"023405600",
|
||||
"Q00000000"
|
||||
);
|
||||
PatternPane pane = new PatternPane(0, 0, 9, 3, pattern);
|
||||
pane = new PatternPane(0, 0, 9, 3, pattern);
|
||||
addPane(pane);
|
||||
|
||||
GuiGlobalItems.addBackgroundItem(pane);
|
||||
|
|
@ -71,49 +69,93 @@ public class EnchantConfigGui extends ChestGui {
|
|||
|
||||
pane.bindItem('D', new GuiItem(displayItemstack, GuiGlobalActions.stayInPlace, CustomAnvil.instance));
|
||||
|
||||
// enchant level limit item
|
||||
var enchantLimitItem = MainConfigGui.enchantLimitItem(new EnchantLimitConfigGui()); //TODO
|
||||
pane.bindItem('2', enchantLimitItem);
|
||||
|
||||
// enchant level limit item
|
||||
var enchantMergeLimitItem = MainConfigGui.enchantMergeLimitItem(new EnchantMergeLimitConfigGui()); //TODO
|
||||
pane.bindItem('3', enchantMergeLimitItem);
|
||||
|
||||
// enchant cost item
|
||||
var enchantCostItem = MainConfigGui.enchantCostItem(new EnchantCostConfigGui()); //TODO
|
||||
pane.bindItem('4', enchantCostItem);
|
||||
updateGuiValues();
|
||||
|
||||
// Enchantment Conflicts item
|
||||
var enchantConflictItem = MainConfigGui.enchantConflictItem(getEnchantConflictGui(enchantments));
|
||||
var enchantConflictItem = MainConfigGui.enchantConflictItem(getEnchantConflictGui());
|
||||
pane.bindItem('5', enchantConflictItem);
|
||||
|
||||
// Group config items
|
||||
var groupConfigItem = MainConfigGui.groupConfigItem(getGroupConfigGui(enchantments));
|
||||
var groupConfigItem = MainConfigGui.groupConfigItem(getGroupConfigGui());
|
||||
pane.bindItem('6', groupConfigItem);
|
||||
|
||||
// quit item
|
||||
pane.bindItem('Q', MainConfigGui.quitItem());
|
||||
}
|
||||
|
||||
private GuiItem enchantLimitConfigGui() {
|
||||
if (enchantLimitConfigGui == null) {
|
||||
enchantLimitConfigGui = new EnchantLimitConfigGui(this);
|
||||
enchantLimitConfigGui.setFilter(enchantments::contains);
|
||||
enchantLimitConfigGui.init();
|
||||
}
|
||||
|
||||
// Bypass
|
||||
if(enchantments.size() == 1) {
|
||||
var enchant = enchantments.iterator().next();
|
||||
var factory = EnchantLimitConfigGui.createFactory(enchant, this);
|
||||
|
||||
return enchantLimitConfigGui.itemFromFactory(enchant, factory);
|
||||
}
|
||||
|
||||
return MainConfigGui.enchantLimitItem(enchantLimitConfigGui);
|
||||
}
|
||||
|
||||
private GuiItem enchantMergeLimitConfigGui() {
|
||||
if (enchantMergeLimitConfigGui == null) {
|
||||
enchantMergeLimitConfigGui = new EnchantMergeLimitConfigGui(this);
|
||||
enchantMergeLimitConfigGui.setFilter(enchantments::contains);
|
||||
enchantMergeLimitConfigGui.init();
|
||||
}
|
||||
|
||||
// Bypass
|
||||
if(enchantments.size() == 1) {
|
||||
var enchant = enchantments.iterator().next();
|
||||
var factory = EnchantMergeLimitConfigGui.createFactory(enchant, this);
|
||||
|
||||
return enchantMergeLimitConfigGui.itemFromFactory(enchant, factory);
|
||||
}
|
||||
|
||||
return MainConfigGui.enchantMergeLimitItem(enchantMergeLimitConfigGui);
|
||||
}
|
||||
|
||||
private GuiItem enchantCostConfigGui() {
|
||||
if (enchantCostConfigGui == null) {
|
||||
enchantCostConfigGui = new EnchantCostConfigGui(this);
|
||||
enchantCostConfigGui.setFilter(enchantments::contains);
|
||||
enchantCostConfigGui.init();
|
||||
}
|
||||
|
||||
// Bypass
|
||||
if(enchantments.size() == 1) {
|
||||
var enchant = enchantments.iterator().next();
|
||||
var factory = EnchantCostConfigGui.createFactory(enchant, this);
|
||||
|
||||
return enchantCostConfigGui.itemFromFactory(enchant, factory);
|
||||
}
|
||||
|
||||
return MainConfigGui.enchantCostItem(enchantCostConfigGui);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Contract(pure = true)
|
||||
private Predicate<EnchantConflictGroup> getGroupFilter(@NotNull Set<CAEnchantment> enchantments) {
|
||||
private Predicate<EnchantConflictGroup> getGroupFilter() {
|
||||
return group -> group.getEnchants()
|
||||
.stream()
|
||||
.anyMatch(enchantments::contains);
|
||||
}
|
||||
|
||||
private EnchantConflictGui getEnchantConflictGui(@NotNull Set<CAEnchantment> enchantments) {
|
||||
private EnchantConflictGui getEnchantConflictGui() {
|
||||
if (enchantConflictGui == null) {
|
||||
enchantConflictGui = new EnchantConflictGui(this);
|
||||
enchantConflictGui.setFilter(getGroupFilter(enchantments));
|
||||
enchantConflictGui.setFilter(getGroupFilter());
|
||||
enchantConflictGui.init();
|
||||
}
|
||||
|
||||
return enchantConflictGui;
|
||||
}
|
||||
|
||||
private GroupConfigGui getGroupConfigGui(@NotNull Set<CAEnchantment> enchantments) {
|
||||
private GroupConfigGui getGroupConfigGui() {
|
||||
if (groupConfigGui == null) {
|
||||
groupConfigGui = new GroupConfigGui(this);
|
||||
|
||||
|
|
@ -122,7 +164,7 @@ public class EnchantConfigGui extends ChestGui {
|
|||
.getConflictManager()
|
||||
.getConflictList()
|
||||
.stream()
|
||||
.filter(getGroupFilter(enchantments))
|
||||
.filter(getGroupFilter())
|
||||
.map(EnchantConflictGroup::getCantConflictGroup)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
|
|
@ -135,4 +177,20 @@ public class EnchantConfigGui extends ChestGui {
|
|||
return groupConfigGui;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateGuiValues() {
|
||||
// enchant level limit item
|
||||
pane.bindItem('2', enchantLimitConfigGui());
|
||||
|
||||
// enchant level limit item
|
||||
pane.bindItem('3', enchantMergeLimitConfigGui());
|
||||
|
||||
// enchant cost item
|
||||
pane.bindItem('4', enchantCostConfigGui());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Gui getConnectedGui() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
package xyz.alexcrea.cuanvil.gui.config.global;
|
||||
|
||||
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantment;
|
||||
import xyz.alexcrea.cuanvil.enchant.EnchantmentProperties;
|
||||
import xyz.alexcrea.cuanvil.enchant.EnchantmentRarity;
|
||||
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.settings.EnchantCostSettingsGui;
|
||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
||||
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
||||
|
|
@ -18,13 +18,13 @@ import java.util.Arrays;
|
|||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import static io.delilaheve.util.ConfigOptions.ENCHANT_VALUES_ROOT;
|
||||
|
||||
/**
|
||||
* Global Config gui for enchantment cost settings.
|
||||
*/
|
||||
public class EnchantCostConfigGui extends AbstractEnchantConfigGui<EnchantCostSettingsGui.EnchantCostSettingFactory> {
|
||||
|
||||
private static final String SECTION_NAME = "enchant_values";
|
||||
|
||||
private static EnchantCostConfigGui INSTANCE = null;
|
||||
|
||||
@Nullable
|
||||
|
|
@ -42,13 +42,24 @@ public class EnchantCostConfigGui extends AbstractEnchantConfigGui<EnchantCostSe
|
|||
init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor of this Global gui for enchantment cost settings.
|
||||
*/
|
||||
public EnchantCostConfigGui(Gui parent) {
|
||||
super("§8Enchantment Level Cost", parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnchantCostSettingsGui.EnchantCostSettingFactory createFactory(CAEnchantment enchant) {
|
||||
return createFactory(enchant, this);
|
||||
}
|
||||
|
||||
public static EnchantCostSettingsGui.EnchantCostSettingFactory createFactory(CAEnchantment enchant, ValueUpdatableGui parent) {
|
||||
String key = enchant.getKey().toString().toLowerCase(Locale.ENGLISH);
|
||||
String prettyKey = CasedStringUtil.snakeToUpperSpacedCase(key.replace(":", "_"));
|
||||
|
||||
return new EnchantCostSettingsGui.EnchantCostSettingFactory(prettyKey + " Cost", this,
|
||||
SECTION_NAME + '.' + key, ConfigHolder.DEFAULT_CONFIG,
|
||||
return new EnchantCostSettingsGui.EnchantCostSettingFactory(prettyKey + " Cost", parent,
|
||||
ENCHANT_VALUES_ROOT + '.' + key, ConfigHolder.DEFAULT_CONFIG,
|
||||
Arrays.asList(
|
||||
"§7How many level should " + prettyKey,
|
||||
"§7cost when applied by book or by another item."
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
package xyz.alexcrea.cuanvil.gui.config.global;
|
||||
|
||||
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
|
||||
import io.delilaheve.util.ConfigOptions;
|
||||
import org.bukkit.Material;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantment;
|
||||
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.settings.IntSettingsGui;
|
||||
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
||||
|
||||
|
|
@ -36,14 +38,22 @@ public class EnchantLimitConfigGui extends AbstractEnchantConfigGui<IntSettingsG
|
|||
init();
|
||||
}
|
||||
|
||||
public EnchantLimitConfigGui(Gui parent) {
|
||||
super("§8Enchantment Level Limit", parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntSettingsGui.IntSettingFactory createFactory(CAEnchantment enchant) {
|
||||
return createFactory(enchant, this);
|
||||
}
|
||||
|
||||
public static IntSettingsGui.IntSettingFactory createFactory(CAEnchantment enchant, ValueUpdatableGui parent) {
|
||||
String key = enchant.getKey().toString().toLowerCase(Locale.ROOT);
|
||||
String prettyKey = CasedStringUtil.snakeToUpperSpacedCase(key.replace(":", "_"));
|
||||
|
||||
var defaultValue = enchant.defaultMaxLevel();
|
||||
|
||||
return new IntSettingsGui.IntSettingFactory(prettyKey + " Limit", this,
|
||||
return new IntSettingsGui.IntSettingFactory(prettyKey + " Limit", parent,
|
||||
SECTION_NAME + '.' + key, ConfigHolder.DEFAULT_CONFIG,
|
||||
Collections.singletonList(
|
||||
"§7Maximum applied level of " + prettyKey
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
package xyz.alexcrea.cuanvil.gui.config.global;
|
||||
|
||||
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
|
||||
import io.delilaheve.util.ConfigOptions;
|
||||
import org.bukkit.Material;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantment;
|
||||
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.settings.IntSettingsGui;
|
||||
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
||||
|
||||
|
|
@ -33,12 +35,24 @@ public class EnchantMergeLimitConfigGui extends AbstractEnchantConfigGui<IntSett
|
|||
init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor of this Global gui for enchantment level limit settings.
|
||||
*/
|
||||
public EnchantMergeLimitConfigGui(Gui parent) {
|
||||
super("§8Enchantment Maximum Merge Level", parent);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IntSettingsGui.IntSettingFactory createFactory(CAEnchantment enchant) {
|
||||
return createFactory(enchant, this);
|
||||
}
|
||||
|
||||
public static IntSettingsGui.IntSettingFactory createFactory(CAEnchantment enchant, ValueUpdatableGui parent) {
|
||||
String key = enchant.getKey().toString().toLowerCase(Locale.ROOT);
|
||||
String prettyKey = CasedStringUtil.snakeToUpperSpacedCase(key.replace(":", "_"));
|
||||
|
||||
return new IntSettingsGui.IntSettingFactory(prettyKey + " Merge Limit", this,
|
||||
return new IntSettingsGui.IntSettingFactory(prettyKey + " Merge Limit", parent,
|
||||
SECTION_NAME + '.' + key, ConfigHolder.DEFAULT_CONFIG,
|
||||
Arrays.asList(
|
||||
"§7Maximum merge level for for " + prettyKey,
|
||||
|
|
|
|||
|
|
@ -21,10 +21,10 @@ import xyz.alexcrea.cuanvil.util.UnitRepairUtil;
|
|||
|
||||
public class ItemConfigGui extends ChestGui {
|
||||
|
||||
public EnchantConflictGui enchantConflictGui;
|
||||
public GroupConfigGui groupConfigGui;
|
||||
public UnitRepairConfigGui unitRepairConfigGui;
|
||||
public CustomRecipeConfigGui customRecipeConfigGui;
|
||||
private EnchantConflictGui enchantConflictGui;
|
||||
private GroupConfigGui groupConfigGui;
|
||||
private UnitRepairConfigGui unitRepairConfigGui;
|
||||
private CustomRecipeConfigGui customRecipeConfigGui;
|
||||
|
||||
public ItemConfigGui(@NotNull Material display, @NotNull NamespacedKey material) {
|
||||
super(3,
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ public abstract class SettingGuiListConfigGui< T, S extends SettingGui.SettingGu
|
|||
|
||||
protected HashMap<T, GuiItem> guiItemMap;
|
||||
protected HashMap<T, S> factoryMap;
|
||||
|
||||
protected SettingGuiListConfigGui(@NotNull String title, Gui parent) {
|
||||
super(title, parent);
|
||||
this.guiItemMap = new HashMap<>();
|
||||
|
|
@ -86,17 +87,22 @@ public abstract class SettingGuiListConfigGui< T, S extends SettingGui.SettingGu
|
|||
}
|
||||
|
||||
@Override // Not used
|
||||
protected void updateGeneric(T generic, ItemStack usedItem) {}
|
||||
protected void updateGeneric(T generic, ItemStack usedItem) {
|
||||
}
|
||||
|
||||
@Override // Not used
|
||||
protected ItemStack createItemForGeneric(T generic) {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected abstract List<String> getCreateItemLore();
|
||||
|
||||
protected abstract Consumer<InventoryClickEvent> getCreateClickConsumer();
|
||||
|
||||
protected abstract String createItemName();
|
||||
|
||||
protected abstract S createFactory(T generic);
|
||||
|
||||
protected abstract GuiItem itemFromFactory(T generic, S factory);
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -202,7 +202,6 @@ public class EnchantCostSettingsGui extends IntSettingsGui {
|
|||
}
|
||||
pane.bindItem('D', returnToDefault);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue