mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-08-28 08:25:56 +02:00
start of enchant config gui
This commit is contained in:
parent
a9af606ae9
commit
341dd10e3f
4 changed files with 154 additions and 2 deletions
|
|
@ -9,6 +9,7 @@ import org.jetbrains.annotations.Nullable;
|
|||
import xyz.alexcrea.cuanvil.enchant.bulk.BulkCleanEnchantOperation;
|
||||
import xyz.alexcrea.cuanvil.enchant.bulk.BulkGetEnchantOperation;
|
||||
import xyz.alexcrea.cuanvil.group.EnchantConflictGroup;
|
||||
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
|
|
@ -45,6 +46,14 @@ public interface CAEnchantment {
|
|||
@NotNull
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Get the enchantment name prettified (upper spaced case)
|
||||
* @return Prettier enchantment name
|
||||
*/
|
||||
default String getPrettyName() {
|
||||
return CasedStringUtil.snakeToUpperSpacedCase(getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default maximum level of this enchantment.
|
||||
* @return The default maximum level of this enchantment.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,138 @@
|
|||
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.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.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 EnchantLimitConfigGui enchantLimitConfigGui;
|
||||
public EnchantMergeLimitConfigGui enchantMergeLimitConfigGui;
|
||||
public EnchantCostConfigGui enchantCostConfigGui;
|
||||
public EnchantConflictGui enchantConflictGui;
|
||||
public GroupConfigGui groupConfigGui;
|
||||
|
||||
public EnchantConfigGui(@NotNull Set<CAEnchantment> enchantments) {
|
||||
super(3,
|
||||
"Configuring Enchantments",
|
||||
CustomAnvil.instance);
|
||||
|
||||
Pattern pattern = new Pattern(
|
||||
"0000D0000",
|
||||
"023405600",
|
||||
"Q00000000"
|
||||
);
|
||||
PatternPane pane = new PatternPane(0, 0, 9, 3, pattern);
|
||||
addPane(pane);
|
||||
|
||||
GuiGlobalItems.addBackgroundItem(pane);
|
||||
|
||||
ItemStack displayItemstack = new ItemStack(Material.ENCHANTED_BOOK);
|
||||
ItemMeta displayMeta = displayItemstack.getItemMeta();
|
||||
assert displayMeta != null;
|
||||
|
||||
displayMeta.setDisplayName("§aConfiguring Enchantments:");
|
||||
displayItemstack.setItemMeta(displayMeta);
|
||||
|
||||
// Set enchantments
|
||||
HashMap<CAEnchantment, Integer> enchantmentMap = new HashMap<>();
|
||||
for (CAEnchantment enchantment : enchantments) {
|
||||
enchantmentMap.put(enchantment, 1);
|
||||
}
|
||||
EnchantmentApi.setEnchantments(displayItemstack, enchantmentMap);
|
||||
|
||||
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);
|
||||
|
||||
// Enchantment Conflicts item
|
||||
var enchantConflictItem = MainConfigGui.enchantConflictItem(getEnchantConflictGui(enchantments));
|
||||
pane.bindItem('5', enchantConflictItem);
|
||||
|
||||
// Group config items
|
||||
var groupConfigItem = MainConfigGui.groupConfigItem(getGroupConfigGui(enchantments));
|
||||
pane.bindItem('6', groupConfigItem);
|
||||
|
||||
// quit item
|
||||
pane.bindItem('Q', MainConfigGui.quitItem());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Contract(pure = true)
|
||||
private Predicate<EnchantConflictGroup> getGroupFilter(@NotNull Set<CAEnchantment> enchantments) {
|
||||
return group -> group.getEnchants()
|
||||
.stream()
|
||||
.anyMatch(enchantments::contains);
|
||||
}
|
||||
|
||||
private EnchantConflictGui getEnchantConflictGui(@NotNull Set<CAEnchantment> enchantments) {
|
||||
if (enchantConflictGui == null) {
|
||||
enchantConflictGui = new EnchantConflictGui(this);
|
||||
enchantConflictGui.setFilter(getGroupFilter(enchantments));
|
||||
enchantConflictGui.init();
|
||||
}
|
||||
|
||||
return enchantConflictGui;
|
||||
}
|
||||
|
||||
private GroupConfigGui getGroupConfigGui(@NotNull Set<CAEnchantment> enchantments) {
|
||||
if (groupConfigGui == null) {
|
||||
groupConfigGui = new GroupConfigGui(this);
|
||||
|
||||
// Get all the conflict related to this enchantment
|
||||
var groups = ConfigHolder.CONFLICT_HOLDER
|
||||
.getConflictManager()
|
||||
.getConflictList()
|
||||
.stream()
|
||||
.filter(getGroupFilter(enchantments))
|
||||
.map(EnchantConflictGroup::getCantConflictGroup)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
groupConfigGui.setFilter(group ->
|
||||
groups.stream().anyMatch(other -> other.isReferencing(group))
|
||||
);
|
||||
groupConfigGui.init();
|
||||
}
|
||||
|
||||
return groupConfigGui;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -27,7 +27,11 @@ public class ItemConfigGui extends ChestGui {
|
|||
public CustomRecipeConfigGui customRecipeConfigGui;
|
||||
|
||||
public ItemConfigGui(@NotNull Material display, @NotNull NamespacedKey material) {
|
||||
super(3, CasedStringUtil.snakeToUpperSpacedCase(material.getKey().toLowerCase()) + " Config", CustomAnvil.instance);
|
||||
super(3,
|
||||
CasedStringUtil.snakeToUpperSpacedCase(
|
||||
material.getKey().toLowerCase()
|
||||
) + " Config",
|
||||
CustomAnvil.instance);
|
||||
|
||||
Pattern pattern = new Pattern(
|
||||
"0000D0000",
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil
|
|||
import xyz.alexcrea.cuanvil.enchant.CAEnchantment
|
||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantmentRegistry
|
||||
import xyz.alexcrea.cuanvil.gui.config.MainConfigGui
|
||||
import xyz.alexcrea.cuanvil.gui.config.global.EnchantConfigGui
|
||||
import xyz.alexcrea.cuanvil.gui.config.global.ItemConfigGui
|
||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions
|
||||
import xyz.alexcrea.cuanvil.util.MaterialUtil.customType
|
||||
|
|
@ -80,7 +81,7 @@ class EditConfigExecutor : CASubCommand() {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO open enchantments edit gui
|
||||
EnchantConfigGui(enchantToFilter).show(sender)
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue