From 6f3cee994fda10d8bdbb6358f086f859b91004f5 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Wed, 4 Nov 2020 18:39:16 +0000 Subject: [PATCH] Added support for multiple specials/artifacts on items --- .../ecoenchants/enchantments/EcoEnchant.java | 27 ++++++++++++++++--- .../obtaining/EnchantingListeners.java | 11 +++----- .../support/obtaining/LootPopulator.java | 4 +-- .../support/obtaining/VillagerListeners.java | 10 +++---- .../com/willfp/ecoenchants/loader/Loader.java | 1 + Plugin/src/main/resources/config.yml | 6 +++++ 6 files changed, 38 insertions(+), 21 deletions(-) diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchant.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchant.java index 01e3400a..3ddaf044 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchant.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchant.java @@ -339,9 +339,28 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Regist * The types of {@link EcoEnchant} */ public enum EnchantmentType { - NORMAL, - CURSE, - SPECIAL, - ARTIFACT + NORMAL(false), + CURSE(false), + SPECIAL(true), + ARTIFACT(true); + + static { + update(); + } + + boolean singular; + + EnchantmentType(boolean singular) { + this.singular = singular; + } + + public boolean isSingular() { + return singular; + } + + public static void update() { + SPECIAL.singular = !ConfigManager.getConfig().getBool("types.special.allow-multiple"); + ARTIFACT.singular = !ConfigManager.getConfig().getBool("types.artifact.allow-multiple"); + } } } diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/EnchantingListeners.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/EnchantingListeners.java index eebb5cbc..6b15ddf5 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/EnchantingListeners.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/EnchantingListeners.java @@ -18,12 +18,7 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.EnchantmentStorageMeta; import org.bukkit.scheduler.BukkitRunnable; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.concurrent.atomic.AtomicBoolean; public class EnchantingListeners implements Listener { @@ -102,8 +97,8 @@ public class EnchantingListeners implements Listener { if(EcoEnchants.getFromEnchantment(enchant) != null) { EcoEnchant ecoEnchant = EcoEnchants.getFromEnchantment(enchant); - if (enchantment.getType().equals(EcoEnchant.EnchantmentType.SPECIAL) && ecoEnchant.getType().equals(EcoEnchant.EnchantmentType.SPECIAL)) anyConflicts.set(true); - if (enchantment.getType().equals(EcoEnchant.EnchantmentType.ARTIFACT) && ecoEnchant.getType().equals(EcoEnchant.EnchantmentType.ARTIFACT)) anyConflicts.set(true); + if (enchantment.getType().equals(EcoEnchant.EnchantmentType.SPECIAL) && ecoEnchant.getType().equals(EcoEnchant.EnchantmentType.SPECIAL) && EcoEnchant.EnchantmentType.SPECIAL.isSingular()) anyConflicts.set(true); + if (enchantment.getType().equals(EcoEnchant.EnchantmentType.ARTIFACT) && ecoEnchant.getType().equals(EcoEnchant.EnchantmentType.ARTIFACT) && EcoEnchant.EnchantmentType.ARTIFACT.isSingular()) anyConflicts.set(true); } }); if (anyConflicts.get()) continue; diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/LootPopulator.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/LootPopulator.java index 3ae806ca..f2d77315 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/LootPopulator.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/LootPopulator.java @@ -74,8 +74,8 @@ public class LootPopulator extends BlockPopulator { if (enchant.conflictsWith(enchantment)) anyConflicts.set(true); EcoEnchant ecoEnchant = EcoEnchants.getFromEnchantment(enchant); - if (enchantment.getType().equals(EcoEnchant.EnchantmentType.SPECIAL) && ecoEnchant.getType().equals(EcoEnchant.EnchantmentType.SPECIAL)) anyConflicts.set(true); - if (enchantment.getType().equals(EcoEnchant.EnchantmentType.ARTIFACT) && ecoEnchant.getType().equals(EcoEnchant.EnchantmentType.ARTIFACT)) anyConflicts.set(true); + if (enchantment.getType().equals(EcoEnchant.EnchantmentType.SPECIAL) && ecoEnchant.getType().equals(EcoEnchant.EnchantmentType.SPECIAL) && EcoEnchant.EnchantmentType.SPECIAL.isSingular()) anyConflicts.set(true); + if (enchantment.getType().equals(EcoEnchant.EnchantmentType.ARTIFACT) && ecoEnchant.getType().equals(EcoEnchant.EnchantmentType.ARTIFACT) && EcoEnchant.EnchantmentType.ARTIFACT.isSingular()) anyConflicts.set(true); }); if (anyConflicts.get()) continue; diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/VillagerListeners.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/VillagerListeners.java index 0a427a51..7b2b6956 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/VillagerListeners.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/VillagerListeners.java @@ -14,11 +14,7 @@ import org.bukkit.inventory.MerchantRecipe; import org.bukkit.inventory.meta.EnchantmentStorageMeta; import org.bukkit.inventory.meta.ItemMeta; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.concurrent.atomic.AtomicBoolean; public class VillagerListeners implements Listener { @@ -134,8 +130,8 @@ public class VillagerListeners implements Listener { if (enchant.conflictsWith(enchantment)) anyConflicts.set(true); EcoEnchant ecoEnchant = EcoEnchants.getFromEnchantment(enchant); - if (enchantment.getType().equals(EcoEnchant.EnchantmentType.SPECIAL) && ecoEnchant.getType().equals(EcoEnchant.EnchantmentType.SPECIAL)) anyConflicts.set(true); - if (enchantment.getType().equals(EcoEnchant.EnchantmentType.ARTIFACT) && ecoEnchant.getType().equals(EcoEnchant.EnchantmentType.ARTIFACT)) anyConflicts.set(true); + if (enchantment.getType().equals(EcoEnchant.EnchantmentType.SPECIAL) && ecoEnchant.getType().equals(EcoEnchant.EnchantmentType.SPECIAL) && EcoEnchant.EnchantmentType.SPECIAL.isSingular()) anyConflicts.set(true); + if (enchantment.getType().equals(EcoEnchant.EnchantmentType.ARTIFACT) && ecoEnchant.getType().equals(EcoEnchant.EnchantmentType.ARTIFACT) && EcoEnchant.EnchantmentType.ARTIFACT.isSingular()) anyConflicts.set(true); }); if (anyConflicts.get()) continue; diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/loader/Loader.java b/Plugin/src/main/java/com/willfp/ecoenchants/loader/Loader.java index 97b8fa73..e2b32ac1 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/loader/Loader.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/loader/Loader.java @@ -463,6 +463,7 @@ public class Loader { EcoEnchants.update(); EnchantDisplay.update(); TabCompleterEnchantinfo.reload(); + EcoEnchant.EnchantmentType.update(); EcoEnchants.getAll().forEach((ecoEnchant -> { HandlerList.unregisterAll(ecoEnchant); diff --git a/Plugin/src/main/resources/config.yml b/Plugin/src/main/resources/config.yml index 64d30d1c..75e42467 100644 --- a/Plugin/src/main/resources/config.yml +++ b/Plugin/src/main/resources/config.yml @@ -68,6 +68,12 @@ loot: enabled: true # Enable reduction factor: 7.5 # Factor to reduce probability by. Done as compound, so second pass is (factor) times less likely than first, third less likely than second, etc +types: + special: + allow-multiple: false # Allow multiple special enchantments on a single item + artifact: + allow-multiple: false # Allow multiple artifacts on a single item (can cause lag!) + # # Enchantment-specific config has now been moved to their own files. # Check the /enchants directory.