Skip to content

Commit

Permalink
Fix Enchantment squared not working on paper and above
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrea authored and H7KZ committed Sep 12, 2024
1 parent 524a109 commit f5529a2
Showing 1 changed file with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import cz.kominekjan.disenchantment.plugins.IPlugin;
import cz.kominekjan.disenchantment.plugins.impl.VanillaPlugin;
import cz.kominekjan.disenchantment.utils.DisenchantUtils;
import me.athlaeos.enchantssquared.enchantments.CustomEnchant;
import me.athlaeos.enchantssquared.managers.CustomEnchantManager;
import org.bukkit.enchantments.Enchantment;
Expand All @@ -27,18 +26,27 @@ public void activate() {
}

public ItemStack createEnchantedBook(Map<Enchantment, Integer> enchantments) {
ItemStack book = VanillaPlugin.createEnchantedBook(enchantments);
Map<SquarredWrappedEnchantment, Integer> esEnchants = new HashMap<>();

// Fetch enchantment squared enchants
enchantments.forEach((bukkitEnchantment, level) -> {
if (!(bukkitEnchantment instanceof SquarredWrappedEnchantment squaredEnchantment)) return;

// Remove the dummy enchantment object
DisenchantUtils.removeStoredEnchantment(book, bukkitEnchantment);

// And add the enchantment squared enchantment
CustomEnchantManager.getInstance().addEnchant(book, squaredEnchantment.getEnchantment().getType(), level);
esEnchants.put(squaredEnchantment, level);
});

// Remove es enchantment from bukkit enchantment map
for (SquarredWrappedEnchantment esEnchantment : esEnchants.keySet()) {
enchantments.remove(esEnchantment);
}

// Create book with only bukkit enchantments
ItemStack book = VanillaPlugin.createEnchantedBook(enchantments);

// Add enchantment squared enchantments to the book
CustomEnchantManager manager = CustomEnchantManager.getInstance();
esEnchants.forEach((enchantment, level) -> manager.addEnchant(book, enchantment.getEnchantment().getType(), level));

return book;
}

Expand Down

0 comments on commit f5529a2

Please sign in to comment.