Add mutuallyExclusiveEnchantments config option
This commit is contained in:
parent
1b9b97db35
commit
9e1d8ec69f
@ -11,10 +11,7 @@ import java.io.IOException;
|
|||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.StandardOpenOption;
|
import java.nio.file.StandardOpenOption;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.LinkedHashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class ConfigLoader
|
public class ConfigLoader
|
||||||
@ -37,6 +34,7 @@ public class ConfigLoader
|
|||||||
private boolean useTierDurability;
|
private boolean useTierDurability;
|
||||||
private boolean dropNetheriteAsChestplate;
|
private boolean dropNetheriteAsChestplate;
|
||||||
private LinkedHashSet<Enchantment> allowedEnchantments;
|
private LinkedHashSet<Enchantment> allowedEnchantments;
|
||||||
|
private LinkedHashSet<List<Enchantment>> mutuallyExclusiveEnchantments;
|
||||||
private boolean allowMultipleProtectionEnchantments;
|
private boolean allowMultipleProtectionEnchantments;
|
||||||
private boolean craftingInSmithingTable;
|
private boolean craftingInSmithingTable;
|
||||||
private boolean allowUpgradeToNetherite;
|
private boolean allowUpgradeToNetherite;
|
||||||
@ -86,6 +84,10 @@ public class ConfigLoader
|
|||||||
"If you install additional enchantment plugins, you can add their enchantments as well.",
|
"If you install additional enchantment plugins, you can add their enchantments as well.",
|
||||||
"Just add their 'NamespacedKey'. Ask the enchantment plugin dev for more info if you need it."
|
"Just add their 'NamespacedKey'. Ask the enchantment plugin dev for more info if you need it."
|
||||||
};
|
};
|
||||||
|
String[] mutuallyExclusiveEnchantmentsComment =
|
||||||
|
{
|
||||||
|
"The lists of enchantments where only one is allowed."
|
||||||
|
};
|
||||||
String[] dropNetheriteAsChestplateComment =
|
String[] dropNetheriteAsChestplateComment =
|
||||||
{
|
{
|
||||||
"Whether to drop Netherite Armored Elytras as netherite chestplates when they are dropped",
|
"Whether to drop Netherite Armored Elytras as netherite chestplates when they are dropped",
|
||||||
@ -164,6 +166,15 @@ public class ConfigLoader
|
|||||||
"minecraft:thorns", "minecraft:binding_curse", "minecraft:vanishing_curse",
|
"minecraft:thorns", "minecraft:binding_curse", "minecraft:vanishing_curse",
|
||||||
"minecraft:mending"));
|
"minecraft:mending"));
|
||||||
|
|
||||||
|
// Set a default list of lists of mutually exclusive enchantments
|
||||||
|
// Default only has a list for the protection enchantments
|
||||||
|
List<List<String>> defaultMutuallyExclusiveEnchantments = new ArrayList<>();
|
||||||
|
defaultMutuallyExclusiveEnchantments.add(List.of(
|
||||||
|
"minecraft:protection",
|
||||||
|
"minecraft:projectile_protection",
|
||||||
|
"minecraft:blast_protection",
|
||||||
|
"minecraft:fire_protection"));
|
||||||
|
|
||||||
FileConfiguration config = plugin.getConfig();
|
FileConfiguration config = plugin.getConfig();
|
||||||
|
|
||||||
|
|
||||||
@ -199,6 +210,11 @@ public class ConfigLoader
|
|||||||
allowedEnchantments = new LinkedHashSet<>();
|
allowedEnchantments = new LinkedHashSet<>();
|
||||||
defaultAllowedEnchantments.forEach(this::addNameSpacedKey);
|
defaultAllowedEnchantments.forEach(this::addNameSpacedKey);
|
||||||
|
|
||||||
|
defaultMutuallyExclusiveEnchantments = addNewConfigOption(config, "mutuallyExclusiveEnchantments",
|
||||||
|
defaultMutuallyExclusiveEnchantments, mutuallyExclusiveEnchantmentsComment);
|
||||||
|
mutuallyExclusiveEnchantments = new LinkedHashSet<>();
|
||||||
|
defaultMutuallyExclusiveEnchantments.forEach(this::addMutuallyExclusiveEnchantments);
|
||||||
|
|
||||||
allowMultipleProtectionEnchantments = addNewConfigOption(config, "allowMultipleProtectionEnchantments", false,
|
allowMultipleProtectionEnchantments = addNewConfigOption(config, "allowMultipleProtectionEnchantments", false,
|
||||||
allowMultipleProtectionEnchantmentsComment);
|
allowMultipleProtectionEnchantmentsComment);
|
||||||
allowAddingEnchantments = addNewConfigOption(config, "allowAddingEnchantments", true,
|
allowAddingEnchantments = addNewConfigOption(config, "allowAddingEnchantments", true,
|
||||||
@ -244,6 +260,35 @@ public class ConfigLoader
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addMutuallyExclusiveEnchantments(List<String> fullKeys)
|
||||||
|
{
|
||||||
|
List<Enchantment> enchantments = new LinkedList<>();
|
||||||
|
for (String fullKey : fullKeys) {
|
||||||
|
try {
|
||||||
|
final String[] keyParts = fullKey.strip().split(":", 2);
|
||||||
|
if (keyParts.length < 2)
|
||||||
|
{
|
||||||
|
Bukkit.getLogger().warning("\"" + fullKey + "\" is not a valid NamespacedKey!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//noinspection deprecation
|
||||||
|
final NamespacedKey key = new NamespacedKey(keyParts[0], keyParts[1]);
|
||||||
|
final Enchantment enchantment = Enchantment.getByKey(key);
|
||||||
|
if (enchantment == null)
|
||||||
|
{
|
||||||
|
Bukkit.getLogger().warning("The enchantment \"" + fullKey + "\" could not be found!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
enchantments.add(enchantment);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
plugin.getLogger().log(Level.WARNING, e, () -> "Failed to register NamespacedKey key: '" + fullKey + "'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mutuallyExclusiveEnchantments.add(enchantments);
|
||||||
|
}
|
||||||
|
|
||||||
private <T> T addNewConfigOption(FileConfiguration config, String optionName, T defaultValue, String[] comment)
|
private <T> T addNewConfigOption(FileConfiguration config, String optionName, T defaultValue, String[] comment)
|
||||||
{
|
{
|
||||||
ConfigOption<T> option = new ConfigOption<>(plugin, config, optionName, defaultValue, comment);
|
ConfigOption<T> option = new ConfigOption<>(plugin, config, optionName, defaultValue, comment);
|
||||||
@ -358,6 +403,11 @@ public class ConfigLoader
|
|||||||
return allowedEnchantments;
|
return allowedEnchantments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LinkedHashSet<List<Enchantment>> getMutuallyExclusiveEnchantments()
|
||||||
|
{
|
||||||
|
return mutuallyExclusiveEnchantments;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean bypassWearPerm()
|
public boolean bypassWearPerm()
|
||||||
{
|
{
|
||||||
return bypassWearPerm;
|
return bypassWearPerm;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user