mirror of
https://github.com/YouHaveTrouble/Enchantio.git
synced 2026-05-11 21:56:55 +00:00
151 lines
5.3 KiB
Java
151 lines
5.3 KiB
Java
package me.youhavetrouble.enchantio.enchants;
|
|
|
|
import io.papermc.paper.registry.data.EnchantmentRegistryEntry;
|
|
import io.papermc.paper.registry.tag.TagKey;
|
|
import io.papermc.paper.tag.TagEntry;
|
|
import me.youhavetrouble.enchantio.EnchantioConfig;
|
|
import net.kyori.adventure.key.Key;
|
|
import net.kyori.adventure.text.Component;
|
|
import org.bukkit.configuration.ConfigurationSection;
|
|
import org.bukkit.enchantments.Enchantment;
|
|
import org.bukkit.inventory.EquipmentSlotGroup;
|
|
import org.bukkit.inventory.ItemType;
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
import java.util.*;
|
|
|
|
import static me.youhavetrouble.enchantio.EnchantioConfig.ENCHANTS;
|
|
|
|
@SuppressWarnings("UnstableApiUsage")
|
|
public class PanicEnchant implements EnchantioEnchant {
|
|
|
|
public static final Key KEY = Key.key("enchantio:panic_curse");
|
|
|
|
private final int anvilCost, weight, maxLevel;
|
|
private final EnchantmentRegistryEntry.EnchantmentCost minimumCost;
|
|
private final EnchantmentRegistryEntry.EnchantmentCost maximumCost;
|
|
private final double panicChancePerLevel;
|
|
private final Set<TagEntry<ItemType>> supportedItemTags = new HashSet<>();
|
|
private final Set<TagKey<Enchantment>> enchantTagKeys = new HashSet<>();
|
|
private final Set<EquipmentSlotGroup> activeSlots = new HashSet<>();
|
|
|
|
public PanicEnchant(
|
|
int anvilCost,
|
|
int weight,
|
|
EnchantmentRegistryEntry.EnchantmentCost minimumCost,
|
|
EnchantmentRegistryEntry.EnchantmentCost maximumCost,
|
|
Collection<TagKey<Enchantment>> enchantTagKeys,
|
|
Collection<TagEntry<ItemType>> supportedItemTags,
|
|
Collection<EquipmentSlotGroup> activeSlots,
|
|
int maxLevel,
|
|
double panicChancePerLevel
|
|
) {
|
|
this.anvilCost = anvilCost;
|
|
this.weight = weight;
|
|
this.maxLevel = maxLevel;
|
|
this.minimumCost = minimumCost;
|
|
this.maximumCost = maximumCost;
|
|
this.supportedItemTags.addAll(supportedItemTags);
|
|
this.panicChancePerLevel = panicChancePerLevel;
|
|
this.activeSlots.addAll(activeSlots);
|
|
this.enchantTagKeys.addAll(enchantTagKeys);
|
|
}
|
|
|
|
@Override
|
|
public @NotNull Key getKey() {
|
|
return KEY;
|
|
}
|
|
|
|
@Override
|
|
public @NotNull Component getDescription() {
|
|
return Component.translatable("enchantio.enchant.panic_curse", "Curse of Panic");
|
|
}
|
|
|
|
@Override
|
|
public int getAnvilCost() {
|
|
return anvilCost;
|
|
}
|
|
|
|
@Override
|
|
public int getMaxLevel() {
|
|
return maxLevel;
|
|
}
|
|
|
|
@Override
|
|
public int getWeight() {
|
|
return weight;
|
|
}
|
|
|
|
@Override
|
|
public EnchantmentRegistryEntry.@NotNull EnchantmentCost getMinimumCost() {
|
|
return minimumCost;
|
|
}
|
|
|
|
@Override
|
|
public EnchantmentRegistryEntry.@NotNull EnchantmentCost getMaximumCost() {
|
|
return maximumCost;
|
|
}
|
|
|
|
@Override
|
|
public @NotNull Iterable<EquipmentSlotGroup> getActiveSlots() {
|
|
return activeSlots;
|
|
}
|
|
|
|
@Override
|
|
public @NotNull Set<TagEntry<ItemType>> getSupportedItems() {
|
|
return supportedItemTags;
|
|
}
|
|
|
|
@Override
|
|
public @NotNull Set<TagKey<Enchantment>> getEnchantTagKeys() {
|
|
return Collections.unmodifiableSet(enchantTagKeys);
|
|
}
|
|
|
|
public double getPanicChancePerLevel() {
|
|
return panicChancePerLevel;
|
|
}
|
|
|
|
public static PanicEnchant create(ConfigurationSection configurationSection) {
|
|
PanicEnchant panicEnchant = new PanicEnchant(
|
|
EnchantioConfig.getInt(configurationSection, "anvilCost", 1),
|
|
EnchantioConfig.getInt(configurationSection, "weight", 2),
|
|
EnchantmentRegistryEntry.EnchantmentCost.of(
|
|
EnchantioConfig.getInt(configurationSection, "minimumCost.base", 0),
|
|
EnchantioConfig.getInt(configurationSection, "minimumCost.additionalPerLevel", 3)
|
|
),
|
|
EnchantmentRegistryEntry.EnchantmentCost.of(
|
|
EnchantioConfig.getInt(configurationSection, "maximumCost.base", 20),
|
|
EnchantioConfig.getInt(configurationSection, "maximumCost.additionalPerLevel", 1)
|
|
),
|
|
EnchantioConfig.getEnchantmentTagKeysFromList(EnchantioConfig.getStringList(
|
|
configurationSection,
|
|
"enchantmentTags",
|
|
List.of("#in_enchanting_table", "#curse")
|
|
)),
|
|
EnchantioConfig.getItemTagEntriesFromList(EnchantioConfig.getStringList(
|
|
configurationSection,
|
|
"supportedItemTags",
|
|
List.of(
|
|
"#minecraft:enchantable/armor"
|
|
)
|
|
)),
|
|
EnchantioConfig.getEquipmentSlotGroups(EnchantioConfig.getStringList(
|
|
configurationSection,
|
|
"activeSlots",
|
|
List.of(
|
|
"ARMOR"
|
|
)
|
|
)),
|
|
EnchantioConfig.getInt(configurationSection, "maxLevel", 1),
|
|
EnchantioConfig.getDouble(configurationSection, "panicChancePerLevel", 0.025)
|
|
);
|
|
|
|
if (EnchantioConfig.getBoolean(configurationSection, "enabled", true)) {
|
|
ENCHANTS.put(PanicEnchant.KEY, panicEnchant);
|
|
}
|
|
|
|
return panicEnchant;
|
|
}
|
|
|
|
}
|