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;
|
package xyz.alexcrea.cuanvil.gui.config.global;
|
||||||
|
|
||||||
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
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 com.github.stefvanschie.inventoryframework.pane.util.Pattern;
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantment;
|
import xyz.alexcrea.cuanvil.enchant.CAEnchantment;
|
||||||
|
|
@ -30,6 +31,10 @@ public abstract class AbstractEnchantConfigGui<T extends SettingGui.SettingGuiFa
|
||||||
super(title);
|
super(title);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected AbstractEnchantConfigGui(String title, Gui parent) {
|
||||||
|
super(title, parent);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateGuiValues() { //TODO maybe optimise it.
|
public void updateGuiValues() { //TODO maybe optimise it.
|
||||||
reloadValues();
|
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.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.pane.PatternPane;
|
import com.github.stefvanschie.inventoryframework.pane.PatternPane;
|
||||||
import com.github.stefvanschie.inventoryframework.pane.util.Pattern;
|
import com.github.stefvanschie.inventoryframework.pane.util.Pattern;
|
||||||
import io.delilaheve.CustomAnvil;
|
import io.delilaheve.CustomAnvil;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.NamespacedKey;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.jetbrains.annotations.Contract;
|
import org.jetbrains.annotations.Contract;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
import xyz.alexcrea.cuanvil.api.EnchantmentApi;
|
import xyz.alexcrea.cuanvil.api.EnchantmentApi;
|
||||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantment;
|
import xyz.alexcrea.cuanvil.enchant.CAEnchantment;
|
||||||
import xyz.alexcrea.cuanvil.group.EnchantConflictGroup;
|
import xyz.alexcrea.cuanvil.group.EnchantConflictGroup;
|
||||||
|
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
||||||
import xyz.alexcrea.cuanvil.gui.config.MainConfigGui;
|
import xyz.alexcrea.cuanvil.gui.config.MainConfigGui;
|
||||||
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.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.HashMap;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class EnchantConfigGui extends ChestGui {
|
public class EnchantConfigGui extends ChestGui implements ValueUpdatableGui {
|
||||||
|
|
||||||
public EnchantLimitConfigGui enchantLimitConfigGui;
|
private final Set<CAEnchantment> enchantments;
|
||||||
public EnchantMergeLimitConfigGui enchantMergeLimitConfigGui;
|
private final PatternPane pane;
|
||||||
public EnchantCostConfigGui enchantCostConfigGui;
|
|
||||||
public EnchantConflictGui enchantConflictGui;
|
private EnchantLimitConfigGui enchantLimitConfigGui;
|
||||||
public GroupConfigGui groupConfigGui;
|
private EnchantMergeLimitConfigGui enchantMergeLimitConfigGui;
|
||||||
|
private EnchantCostConfigGui enchantCostConfigGui;
|
||||||
|
|
||||||
|
private EnchantConflictGui enchantConflictGui;
|
||||||
|
private GroupConfigGui groupConfigGui;
|
||||||
|
|
||||||
public EnchantConfigGui(@NotNull Set<CAEnchantment> enchantments) {
|
public EnchantConfigGui(@NotNull Set<CAEnchantment> enchantments) {
|
||||||
super(3,
|
super(3,
|
||||||
"Configuring Enchantments",
|
"Configuring Enchantments",
|
||||||
CustomAnvil.instance);
|
CustomAnvil.instance);
|
||||||
|
this.enchantments = enchantments;
|
||||||
|
|
||||||
Pattern pattern = new Pattern(
|
Pattern pattern = new Pattern(
|
||||||
"0000D0000",
|
"0000D0000",
|
||||||
"023405600",
|
"023405600",
|
||||||
"Q00000000"
|
"Q00000000"
|
||||||
);
|
);
|
||||||
PatternPane pane = new PatternPane(0, 0, 9, 3, pattern);
|
pane = new PatternPane(0, 0, 9, 3, pattern);
|
||||||
addPane(pane);
|
addPane(pane);
|
||||||
|
|
||||||
GuiGlobalItems.addBackgroundItem(pane);
|
GuiGlobalItems.addBackgroundItem(pane);
|
||||||
|
|
@ -71,49 +69,93 @@ public class EnchantConfigGui extends ChestGui {
|
||||||
|
|
||||||
pane.bindItem('D', new GuiItem(displayItemstack, GuiGlobalActions.stayInPlace, CustomAnvil.instance));
|
pane.bindItem('D', new GuiItem(displayItemstack, GuiGlobalActions.stayInPlace, CustomAnvil.instance));
|
||||||
|
|
||||||
// enchant level limit item
|
updateGuiValues();
|
||||||
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);
|
|
||||||
|
|
||||||
// Enchantment Conflicts item
|
// Enchantment Conflicts item
|
||||||
var enchantConflictItem = MainConfigGui.enchantConflictItem(getEnchantConflictGui(enchantments));
|
var enchantConflictItem = MainConfigGui.enchantConflictItem(getEnchantConflictGui());
|
||||||
pane.bindItem('5', enchantConflictItem);
|
pane.bindItem('5', enchantConflictItem);
|
||||||
|
|
||||||
// Group config items
|
// Group config items
|
||||||
var groupConfigItem = MainConfigGui.groupConfigItem(getGroupConfigGui(enchantments));
|
var groupConfigItem = MainConfigGui.groupConfigItem(getGroupConfigGui());
|
||||||
pane.bindItem('6', groupConfigItem);
|
pane.bindItem('6', groupConfigItem);
|
||||||
|
|
||||||
// quit item
|
// quit item
|
||||||
pane.bindItem('Q', MainConfigGui.quitItem());
|
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
|
@NotNull
|
||||||
@Contract(pure = true)
|
@Contract(pure = true)
|
||||||
private Predicate<EnchantConflictGroup> getGroupFilter(@NotNull Set<CAEnchantment> enchantments) {
|
private Predicate<EnchantConflictGroup> getGroupFilter() {
|
||||||
return group -> group.getEnchants()
|
return group -> group.getEnchants()
|
||||||
.stream()
|
.stream()
|
||||||
.anyMatch(enchantments::contains);
|
.anyMatch(enchantments::contains);
|
||||||
}
|
}
|
||||||
|
|
||||||
private EnchantConflictGui getEnchantConflictGui(@NotNull Set<CAEnchantment> enchantments) {
|
private EnchantConflictGui getEnchantConflictGui() {
|
||||||
if (enchantConflictGui == null) {
|
if (enchantConflictGui == null) {
|
||||||
enchantConflictGui = new EnchantConflictGui(this);
|
enchantConflictGui = new EnchantConflictGui(this);
|
||||||
enchantConflictGui.setFilter(getGroupFilter(enchantments));
|
enchantConflictGui.setFilter(getGroupFilter());
|
||||||
enchantConflictGui.init();
|
enchantConflictGui.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
return enchantConflictGui;
|
return enchantConflictGui;
|
||||||
}
|
}
|
||||||
|
|
||||||
private GroupConfigGui getGroupConfigGui(@NotNull Set<CAEnchantment> enchantments) {
|
private GroupConfigGui getGroupConfigGui() {
|
||||||
if (groupConfigGui == null) {
|
if (groupConfigGui == null) {
|
||||||
groupConfigGui = new GroupConfigGui(this);
|
groupConfigGui = new GroupConfigGui(this);
|
||||||
|
|
||||||
|
|
@ -122,7 +164,7 @@ public class EnchantConfigGui extends ChestGui {
|
||||||
.getConflictManager()
|
.getConflictManager()
|
||||||
.getConflictList()
|
.getConflictList()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(getGroupFilter(enchantments))
|
.filter(getGroupFilter())
|
||||||
.map(EnchantConflictGroup::getCantConflictGroup)
|
.map(EnchantConflictGroup::getCantConflictGroup)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
|
|
@ -135,4 +177,20 @@ public class EnchantConfigGui extends ChestGui {
|
||||||
return groupConfigGui;
|
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;
|
package xyz.alexcrea.cuanvil.gui.config.global;
|
||||||
|
|
||||||
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||||
|
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
|
||||||
import org.bukkit.Material;
|
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 org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantment;
|
import xyz.alexcrea.cuanvil.enchant.CAEnchantment;
|
||||||
import xyz.alexcrea.cuanvil.enchant.EnchantmentProperties;
|
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
||||||
import xyz.alexcrea.cuanvil.enchant.EnchantmentRarity;
|
|
||||||
import xyz.alexcrea.cuanvil.gui.config.settings.EnchantCostSettingsGui;
|
import xyz.alexcrea.cuanvil.gui.config.settings.EnchantCostSettingsGui;
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
||||||
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
||||||
|
|
@ -18,13 +18,13 @@ import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import static io.delilaheve.util.ConfigOptions.ENCHANT_VALUES_ROOT;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Global Config gui for enchantment cost settings.
|
* Global Config gui for enchantment cost settings.
|
||||||
*/
|
*/
|
||||||
public class EnchantCostConfigGui extends AbstractEnchantConfigGui<EnchantCostSettingsGui.EnchantCostSettingFactory> {
|
public class EnchantCostConfigGui extends AbstractEnchantConfigGui<EnchantCostSettingsGui.EnchantCostSettingFactory> {
|
||||||
|
|
||||||
private static final String SECTION_NAME = "enchant_values";
|
|
||||||
|
|
||||||
private static EnchantCostConfigGui INSTANCE = null;
|
private static EnchantCostConfigGui INSTANCE = null;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|
@ -37,18 +37,29 @@ public class EnchantCostConfigGui extends AbstractEnchantConfigGui<EnchantCostSe
|
||||||
*/
|
*/
|
||||||
public EnchantCostConfigGui() {
|
public EnchantCostConfigGui() {
|
||||||
super("§8Enchantment Level Cost");
|
super("§8Enchantment Level Cost");
|
||||||
if(INSTANCE == null) INSTANCE = this;
|
if (INSTANCE == null) INSTANCE = this;
|
||||||
|
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor of this Global gui for enchantment cost settings.
|
||||||
|
*/
|
||||||
|
public EnchantCostConfigGui(Gui parent) {
|
||||||
|
super("§8Enchantment Level Cost", parent);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EnchantCostSettingsGui.EnchantCostSettingFactory createFactory(CAEnchantment enchant) {
|
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 key = enchant.getKey().toString().toLowerCase(Locale.ENGLISH);
|
||||||
String prettyKey = CasedStringUtil.snakeToUpperSpacedCase(key.replace(":", "_"));
|
String prettyKey = CasedStringUtil.snakeToUpperSpacedCase(key.replace(":", "_"));
|
||||||
|
|
||||||
return new EnchantCostSettingsGui.EnchantCostSettingFactory(prettyKey + " Cost", this,
|
return new EnchantCostSettingsGui.EnchantCostSettingFactory(prettyKey + " Cost", parent,
|
||||||
SECTION_NAME + '.' + key, ConfigHolder.DEFAULT_CONFIG,
|
ENCHANT_VALUES_ROOT + '.' + key, ConfigHolder.DEFAULT_CONFIG,
|
||||||
Arrays.asList(
|
Arrays.asList(
|
||||||
"§7How many level should " + prettyKey,
|
"§7How many level should " + prettyKey,
|
||||||
"§7cost when applied by book or by another item."
|
"§7cost when applied by book or by another item."
|
||||||
|
|
@ -74,7 +85,7 @@ public class EnchantCostConfigGui extends AbstractEnchantConfigGui<EnchantCostSe
|
||||||
lore.add("§7Book Cost: §e" + bookCost);
|
lore.add("§7Book Cost: §e" + bookCost);
|
||||||
|
|
||||||
List<String> displayLore = factory.getDisplayLore();
|
List<String> displayLore = factory.getDisplayLore();
|
||||||
if(!displayLore.isEmpty()){
|
if (!displayLore.isEmpty()) {
|
||||||
lore.add("");
|
lore.add("");
|
||||||
lore.addAll(displayLore);
|
lore.addAll(displayLore);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,13 @@
|
||||||
package xyz.alexcrea.cuanvil.gui.config.global;
|
package xyz.alexcrea.cuanvil.gui.config.global;
|
||||||
|
|
||||||
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||||
|
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
|
||||||
import io.delilaheve.util.ConfigOptions;
|
import io.delilaheve.util.ConfigOptions;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantment;
|
import xyz.alexcrea.cuanvil.enchant.CAEnchantment;
|
||||||
|
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
||||||
import xyz.alexcrea.cuanvil.gui.config.settings.IntSettingsGui;
|
import xyz.alexcrea.cuanvil.gui.config.settings.IntSettingsGui;
|
||||||
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
||||||
|
|
||||||
|
|
@ -36,14 +38,22 @@ public class EnchantLimitConfigGui extends AbstractEnchantConfigGui<IntSettingsG
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public EnchantLimitConfigGui(Gui parent) {
|
||||||
|
super("§8Enchantment Level Limit", parent);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IntSettingsGui.IntSettingFactory createFactory(CAEnchantment enchant) {
|
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 key = enchant.getKey().toString().toLowerCase(Locale.ROOT);
|
||||||
String prettyKey = CasedStringUtil.snakeToUpperSpacedCase(key.replace(":", "_"));
|
String prettyKey = CasedStringUtil.snakeToUpperSpacedCase(key.replace(":", "_"));
|
||||||
|
|
||||||
var defaultValue = enchant.defaultMaxLevel();
|
var defaultValue = enchant.defaultMaxLevel();
|
||||||
|
|
||||||
return new IntSettingsGui.IntSettingFactory(prettyKey + " Limit", this,
|
return new IntSettingsGui.IntSettingFactory(prettyKey + " Limit", parent,
|
||||||
SECTION_NAME + '.' + key, ConfigHolder.DEFAULT_CONFIG,
|
SECTION_NAME + '.' + key, ConfigHolder.DEFAULT_CONFIG,
|
||||||
Collections.singletonList(
|
Collections.singletonList(
|
||||||
"§7Maximum applied level of " + prettyKey
|
"§7Maximum applied level of " + prettyKey
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,13 @@
|
||||||
package xyz.alexcrea.cuanvil.gui.config.global;
|
package xyz.alexcrea.cuanvil.gui.config.global;
|
||||||
|
|
||||||
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||||
|
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
|
||||||
import io.delilaheve.util.ConfigOptions;
|
import io.delilaheve.util.ConfigOptions;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantment;
|
import xyz.alexcrea.cuanvil.enchant.CAEnchantment;
|
||||||
|
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
||||||
import xyz.alexcrea.cuanvil.gui.config.settings.IntSettingsGui;
|
import xyz.alexcrea.cuanvil.gui.config.settings.IntSettingsGui;
|
||||||
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
||||||
|
|
||||||
|
|
@ -33,12 +35,24 @@ public class EnchantMergeLimitConfigGui extends AbstractEnchantConfigGui<IntSett
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor of this Global gui for enchantment level limit settings.
|
||||||
|
*/
|
||||||
|
public EnchantMergeLimitConfigGui(Gui parent) {
|
||||||
|
super("§8Enchantment Maximum Merge Level", parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IntSettingsGui.IntSettingFactory createFactory(CAEnchantment enchant) {
|
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 key = enchant.getKey().toString().toLowerCase(Locale.ROOT);
|
||||||
String prettyKey = CasedStringUtil.snakeToUpperSpacedCase(key.replace(":", "_"));
|
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,
|
SECTION_NAME + '.' + key, ConfigHolder.DEFAULT_CONFIG,
|
||||||
Arrays.asList(
|
Arrays.asList(
|
||||||
"§7Maximum merge level for for " + prettyKey,
|
"§7Maximum merge level for for " + prettyKey,
|
||||||
|
|
|
||||||
|
|
@ -21,10 +21,10 @@ import xyz.alexcrea.cuanvil.util.UnitRepairUtil;
|
||||||
|
|
||||||
public class ItemConfigGui extends ChestGui {
|
public class ItemConfigGui extends ChestGui {
|
||||||
|
|
||||||
public EnchantConflictGui enchantConflictGui;
|
private EnchantConflictGui enchantConflictGui;
|
||||||
public GroupConfigGui groupConfigGui;
|
private GroupConfigGui groupConfigGui;
|
||||||
public UnitRepairConfigGui unitRepairConfigGui;
|
private UnitRepairConfigGui unitRepairConfigGui;
|
||||||
public CustomRecipeConfigGui customRecipeConfigGui;
|
private CustomRecipeConfigGui customRecipeConfigGui;
|
||||||
|
|
||||||
public ItemConfigGui(@NotNull Material display, @NotNull NamespacedKey material) {
|
public ItemConfigGui(@NotNull Material display, @NotNull NamespacedKey material) {
|
||||||
super(3,
|
super(3,
|
||||||
|
|
|
||||||
|
|
@ -15,10 +15,11 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public abstract class SettingGuiListConfigGui< T, S extends SettingGui.SettingGuiFactory> extends ElementListConfigGui< T >{
|
public abstract class SettingGuiListConfigGui<T, S extends SettingGui.SettingGuiFactory> extends ElementListConfigGui<T> {
|
||||||
|
|
||||||
protected HashMap<T, GuiItem> guiItemMap;
|
protected HashMap<T, GuiItem> guiItemMap;
|
||||||
protected HashMap<T, S> factoryMap;
|
protected HashMap<T, S> factoryMap;
|
||||||
|
|
||||||
protected SettingGuiListConfigGui(@NotNull String title, Gui parent) {
|
protected SettingGuiListConfigGui(@NotNull String title, Gui parent) {
|
||||||
super(title, parent);
|
super(title, parent);
|
||||||
this.guiItemMap = new HashMap<>();
|
this.guiItemMap = new HashMap<>();
|
||||||
|
|
@ -44,7 +45,7 @@ public abstract class SettingGuiListConfigGui< T, S extends SettingGui.SettingGu
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateValueForGeneric(T generic, boolean shouldUpdate) {
|
public void updateValueForGeneric(T generic, boolean shouldUpdate) {
|
||||||
if(!this.factoryMap.containsKey(generic)){
|
if (!this.factoryMap.containsKey(generic)) {
|
||||||
// Create new item & factory
|
// Create new item & factory
|
||||||
S factory = createFactory(generic);
|
S factory = createFactory(generic);
|
||||||
GuiItem newItem = itemFromFactory(generic, factory);
|
GuiItem newItem = itemFromFactory(generic, factory);
|
||||||
|
|
@ -52,7 +53,7 @@ public abstract class SettingGuiListConfigGui< T, S extends SettingGui.SettingGu
|
||||||
addToPage(newItem);
|
addToPage(newItem);
|
||||||
this.guiItemMap.put(generic, newItem);
|
this.guiItemMap.put(generic, newItem);
|
||||||
this.factoryMap.put(generic, factory);
|
this.factoryMap.put(generic, factory);
|
||||||
}else{
|
} else {
|
||||||
S factory = this.factoryMap.get(generic);
|
S factory = this.factoryMap.get(generic);
|
||||||
// Update old item
|
// Update old item
|
||||||
GuiItem oldItem = this.guiItemMap.get(generic);
|
GuiItem oldItem = this.guiItemMap.get(generic);
|
||||||
|
|
@ -61,7 +62,7 @@ public abstract class SettingGuiListConfigGui< T, S extends SettingGui.SettingGu
|
||||||
updateGuiItem(oldItem, newItem);
|
updateGuiItem(oldItem, newItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(shouldUpdate){
|
if (shouldUpdate) {
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -74,7 +75,7 @@ public abstract class SettingGuiListConfigGui< T, S extends SettingGui.SettingGu
|
||||||
super.reloadValues();
|
super.reloadValues();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateGuiItem(GuiItem oldITem, GuiItem newItem){
|
private void updateGuiItem(GuiItem oldITem, GuiItem newItem) {
|
||||||
oldITem.setItem(newItem.getItem());
|
oldITem.setItem(newItem.getItem());
|
||||||
oldITem.setProperties(newItem.getProperties());
|
oldITem.setProperties(newItem.getProperties());
|
||||||
oldITem.setVisible(newItem.isVisible());
|
oldITem.setVisible(newItem.isVisible());
|
||||||
|
|
@ -86,17 +87,22 @@ public abstract class SettingGuiListConfigGui< T, S extends SettingGui.SettingGu
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override // Not used
|
@Override // Not used
|
||||||
protected void updateGeneric(T generic, ItemStack usedItem) {}
|
protected void updateGeneric(T generic, ItemStack usedItem) {
|
||||||
|
}
|
||||||
|
|
||||||
@Override // Not used
|
@Override // Not used
|
||||||
protected ItemStack createItemForGeneric(T generic) {
|
protected ItemStack createItemForGeneric(T generic) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract List<String> getCreateItemLore();
|
protected abstract List<String> getCreateItemLore();
|
||||||
|
|
||||||
protected abstract Consumer<InventoryClickEvent> getCreateClickConsumer();
|
protected abstract Consumer<InventoryClickEvent> getCreateClickConsumer();
|
||||||
|
|
||||||
protected abstract String createItemName();
|
protected abstract String createItemName();
|
||||||
|
|
||||||
protected abstract S createFactory(T generic);
|
protected abstract S createFactory(T generic);
|
||||||
|
|
||||||
protected abstract GuiItem itemFromFactory(T generic, S factory);
|
protected abstract GuiItem itemFromFactory(T generic, S factory);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -183,7 +183,7 @@ public class EnchantCostSettingsGui extends IntSettingsGui {
|
||||||
assert nowMeta != null;
|
assert nowMeta != null;
|
||||||
|
|
||||||
nowMeta.setDisplayName("§fValue: §e" + nowBook);
|
nowMeta.setDisplayName("§fValue: §e" + nowBook);
|
||||||
if(!holder.displayLore.isEmpty()){
|
if (!holder.displayLore.isEmpty()) {
|
||||||
nowMeta.setLore(holder.displayLore);
|
nowMeta.setLore(holder.displayLore);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -202,7 +202,6 @@ public class EnchantCostSettingsGui extends IntSettingsGui {
|
||||||
}
|
}
|
||||||
pane.bindItem('D', returnToDefault);
|
pane.bindItem('D', returnToDefault);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -318,9 +318,9 @@ public class IntSettingsGui extends AbstractSettingGui {
|
||||||
this.defaultVal = defaultVal;
|
this.defaultVal = defaultVal;
|
||||||
this.steps = steps;
|
this.steps = steps;
|
||||||
|
|
||||||
if(displayLore == null){
|
if (displayLore == null) {
|
||||||
this.displayLore = Collections.emptyList();
|
this.displayLore = Collections.emptyList();
|
||||||
}else {
|
} else {
|
||||||
this.displayLore = displayLore;
|
this.displayLore = displayLore;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -392,7 +392,7 @@ public class IntSettingsGui extends AbstractSettingGui {
|
||||||
|
|
||||||
protected String deltaDisplay(ValueDisplayType type, int now, int planned) {
|
protected String deltaDisplay(ValueDisplayType type, int now, int planned) {
|
||||||
var delta = planned - now;
|
var delta = planned - now;
|
||||||
if(delta < 0) return "§c" + delta;
|
if (delta < 0) return "§c" + delta;
|
||||||
else return "§a+" + delta;
|
else return "§a+" + delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue