Skip to content

Commit

Permalink
allow specifying which enchantments to remove
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jan 19, 2019
1 parent b376ce6 commit c76f23b
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.aufdemrand.denizencore.objects.dObject;
import net.aufdemrand.denizencore.objects.properties.Property;
import net.aufdemrand.denizencore.tags.Attribute;
import net.aufdemrand.denizencore.utilities.CoreUtilities;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
Expand Down Expand Up @@ -181,17 +182,27 @@ public void adjust(Mechanism mechanism) {
// @name remove_enchantments
// @input None
// @description
// Removes all the item's enchantments.
// Removes the specified enchantments from the item (as a list of enchantment names).
// Give no value input to remove all enchantments.
// @tags
// <i@item.enchantments>
// <i@item.enchantments.levels>
// <i@item.enchantments.with_levels>
// -->
if (mechanism.matches("remove_enchantments")) {
HashSet<String> names = null;
if (mechanism.hasValue()) {
names = new HashSet<>();
for (String ench : mechanism.getValue().asType(dList.class)) {
names.add(CoreUtilities.toLowerCase(ench));
}
}
if (item.getItemStack().getType() == Material.ENCHANTED_BOOK) {
EnchantmentStorageMeta meta = (EnchantmentStorageMeta) item.getItemStack().getItemMeta();
for (Enchantment ench : meta.getStoredEnchants().keySet()) {
meta.removeStoredEnchant(ench);
if (names == null || names.contains(CoreUtilities.toLowerCase(ench.getName()))) {
meta.removeStoredEnchant(ench);
}
}
item.getItemStack().setItemMeta(meta);
}
Expand Down

0 comments on commit c76f23b

Please sign in to comment.