Attempt to switch from Enchantment to WrapperEnchantment

This commit is contained in:
alexcrea 2024-06-16 03:58:18 +02:00
parent 9f74c2cfff
commit 1eac81aef6
No known key found for this signature in database
GPG key ID: 43FD265DB0DBF91F
12 changed files with 63 additions and 104 deletions

View file

@ -1,15 +1,15 @@
package xyz.alexcrea.cuanvil.gui.config;
import org.bukkit.enchantments.Enchantment;
import xyz.alexcrea.cuanvil.enchant.WrappedEnchantment;
import java.util.Set;
public interface SelectEnchantmentContainer {
Set<Enchantment> getSelectedEnchantments();
Set<WrappedEnchantment> getSelectedEnchantments();
boolean setSelectedEnchantments(Set<Enchantment> enchantments);
boolean setSelectedEnchantments(Set<WrappedEnchantment> enchantments);
Set<Enchantment> illegalEnchantments();
Set<WrappedEnchantment> illegalEnchantments();
}

View file

@ -4,7 +4,7 @@ import com.github.stefvanschie.inventoryframework.gui.GuiItem;
import com.github.stefvanschie.inventoryframework.pane.Orientable;
import com.github.stefvanschie.inventoryframework.pane.OutlinePane;
import io.delilaheve.CustomAnvil;
import org.bukkit.enchantments.Enchantment;
import xyz.alexcrea.cuanvil.enchant.WrappedEnchantment;
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
import xyz.alexcrea.cuanvil.gui.config.settings.AbstractSettingGui;
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
@ -55,7 +55,7 @@ public abstract class AbstractEnchantConfigGui<T extends AbstractSettingGui.Sett
protected void prepareValues() {
bookItemFactoryList = new ArrayList<>();
for (Enchantment enchant : GuiSharedConstant.SORTED_ENCHANTMENT_LIST) {
for (WrappedEnchantment enchant : GuiSharedConstant.SORTED_ENCHANTMENT_LIST) {
T factory = getFactoryFromEnchant(enchant);
bookItemFactoryList.add(factory);
@ -80,7 +80,7 @@ public abstract class AbstractEnchantConfigGui<T extends AbstractSettingGui.Sett
}
public abstract T getFactoryFromEnchant(Enchantment enchant);
public abstract T getFactoryFromEnchant(WrappedEnchantment enchant);
public abstract GuiItem getItemFromFactory(T inventoryFactory);

View file

@ -2,12 +2,12 @@ package xyz.alexcrea.cuanvil.gui.config.global;
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import xyz.alexcrea.cuanvil.config.ConfigHolder;
import xyz.alexcrea.cuanvil.enchant.EnchantmentProperties;
import xyz.alexcrea.cuanvil.enchant.EnchantmentRarity;
import xyz.alexcrea.cuanvil.enchant.WrappedEnchantment;
import xyz.alexcrea.cuanvil.gui.config.settings.EnchantCostSettingsGui;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
@ -39,7 +39,7 @@ public class EnchantCostConfigGui extends AbstractEnchantConfigGui<EnchantCostSe
}
@Override
public EnchantCostSettingsGui.EnchantCostSettingFactory getFactoryFromEnchant(Enchantment enchant) {
public EnchantCostSettingsGui.EnchantCostSettingFactory getFactoryFromEnchant(WrappedEnchantment enchant) {
String key = enchant.getKey().getKey().toLowerCase(Locale.ENGLISH);
String prettyKey = CasedStringUtil.snakeToUpperSpacedCase(key);

View file

@ -2,8 +2,8 @@ package xyz.alexcrea.cuanvil.gui.config.global;
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import xyz.alexcrea.cuanvil.config.ConfigHolder;
import xyz.alexcrea.cuanvil.enchant.WrappedEnchantment;
import xyz.alexcrea.cuanvil.gui.config.settings.IntSettingsGui;
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
@ -32,7 +32,7 @@ public class EnchantLimitConfigGui extends AbstractEnchantConfigGui<IntSettingsG
}
@Override
public IntSettingsGui.IntSettingFactory getFactoryFromEnchant(Enchantment enchant) {
public IntSettingsGui.IntSettingFactory getFactoryFromEnchant(WrappedEnchantment enchant) {
String key = enchant.getKey().getKey().toLowerCase(Locale.ROOT);
String prettyKey = CasedStringUtil.snakeToUpperSpacedCase(key);
@ -42,7 +42,7 @@ public class EnchantLimitConfigGui extends AbstractEnchantConfigGui<IntSettingsG
"\u00A77Maximum applied level of " + prettyKey
),
0, 255,
enchant.getMaxLevel(),
enchant.defaultMaxLevel(),
1, 5, 10, 50, 100);
}

View file

@ -5,12 +5,12 @@ 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.enchant.WrappedEnchantment;
import xyz.alexcrea.cuanvil.group.AbstractMaterialGroup;
import xyz.alexcrea.cuanvil.group.EnchantConflictGroup;
import xyz.alexcrea.cuanvil.group.EnchantConflictManager;
@ -118,7 +118,7 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl
EnchantConflictManager manager = ConfigHolder.CONFLICT_HOLDER.getConflictManager();
// Remove from manager
for (Enchantment enchantment : this.enchantConflict.getEnchants()) {
for (WrappedEnchantment enchantment : this.enchantConflict.getEnchants()) {
manager.removeConflictFromMap(enchantment, this.enchantConflict);
}
manager.conflictList.remove(this.enchantConflict);
@ -164,12 +164,12 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl
// Prepare enchantment lore
ArrayList<String> enchantLore = new ArrayList<>();
enchantLore.add("\u00A77Allow you to select a list of \u00A75Enchantments \u00A77that this conflict should include");
Set<Enchantment> enchants = getSelectedEnchantments();
Set<WrappedEnchantment> enchants = getSelectedEnchantments();
if (enchants.isEmpty()) {
enchantLore.add("\u00A77There is no included enchantment for this conflict.");
} else {
enchantLore.add("\u00A77List of included enchantment for this conflict:");
Iterator<Enchantment> enchantIterator = enchants.iterator();
Iterator<WrappedEnchantment> enchantIterator = enchants.iterator();
boolean greaterThanMax = enchants.size() > 5;
int maxindex = (greaterThanMax ? 4 : enchants.size());
@ -243,12 +243,12 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl
// Select enchantment container methods
@Override
public Set<Enchantment> getSelectedEnchantments() {
public Set<WrappedEnchantment> getSelectedEnchantments() {
return this.enchantConflict.getEnchants();
}
@Override
public boolean setSelectedEnchantments(Set<Enchantment> enchantments) {
public boolean setSelectedEnchantments(Set<WrappedEnchantment> enchantments) {
if (!this.shouldWork) {
CustomAnvil.instance.getLogger().info("Trying to save " + enchantConflict + " enchants but sub config is destroyed");
return false;
@ -260,7 +260,7 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl
// Save on file configuration
String[] enchantKeys = new String[enchantments.size()];
int index = 0;
for (Enchantment enchantment : enchantments) {
for (WrappedEnchantment enchantment : enchantments) {
enchantKeys[index++] = enchantment.getKey().getKey();
}
ConfigHolder.CONFLICT_HOLDER.getConfig().set(enchantConflict + ".enchantments", enchantKeys);
@ -280,7 +280,7 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl
}
@Override
public Set<Enchantment> illegalEnchantments() {
public Set<WrappedEnchantment> illegalEnchantments() {
return Collections.emptySet();
}

View file

@ -13,6 +13,7 @@ import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull;
import xyz.alexcrea.cuanvil.enchant.WrappedEnchantment;
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
import xyz.alexcrea.cuanvil.gui.config.SelectEnchantmentContainer;
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
@ -29,7 +30,7 @@ public class EnchantSelectSettingGui extends AbstractSettingGui {
SelectEnchantmentContainer enchantContainer;
int page;
Set<Enchantment> selectedEnchant;
Set<WrappedEnchantment> selectedEnchant;
public EnchantSelectSettingGui(@NotNull String title, ValueUpdatableGui parent, SelectEnchantmentContainer enchantContainer, int page) {
super(6, title, parent);
@ -64,8 +65,8 @@ public class EnchantSelectSettingGui extends AbstractSettingGui {
filledEnchant.align(OutlinePane.Alignment.BEGIN);
filledEnchant.setOrientation(Orientable.Orientation.HORIZONTAL);
Set<Enchantment> illegalEnchant = this.enchantContainer.illegalEnchantments();
for (Enchantment enchant : GuiSharedConstant.SORTED_ENCHANTMENT_LIST) {
Set<WrappedEnchantment> illegalEnchant = this.enchantContainer.illegalEnchantments();
for (WrappedEnchantment enchant : GuiSharedConstant.SORTED_ENCHANTMENT_LIST) {
if (illegalEnchant.contains(enchant)) {
return;
}
@ -76,7 +77,7 @@ public class EnchantSelectSettingGui extends AbstractSettingGui {
}
private GuiItem getGuiItemFromEnchant(Enchantment enchantment) {
private GuiItem getGuiItemFromEnchant(WrappedEnchantment enchantment) {
boolean isIn = this.selectedEnchant.contains(enchantment);
Material usedMaterial;
@ -122,7 +123,7 @@ public class EnchantSelectSettingGui extends AbstractSettingGui {
item.setItemMeta(meta);
}
private Consumer<InventoryClickEvent> getEnchantItemConsumer(Enchantment enchant, GuiItem guiItem) {
private Consumer<InventoryClickEvent> getEnchantItemConsumer(WrappedEnchantment enchant, GuiItem guiItem) {
return event -> {
event.setCancelled(true);
@ -151,7 +152,7 @@ public class EnchantSelectSettingGui extends AbstractSettingGui {
@Override
public boolean hadChange() {
Set<Enchantment> baseGroup = this.enchantContainer.getSelectedEnchantments();
Set<WrappedEnchantment> baseGroup = this.enchantContainer.getSelectedEnchantments();
return baseGroup.size() != this.selectedEnchant.size() ||
!baseGroup.containsAll(this.selectedEnchant);
}

View file

@ -5,9 +5,9 @@ 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 org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import xyz.alexcrea.cuanvil.enchant.WrappedEnchantment;
import xyz.alexcrea.cuanvil.gui.config.MainConfigGui;
import java.util.Arrays;
@ -17,10 +17,10 @@ import java.util.List;
public class GuiSharedConstant {
public static final List<Enchantment> SORTED_ENCHANTMENT_LIST;
public static final List<WrappedEnchantment> SORTED_ENCHANTMENT_LIST;
static {
SORTED_ENCHANTMENT_LIST = Arrays.asList(Enchantment.values());
SORTED_ENCHANTMENT_LIST = Arrays.asList(WrappedEnchantment.values());
SORTED_ENCHANTMENT_LIST.sort(Comparator.comparing(ench -> ench.getKey().getKey()));
}