Fixed grindstoning custom enchants

This commit is contained in:
Auxilor
2022-06-30 22:24:44 +01:00
parent 841fa5f648
commit 339d4938cf
3 changed files with 7 additions and 18 deletions

View File

@@ -2,8 +2,10 @@ package com.willfp.ecoenchants.enchantments.custom;
import com.willfp.eco.core.config.interfaces.Config;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget;
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
import org.bukkit.Bukkit;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;

View File

@@ -3,6 +3,7 @@ package com.willfp.ecoenchants.enchantments.support.merging.grindstone;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.PluginDependent;
import com.willfp.eco.util.NumberUtils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.EntityType;

View File

@@ -1,7 +1,9 @@
package com.willfp.ecoenchants.enchantments.support.merging.grindstone;
import com.willfp.eco.core.fast.FastItemStack;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import lombok.experimental.UtilityClass;
import org.bukkit.Bukkit;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
@@ -22,27 +24,11 @@ public class GrindstoneMerge {
*/
public static Map<Enchantment, Integer> doMerge(@Nullable final ItemStack top,
@Nullable final ItemStack bottom) {
Map<Enchantment, Integer> bottomEnchants = new HashMap<>();
Map<Enchantment, Integer> topEnchants = new HashMap<>();
Map<Enchantment, Integer> bottomEnchants = FastItemStack.wrap(bottom).getEnchants(true);
Map<Enchantment, Integer> topEnchants = FastItemStack.wrap(top).getEnchants(true);
Map<Enchantment, Integer> toKeep = new HashMap<>();
if (top != null) {
if (top.getItemMeta() instanceof EnchantmentStorageMeta) {
topEnchants = new HashMap<>(((EnchantmentStorageMeta) top.getItemMeta()).getStoredEnchants());
} else {
topEnchants = new HashMap<>(top.getEnchantments());
}
}
if (bottom != null) {
if (bottom.getItemMeta() instanceof EnchantmentStorageMeta) {
bottomEnchants = new HashMap<>(((EnchantmentStorageMeta) bottom.getItemMeta()).getStoredEnchants());
} else {
bottomEnchants = new HashMap<>(bottom.getEnchantments());
}
}
bottomEnchants.forEach(((enchantment, integer) -> {
if (enchantment instanceof EcoEnchant ecoEnchant) {
if (!ecoEnchant.isGrindstoneable()) {