mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
Attempt to switch from Enchantment to WrapperEnchantment
This commit is contained in:
parent
9f74c2cfff
commit
1eac81aef6
12 changed files with 63 additions and 104 deletions
|
|
@ -1,15 +1,15 @@
|
||||||
package xyz.alexcrea.cuanvil.gui.config;
|
package xyz.alexcrea.cuanvil.gui.config;
|
||||||
|
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import xyz.alexcrea.cuanvil.enchant.WrappedEnchantment;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public interface SelectEnchantmentContainer {
|
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();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||||
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 io.delilaheve.CustomAnvil;
|
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.ValueUpdatableGui;
|
||||||
import xyz.alexcrea.cuanvil.gui.config.settings.AbstractSettingGui;
|
import xyz.alexcrea.cuanvil.gui.config.settings.AbstractSettingGui;
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
|
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
|
||||||
|
|
@ -55,7 +55,7 @@ public abstract class AbstractEnchantConfigGui<T extends AbstractSettingGui.Sett
|
||||||
protected void prepareValues() {
|
protected void prepareValues() {
|
||||||
bookItemFactoryList = new ArrayList<>();
|
bookItemFactoryList = new ArrayList<>();
|
||||||
|
|
||||||
for (Enchantment enchant : GuiSharedConstant.SORTED_ENCHANTMENT_LIST) {
|
for (WrappedEnchantment enchant : GuiSharedConstant.SORTED_ENCHANTMENT_LIST) {
|
||||||
T factory = getFactoryFromEnchant(enchant);
|
T factory = getFactoryFromEnchant(enchant);
|
||||||
|
|
||||||
bookItemFactoryList.add(factory);
|
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);
|
public abstract GuiItem getItemFromFactory(T inventoryFactory);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,12 @@ package xyz.alexcrea.cuanvil.gui.config.global;
|
||||||
|
|
||||||
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
|
||||||
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.config.ConfigHolder;
|
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||||
import xyz.alexcrea.cuanvil.enchant.EnchantmentProperties;
|
import xyz.alexcrea.cuanvil.enchant.EnchantmentProperties;
|
||||||
import xyz.alexcrea.cuanvil.enchant.EnchantmentRarity;
|
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.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;
|
||||||
|
|
@ -39,7 +39,7 @@ public class EnchantCostConfigGui extends AbstractEnchantConfigGui<EnchantCostSe
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EnchantCostSettingsGui.EnchantCostSettingFactory getFactoryFromEnchant(Enchantment enchant) {
|
public EnchantCostSettingsGui.EnchantCostSettingFactory getFactoryFromEnchant(WrappedEnchantment enchant) {
|
||||||
String key = enchant.getKey().getKey().toLowerCase(Locale.ENGLISH);
|
String key = enchant.getKey().getKey().toLowerCase(Locale.ENGLISH);
|
||||||
String prettyKey = CasedStringUtil.snakeToUpperSpacedCase(key);
|
String prettyKey = CasedStringUtil.snakeToUpperSpacedCase(key);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@ package xyz.alexcrea.cuanvil.gui.config.global;
|
||||||
|
|
||||||
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
|
||||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||||
|
import xyz.alexcrea.cuanvil.enchant.WrappedEnchantment;
|
||||||
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;
|
||||||
|
|
||||||
|
|
@ -32,7 +32,7 @@ public class EnchantLimitConfigGui extends AbstractEnchantConfigGui<IntSettingsG
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IntSettingsGui.IntSettingFactory getFactoryFromEnchant(Enchantment enchant) {
|
public IntSettingsGui.IntSettingFactory getFactoryFromEnchant(WrappedEnchantment enchant) {
|
||||||
String key = enchant.getKey().getKey().toLowerCase(Locale.ROOT);
|
String key = enchant.getKey().getKey().toLowerCase(Locale.ROOT);
|
||||||
String prettyKey = CasedStringUtil.snakeToUpperSpacedCase(key);
|
String prettyKey = CasedStringUtil.snakeToUpperSpacedCase(key);
|
||||||
|
|
||||||
|
|
@ -42,7 +42,7 @@ public class EnchantLimitConfigGui extends AbstractEnchantConfigGui<IntSettingsG
|
||||||
"\u00A77Maximum applied level of " + prettyKey
|
"\u00A77Maximum applied level of " + prettyKey
|
||||||
),
|
),
|
||||||
0, 255,
|
0, 255,
|
||||||
enchant.getMaxLevel(),
|
enchant.defaultMaxLevel(),
|
||||||
1, 5, 10, 50, 100);
|
1, 5, 10, 50, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,12 @@ 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.enchantments.Enchantment;
|
|
||||||
import org.bukkit.entity.HumanEntity;
|
import org.bukkit.entity.HumanEntity;
|
||||||
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.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||||
|
import xyz.alexcrea.cuanvil.enchant.WrappedEnchantment;
|
||||||
import xyz.alexcrea.cuanvil.group.AbstractMaterialGroup;
|
import xyz.alexcrea.cuanvil.group.AbstractMaterialGroup;
|
||||||
import xyz.alexcrea.cuanvil.group.EnchantConflictGroup;
|
import xyz.alexcrea.cuanvil.group.EnchantConflictGroup;
|
||||||
import xyz.alexcrea.cuanvil.group.EnchantConflictManager;
|
import xyz.alexcrea.cuanvil.group.EnchantConflictManager;
|
||||||
|
|
@ -118,7 +118,7 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl
|
||||||
EnchantConflictManager manager = ConfigHolder.CONFLICT_HOLDER.getConflictManager();
|
EnchantConflictManager manager = ConfigHolder.CONFLICT_HOLDER.getConflictManager();
|
||||||
|
|
||||||
// Remove from manager
|
// Remove from manager
|
||||||
for (Enchantment enchantment : this.enchantConflict.getEnchants()) {
|
for (WrappedEnchantment enchantment : this.enchantConflict.getEnchants()) {
|
||||||
manager.removeConflictFromMap(enchantment, this.enchantConflict);
|
manager.removeConflictFromMap(enchantment, this.enchantConflict);
|
||||||
}
|
}
|
||||||
manager.conflictList.remove(this.enchantConflict);
|
manager.conflictList.remove(this.enchantConflict);
|
||||||
|
|
@ -164,12 +164,12 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl
|
||||||
// Prepare enchantment lore
|
// Prepare enchantment lore
|
||||||
ArrayList<String> enchantLore = new ArrayList<>();
|
ArrayList<String> enchantLore = new ArrayList<>();
|
||||||
enchantLore.add("\u00A77Allow you to select a list of \u00A75Enchantments \u00A77that this conflict should include");
|
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()) {
|
if (enchants.isEmpty()) {
|
||||||
enchantLore.add("\u00A77There is no included enchantment for this conflict.");
|
enchantLore.add("\u00A77There is no included enchantment for this conflict.");
|
||||||
} else {
|
} else {
|
||||||
enchantLore.add("\u00A77List of included enchantment for this conflict:");
|
enchantLore.add("\u00A77List of included enchantment for this conflict:");
|
||||||
Iterator<Enchantment> enchantIterator = enchants.iterator();
|
Iterator<WrappedEnchantment> enchantIterator = enchants.iterator();
|
||||||
|
|
||||||
boolean greaterThanMax = enchants.size() > 5;
|
boolean greaterThanMax = enchants.size() > 5;
|
||||||
int maxindex = (greaterThanMax ? 4 : enchants.size());
|
int maxindex = (greaterThanMax ? 4 : enchants.size());
|
||||||
|
|
@ -243,12 +243,12 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl
|
||||||
// Select enchantment container methods
|
// Select enchantment container methods
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<Enchantment> getSelectedEnchantments() {
|
public Set<WrappedEnchantment> getSelectedEnchantments() {
|
||||||
return this.enchantConflict.getEnchants();
|
return this.enchantConflict.getEnchants();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setSelectedEnchantments(Set<Enchantment> enchantments) {
|
public boolean setSelectedEnchantments(Set<WrappedEnchantment> enchantments) {
|
||||||
if (!this.shouldWork) {
|
if (!this.shouldWork) {
|
||||||
CustomAnvil.instance.getLogger().info("Trying to save " + enchantConflict + " enchants but sub config is destroyed");
|
CustomAnvil.instance.getLogger().info("Trying to save " + enchantConflict + " enchants but sub config is destroyed");
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -260,7 +260,7 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl
|
||||||
// Save on file configuration
|
// Save on file configuration
|
||||||
String[] enchantKeys = new String[enchantments.size()];
|
String[] enchantKeys = new String[enchantments.size()];
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for (Enchantment enchantment : enchantments) {
|
for (WrappedEnchantment enchantment : enchantments) {
|
||||||
enchantKeys[index++] = enchantment.getKey().getKey();
|
enchantKeys[index++] = enchantment.getKey().getKey();
|
||||||
}
|
}
|
||||||
ConfigHolder.CONFLICT_HOLDER.getConfig().set(enchantConflict + ".enchantments", enchantKeys);
|
ConfigHolder.CONFLICT_HOLDER.getConfig().set(enchantConflict + ".enchantments", enchantKeys);
|
||||||
|
|
@ -280,7 +280,7 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<Enchantment> illegalEnchantments() {
|
public Set<WrappedEnchantment> illegalEnchantments() {
|
||||||
return Collections.emptySet();
|
return Collections.emptySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ import org.bukkit.inventory.ItemFlag;
|
||||||
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.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import xyz.alexcrea.cuanvil.enchant.WrappedEnchantment;
|
||||||
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
||||||
import xyz.alexcrea.cuanvil.gui.config.SelectEnchantmentContainer;
|
import xyz.alexcrea.cuanvil.gui.config.SelectEnchantmentContainer;
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
|
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
|
||||||
|
|
@ -29,7 +30,7 @@ public class EnchantSelectSettingGui extends AbstractSettingGui {
|
||||||
SelectEnchantmentContainer enchantContainer;
|
SelectEnchantmentContainer enchantContainer;
|
||||||
int page;
|
int page;
|
||||||
|
|
||||||
Set<Enchantment> selectedEnchant;
|
Set<WrappedEnchantment> selectedEnchant;
|
||||||
|
|
||||||
public EnchantSelectSettingGui(@NotNull String title, ValueUpdatableGui parent, SelectEnchantmentContainer enchantContainer, int page) {
|
public EnchantSelectSettingGui(@NotNull String title, ValueUpdatableGui parent, SelectEnchantmentContainer enchantContainer, int page) {
|
||||||
super(6, title, parent);
|
super(6, title, parent);
|
||||||
|
|
@ -64,8 +65,8 @@ public class EnchantSelectSettingGui extends AbstractSettingGui {
|
||||||
filledEnchant.align(OutlinePane.Alignment.BEGIN);
|
filledEnchant.align(OutlinePane.Alignment.BEGIN);
|
||||||
filledEnchant.setOrientation(Orientable.Orientation.HORIZONTAL);
|
filledEnchant.setOrientation(Orientable.Orientation.HORIZONTAL);
|
||||||
|
|
||||||
Set<Enchantment> illegalEnchant = this.enchantContainer.illegalEnchantments();
|
Set<WrappedEnchantment> illegalEnchant = this.enchantContainer.illegalEnchantments();
|
||||||
for (Enchantment enchant : GuiSharedConstant.SORTED_ENCHANTMENT_LIST) {
|
for (WrappedEnchantment enchant : GuiSharedConstant.SORTED_ENCHANTMENT_LIST) {
|
||||||
if (illegalEnchant.contains(enchant)) {
|
if (illegalEnchant.contains(enchant)) {
|
||||||
return;
|
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);
|
boolean isIn = this.selectedEnchant.contains(enchantment);
|
||||||
|
|
||||||
Material usedMaterial;
|
Material usedMaterial;
|
||||||
|
|
@ -122,7 +123,7 @@ public class EnchantSelectSettingGui extends AbstractSettingGui {
|
||||||
item.setItemMeta(meta);
|
item.setItemMeta(meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Consumer<InventoryClickEvent> getEnchantItemConsumer(Enchantment enchant, GuiItem guiItem) {
|
private Consumer<InventoryClickEvent> getEnchantItemConsumer(WrappedEnchantment enchant, GuiItem guiItem) {
|
||||||
return event -> {
|
return event -> {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
|
||||||
|
|
@ -151,7 +152,7 @@ public class EnchantSelectSettingGui extends AbstractSettingGui {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hadChange() {
|
public boolean hadChange() {
|
||||||
Set<Enchantment> baseGroup = this.enchantContainer.getSelectedEnchantments();
|
Set<WrappedEnchantment> baseGroup = this.enchantContainer.getSelectedEnchantments();
|
||||||
return baseGroup.size() != this.selectedEnchant.size() ||
|
return baseGroup.size() != this.selectedEnchant.size() ||
|
||||||
!baseGroup.containsAll(this.selectedEnchant);
|
!baseGroup.containsAll(this.selectedEnchant);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,9 @@ import com.github.stefvanschie.inventoryframework.pane.Pane;
|
||||||
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 org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
|
||||||
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.enchant.WrappedEnchantment;
|
||||||
import xyz.alexcrea.cuanvil.gui.config.MainConfigGui;
|
import xyz.alexcrea.cuanvil.gui.config.MainConfigGui;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
@ -17,10 +17,10 @@ import java.util.List;
|
||||||
|
|
||||||
public class GuiSharedConstant {
|
public class GuiSharedConstant {
|
||||||
|
|
||||||
public static final List<Enchantment> SORTED_ENCHANTMENT_LIST;
|
public static final List<WrappedEnchantment> SORTED_ENCHANTMENT_LIST;
|
||||||
|
|
||||||
static {
|
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()));
|
SORTED_ENCHANTMENT_LIST.sort(Comparator.comparing(ench -> ench.getKey().getKey()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@ package io.delilaheve.util
|
||||||
|
|
||||||
import io.delilaheve.CustomAnvil
|
import io.delilaheve.CustomAnvil
|
||||||
import io.delilaheve.util.EnchantmentUtil.enchantmentName
|
import io.delilaheve.util.EnchantmentUtil.enchantmentName
|
||||||
import org.bukkit.enchantments.Enchantment
|
|
||||||
import xyz.alexcrea.cuanvil.config.ConfigHolder
|
import xyz.alexcrea.cuanvil.config.ConfigHolder
|
||||||
|
import xyz.alexcrea.cuanvil.enchant.WrappedEnchantment
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Config option accessors
|
* Config option accessors
|
||||||
|
|
@ -239,7 +239,7 @@ object ConfigOptions {
|
||||||
/**
|
/**
|
||||||
* Get the given [enchantment]'s limit
|
* Get the given [enchantment]'s limit
|
||||||
*/
|
*/
|
||||||
fun enchantLimit(enchantment: Enchantment): Int {
|
fun enchantLimit(enchantment: WrappedEnchantment): Int {
|
||||||
return enchantLimit(enchantment.enchantmentName)
|
return enchantLimit(enchantment.enchantmentName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -273,7 +273,7 @@ object ConfigOptions {
|
||||||
* it's source [isFromBook]
|
* it's source [isFromBook]
|
||||||
*/
|
*/
|
||||||
fun enchantmentValue(
|
fun enchantmentValue(
|
||||||
enchantment: Enchantment,
|
enchantment: WrappedEnchantment,
|
||||||
isFromBook: Boolean
|
isFromBook: Boolean
|
||||||
): Int {
|
): Int {
|
||||||
return enchantmentValue(enchantment.enchantmentName, isFromBook)
|
return enchantmentValue(enchantment.enchantmentName, isFromBook)
|
||||||
|
|
@ -309,22 +309,4 @@ object ConfigOptions {
|
||||||
return DEFAULT_ENCHANT_VALUE
|
return DEFAULT_ENCHANT_VALUE
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get an array of key of basic config options
|
|
||||||
*/
|
|
||||||
fun getBasicConfigKeys(): Array<String> {
|
|
||||||
return arrayOf(
|
|
||||||
DEFAULT_LIMIT_PATH,
|
|
||||||
CAP_ANVIL_COST,
|
|
||||||
MAX_ANVIL_COST,
|
|
||||||
REPLACE_TOO_EXPENSIVE,
|
|
||||||
ITEM_REPAIR_COST,
|
|
||||||
UNIT_REPAIR_COST,
|
|
||||||
ITEM_RENAME_COST,
|
|
||||||
SACRIFICE_ILLEGAL_COST,
|
|
||||||
REMOVE_ANVIL_COST_LIMIT
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,9 @@ package io.delilaheve.util
|
||||||
|
|
||||||
import io.delilaheve.CustomAnvil
|
import io.delilaheve.CustomAnvil
|
||||||
import org.bukkit.Material
|
import org.bukkit.Material
|
||||||
import org.bukkit.enchantments.Enchantment
|
|
||||||
import org.bukkit.entity.HumanEntity
|
import org.bukkit.entity.HumanEntity
|
||||||
import xyz.alexcrea.cuanvil.config.ConfigHolder
|
import xyz.alexcrea.cuanvil.config.ConfigHolder
|
||||||
|
import xyz.alexcrea.cuanvil.enchant.WrappedEnchantment
|
||||||
import xyz.alexcrea.cuanvil.group.ConflictType
|
import xyz.alexcrea.cuanvil.group.ConflictType
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
|
@ -17,17 +17,17 @@ object EnchantmentUtil {
|
||||||
/**
|
/**
|
||||||
* Enchantment name without namespace
|
* Enchantment name without namespace
|
||||||
*/
|
*/
|
||||||
val Enchantment.enchantmentName: String
|
val WrappedEnchantment.enchantmentName: String
|
||||||
get() = key.key
|
get() = key.key
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Combine 2 sets of enchantments according to our configuration
|
* Combine 2 sets of enchantments according to our configuration
|
||||||
*/
|
*/
|
||||||
fun Map<Enchantment, Int>.combineWith(
|
fun Map<WrappedEnchantment, Int>.combineWith(
|
||||||
other: Map<Enchantment, Int>,
|
other: Map<WrappedEnchantment, Int>,
|
||||||
mat: Material,
|
mat: Material,
|
||||||
player: HumanEntity
|
player: HumanEntity
|
||||||
) = mutableMapOf<Enchantment, Int>().apply {
|
) = mutableMapOf<WrappedEnchantment, Int>().apply {
|
||||||
putAll(this@combineWith)
|
putAll(this@combineWith)
|
||||||
other.forEach { (enchantment, level) ->
|
other.forEach { (enchantment, level) ->
|
||||||
// Get max level or 255 if player can bypass
|
// Get max level or 255 if player can bypass
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,9 @@
|
||||||
package io.delilaheve.util
|
package io.delilaheve.util
|
||||||
|
|
||||||
import io.delilaheve.CustomAnvil
|
|
||||||
import org.bukkit.Material.ENCHANTED_BOOK
|
import org.bukkit.Material.ENCHANTED_BOOK
|
||||||
import org.bukkit.enchantments.Enchantment
|
|
||||||
import org.bukkit.inventory.ItemStack
|
import org.bukkit.inventory.ItemStack
|
||||||
import org.bukkit.inventory.meta.Damageable
|
import org.bukkit.inventory.meta.Damageable
|
||||||
import org.bukkit.inventory.meta.EnchantmentStorageMeta
|
import xyz.alexcrea.cuanvil.enchant.WrappedEnchantment
|
||||||
import kotlin.math.ceil
|
import kotlin.math.ceil
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
|
@ -23,44 +21,21 @@ object ItemUtil {
|
||||||
/**
|
/**
|
||||||
* Find the enchantment map for this [ItemStack] and return it as a [MutableMap]
|
* Find the enchantment map for this [ItemStack] and return it as a [MutableMap]
|
||||||
*/
|
*/
|
||||||
fun ItemStack.findEnchantments() = if (isEnchantedBook()) {
|
fun ItemStack.findEnchantments(): MutableMap<WrappedEnchantment, Int> = WrappedEnchantment.getEnchants(this)
|
||||||
(itemMeta as? EnchantmentStorageMeta)?.storedEnchants ?: emptyMap()
|
|
||||||
} else {
|
|
||||||
itemMeta?.enchants ?: emptyMap()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply an [enchantments] map to this [ItemStack]
|
* Apply an [enchantments] map to this [ItemStack]
|
||||||
*/
|
*/
|
||||||
fun ItemStack.setEnchantmentsUnsafe(enchantments: Map<Enchantment, Int>) {
|
fun ItemStack.setEnchantmentsUnsafe(enchantments: Map<WrappedEnchantment, Int>) {
|
||||||
if (isEnchantedBook()) {
|
WrappedEnchantment.clearEnchants(this)
|
||||||
/* For some god-forsaken reason, item meta is not mutable
|
|
||||||
* so, we have to get the instance, modify it, then set it
|
|
||||||
* back to the item... #BecauseMinecraft */
|
|
||||||
val bookMeta = (itemMeta as? EnchantmentStorageMeta)
|
|
||||||
bookMeta?.replaceEnchants(enchantments)
|
|
||||||
itemMeta = bookMeta
|
|
||||||
} else {
|
|
||||||
itemMeta?.enchants?.forEach { (enchant, _) ->
|
|
||||||
removeEnchantment(enchant)
|
|
||||||
}
|
|
||||||
addUnsafeEnchantments(enchantments)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
val meta = this.itemMeta ?: return
|
||||||
* Apply an [enchantments] map to this book
|
|
||||||
*/
|
enchantments.forEach { (enchantment, level) ->
|
||||||
private fun EnchantmentStorageMeta.replaceEnchants(
|
enchantment.addEnchantmentUnsafe(this, meta, level)
|
||||||
enchantments: Map<Enchantment, Int>
|
|
||||||
) {
|
|
||||||
storedEnchants.forEach { (enchant, _) ->
|
|
||||||
removeStoredEnchant(enchant)
|
|
||||||
}
|
|
||||||
enchantments.forEach { (enchant, level) ->
|
|
||||||
val added = addStoredEnchant(enchant, level, true)
|
|
||||||
CustomAnvil.log("${enchant.key} added to item? $added")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.itemMeta = meta
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ package xyz.alexcrea.cuanvil.group
|
||||||
|
|
||||||
import io.delilaheve.CustomAnvil
|
import io.delilaheve.CustomAnvil
|
||||||
import org.bukkit.Material
|
import org.bukkit.Material
|
||||||
import org.bukkit.enchantments.Enchantment
|
import xyz.alexcrea.cuanvil.enchant.WrappedEnchantment
|
||||||
|
|
||||||
class EnchantConflictGroup(
|
class EnchantConflictGroup(
|
||||||
private val name: String,
|
private val name: String,
|
||||||
|
|
@ -10,13 +10,13 @@ class EnchantConflictGroup(
|
||||||
var minBeforeBlock: Int
|
var minBeforeBlock: Int
|
||||||
) {
|
) {
|
||||||
|
|
||||||
private val enchantments = HashSet<Enchantment>()
|
private val enchantments = HashSet<WrappedEnchantment>()
|
||||||
|
|
||||||
fun addEnchantment(enchant: Enchantment) {
|
fun addEnchantment(enchant: WrappedEnchantment) {
|
||||||
enchantments.add(enchant)
|
enchantments.add(enchant)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun allowed(enchants: Set<Enchantment>, mat: Material): Boolean {
|
fun allowed(enchants: Set<WrappedEnchantment>, mat: Material): Boolean {
|
||||||
if (enchantments.size < minBeforeBlock) {
|
if (enchantments.size < minBeforeBlock) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
@ -42,11 +42,11 @@ class EnchantConflictGroup(
|
||||||
return this.cantConflict
|
return this.cantConflict
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getEnchants(): HashSet<Enchantment> {
|
fun getEnchants(): HashSet<WrappedEnchantment> {
|
||||||
return enchantments
|
return enchantments
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setEnchants(enchants: Set<Enchantment>) {
|
fun setEnchants(enchants: Set<WrappedEnchantment>) {
|
||||||
enchantments.clear()
|
enchantments.clear()
|
||||||
enchantments.addAll(enchants)
|
enchantments.addAll(enchants)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import org.bukkit.Material
|
||||||
import org.bukkit.NamespacedKey
|
import org.bukkit.NamespacedKey
|
||||||
import org.bukkit.configuration.ConfigurationSection
|
import org.bukkit.configuration.ConfigurationSection
|
||||||
import org.bukkit.enchantments.Enchantment
|
import org.bukkit.enchantments.Enchantment
|
||||||
|
import xyz.alexcrea.cuanvil.enchant.WrappedEnchantment
|
||||||
|
|
||||||
class EnchantConflictManager {
|
class EnchantConflictManager {
|
||||||
|
|
||||||
|
|
@ -27,12 +28,12 @@ class EnchantConflictManager {
|
||||||
|
|
||||||
// 1.20.5 compatibility TODO better update system
|
// 1.20.5 compatibility TODO better update system
|
||||||
private val SWEEPING_EDGE_ENCHANT =
|
private val SWEEPING_EDGE_ENCHANT =
|
||||||
Enchantment.getByKey(NamespacedKey.minecraft("sweeping_edge")) ?:
|
WrappedEnchantment.getByKey(NamespacedKey.minecraft("sweeping_edge")) ?:
|
||||||
Enchantment.SWEEPING_EDGE
|
WrappedEnchantment.getByKey(Enchantment.SWEEPING_EDGE.key)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private lateinit var conflictMap: HashMap<Enchantment, ArrayList<EnchantConflictGroup>>
|
private lateinit var conflictMap: HashMap<WrappedEnchantment, ArrayList<EnchantConflictGroup>>
|
||||||
lateinit var conflictList: ArrayList<EnchantConflictGroup>
|
lateinit var conflictList: ArrayList<EnchantConflictGroup>
|
||||||
|
|
||||||
// Read and prepare all conflict
|
// Read and prepare all conflict
|
||||||
|
|
@ -58,14 +59,14 @@ class EnchantConflictManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addConflictToConflictMap(enchant: Enchantment, conflict: EnchantConflictGroup) {
|
fun addConflictToConflictMap(enchant: WrappedEnchantment, 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 {
|
fun removeConflictFromMap(enchant: WrappedEnchantment, conflict: EnchantConflictGroup): Boolean {
|
||||||
return conflictMap[enchant]!!.remove(conflict)
|
return conflictMap[enchant]!!.remove(conflict)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -100,7 +101,7 @@ class EnchantConflictManager {
|
||||||
return conflict
|
return conflict
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getEnchantByName(enchantName: String): Enchantment? {
|
private fun getEnchantByName(enchantName: String): WrappedEnchantment? {
|
||||||
|
|
||||||
// Temporary solution for 1.20.5
|
// Temporary solution for 1.20.5
|
||||||
when(enchantName){
|
when(enchantName){
|
||||||
|
|
@ -110,7 +111,7 @@ class EnchantConflictManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
val enchantKey = NamespacedKey.minecraft(enchantName)
|
val enchantKey = NamespacedKey.minecraft(enchantName)
|
||||||
return Enchantment.getByKey(enchantKey)
|
return WrappedEnchantment.getByKey(enchantKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -151,7 +152,7 @@ class EnchantConflictManager {
|
||||||
return group
|
return group
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isConflicting(base: Set<Enchantment>, mat: Material, newEnchant: Enchantment): ConflictType {
|
fun isConflicting(base: Set<WrappedEnchantment>, mat: Material, newEnchant: WrappedEnchantment): ConflictType {
|
||||||
CustomAnvil.verboseLog("Testing conflict for ${newEnchant.key} on ${mat.key}")
|
CustomAnvil.verboseLog("Testing conflict for ${newEnchant.key} on ${mat.key}")
|
||||||
val conflictList = conflictMap[newEnchant] ?: return ConflictType.NO_CONFLICT
|
val conflictList = conflictMap[newEnchant] ?: return ConflictType.NO_CONFLICT
|
||||||
CustomAnvil.verboseLog("Did not get skipped")
|
CustomAnvil.verboseLog("Did not get skipped")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue