Added support for multiple specials/artifacts on items

This commit is contained in:
Auxilor 2020-11-04 18:39:16 +00:00
parent 63c258984a
commit 6f3cee994f
6 changed files with 38 additions and 21 deletions

View File

@ -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");
}
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -463,6 +463,7 @@ public class Loader {
EcoEnchants.update();
EnchantDisplay.update();
TabCompleterEnchantinfo.reload();
EcoEnchant.EnchantmentType.update();
EcoEnchants.getAll().forEach((ecoEnchant -> {
HandlerList.unregisterAll(ecoEnchant);

View File

@ -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.