Added vanilla enchantment config setting

This commit is contained in:
Auxilor 2021-07-25 15:59:39 +01:00
parent 0197197e35
commit 75633f494d
5 changed files with 44 additions and 5 deletions

View File

@ -23,7 +23,11 @@ public class EcoCraftEnchantment extends CraftEnchantment {
@Override
public boolean conflictsWith(@NotNull final org.bukkit.enchantments.Enchantment other) {
return other instanceof EcoEnchant ? other.conflictsWith(this) : super.conflictsWith(other);
if (other instanceof EcoEnchant) {
return other.conflictsWith(this);
}
return metadata.conflicts() == null ? super.conflictsWith(other) : metadata.conflicts().contains(other.getKey());
}
public void register() {

View File

@ -23,7 +23,11 @@ public class EcoCraftEnchantment extends CraftEnchantment {
@Override
public boolean conflictsWith(@NotNull final org.bukkit.enchantments.Enchantment other) {
return other instanceof EcoEnchant ? other.conflictsWith(this) : super.conflictsWith(other);
if (other instanceof EcoEnchant) {
return other.conflictsWith(this);
}
return metadata.conflicts() == null ? super.conflictsWith(other) : metadata.conflicts().contains(other.getKey());
}
public void register() {

View File

@ -1,6 +1,11 @@
package com.willfp.ecoenchants.enchantments.support.vanilla;
import org.bukkit.NamespacedKey;
import java.util.Set;
public record VanillaEnchantmentMetadata(
Integer maxLevel
Integer maxLevel,
Set<NamespacedKey> conflicts
) {
}

View File

@ -9,8 +9,10 @@ import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
@UtilityClass
@ -47,8 +49,22 @@ public class VanillaEnchantments {
s1 -> Integer.parseInt(s1.split(":")[1])
));
Map<Enchantment, Set<NamespacedKey>> conflicts = plugin.getVanillaEnchantsYml().getStrings("conflicts").stream()
.collect(Collectors.toMap(
s -> Enchantment.getByKey(NamespacedKey.minecraft(s.split(":")[0].toLowerCase())),
s1 -> {
String[] split = s1.split(":");
Set<NamespacedKey> keys = new HashSet<>();
for (int i = 1; i < split.length; i++) {
keys.add(NamespacedKey.minecraft(split[i]));
}
return keys;
}
));
for (Enchantment enchantment : enchantments) {
VanillaEnchantmentMetadata metadata = new VanillaEnchantmentMetadata(maxLevels.get(enchantment));
VanillaEnchantmentMetadata metadata = new VanillaEnchantmentMetadata(maxLevels.get(enchantment), conflicts.get(enchantment));
map.put(enchantment, metadata);
}

View File

@ -14,4 +14,14 @@ enabled: false # There may be potential conflicts if modifying vanilla enchantme
# Currently, it is *not* possible to modify the enchantment levels from enchanting tables.
# It will work with anvils however, but since it is still possible to get enchantments at their vanilla
# max levels, then it isn't recommended to lower the max level of a vanilla enchantment, only to raise it.
max-levels: []
max-levels: []
# Set custom conflicts for vanilla enchantments.
# To do this, add each enchantment like this:
# - "<key>:<conflict 1 key>:<conflict 2 key>:<conflict 3 key>..... etc"
# For example, to make mending conflict with efficiency and sharpness, you would do this:
# conflicts:
# - "mending:efficiency:sharpness"
#
# Beware that this will *override* conflicts, not add to them.
conflicts: []