mirror of
https://github.com/YouHaveTrouble/Enchantio.git
synced 2026-05-11 21:56:55 +00:00
add curse of insomnia
This commit is contained in:
@@ -66,6 +66,12 @@ When player takes damage, there is a chance that their hotbar items will be scra
|
|||||||
**Description**:
|
**Description**:
|
||||||
Player is set on fire when exposed to direct sunlight.
|
Player is set on fire when exposed to direct sunlight.
|
||||||
|
|
||||||
|
### Curse of Insomnia
|
||||||
|
**Translation key**: `enchantio.enchant.insomnia_curse`
|
||||||
|
|
||||||
|
**Description**:
|
||||||
|
Player will not count as sleeping for the purpose of skipping the night/thunderstorm.
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
### supportedItemTags
|
### supportedItemTags
|
||||||
|
|||||||
@@ -47,6 +47,9 @@ public final class Enchantio extends JavaPlugin {
|
|||||||
if (EnchantioConfig.ENCHANTS.containsKey(VampirismEnchant.KEY)) {
|
if (EnchantioConfig.ENCHANTS.containsKey(VampirismEnchant.KEY)) {
|
||||||
getServer().getPluginManager().registerEvents(new VampirismListener(), this);
|
getServer().getPluginManager().registerEvents(new VampirismListener(), this);
|
||||||
}
|
}
|
||||||
|
if (EnchantioConfig.ENCHANTS.containsKey(InsomniaEnchant.KEY)) {
|
||||||
|
getServer().getPluginManager().registerEvents(new InsomniaListener(), this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -9,16 +9,17 @@ import io.papermc.paper.registry.event.RegistryEvents;
|
|||||||
import io.papermc.paper.registry.keys.tags.ItemTypeTagKeys;
|
import io.papermc.paper.registry.keys.tags.ItemTypeTagKeys;
|
||||||
import me.youhavetrouble.enchantio.enchants.EnchantioEnchant;
|
import me.youhavetrouble.enchantio.enchants.EnchantioEnchant;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
@SuppressWarnings("UnstableApiUsage")
|
@SuppressWarnings("UnstableApiUsage")
|
||||||
public class EnchantioBootstrap implements PluginBootstrap {
|
public class EnchantioBootstrap implements PluginBootstrap {
|
||||||
|
|
||||||
private final Logger logger = Logger.getLogger("enchantio");
|
private final Logger logger = LoggerFactory.getLogger("Enchantio");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bootstrap(@NotNull BootstrapContext context) {
|
public void bootstrap(@NotNull BootstrapContext context) {
|
||||||
@@ -30,10 +31,10 @@ public class EnchantioBootstrap implements PluginBootstrap {
|
|||||||
|
|
||||||
Collection<EnchantioEnchant> enchantioEnchants = EnchantioConfig.ENCHANTS.values();
|
Collection<EnchantioEnchant> enchantioEnchants = EnchantioConfig.ENCHANTS.values();
|
||||||
|
|
||||||
logger.fine("Registering supported item tags");
|
logger.info("Registering supported item tags");
|
||||||
context.getLifecycleManager().registerEventHandler(LifecycleEvents.TAGS.preFlatten(RegistryKey.ITEM).newHandler((event) -> {
|
context.getLifecycleManager().registerEventHandler(LifecycleEvents.TAGS.preFlatten(RegistryKey.ITEM).newHandler((event) -> {
|
||||||
for (EnchantioEnchant enchant : enchantioEnchants) {
|
for (EnchantioEnchant enchant : enchantioEnchants) {
|
||||||
logger.fine("Registering item tag " + enchant.getTagForSupportedItems().key());
|
logger.info("Registering item tag {}", enchant.getTagForSupportedItems().key());
|
||||||
event.registrar().addToTag(
|
event.registrar().addToTag(
|
||||||
ItemTypeTagKeys.create(enchant.getTagForSupportedItems().key()),
|
ItemTypeTagKeys.create(enchant.getTagForSupportedItems().key()),
|
||||||
enchant.getSupportedItems()
|
enchant.getSupportedItems()
|
||||||
@@ -43,7 +44,7 @@ public class EnchantioBootstrap implements PluginBootstrap {
|
|||||||
|
|
||||||
context.getLifecycleManager().registerEventHandler(RegistryEvents.ENCHANTMENT.freeze().newHandler(event -> {
|
context.getLifecycleManager().registerEventHandler(RegistryEvents.ENCHANTMENT.freeze().newHandler(event -> {
|
||||||
for (EnchantioEnchant enchant : enchantioEnchants) {
|
for (EnchantioEnchant enchant : enchantioEnchants) {
|
||||||
logger.fine("Registering enchantment " + enchant.getKey());
|
logger.info("Registering enchantment {}", enchant.getKey());
|
||||||
event.registry().register(TypedKey.create(RegistryKey.ENCHANTMENT, enchant.getKey()), enchantment -> {
|
event.registry().register(TypedKey.create(RegistryKey.ENCHANTMENT, enchant.getKey()), enchantment -> {
|
||||||
enchantment.description(enchant.getDescription());
|
enchantment.description(enchant.getDescription());
|
||||||
enchantment.anvilCost(enchant.getAnvilCost());
|
enchantment.anvilCost(enchant.getAnvilCost());
|
||||||
@@ -60,7 +61,6 @@ public class EnchantioBootstrap implements PluginBootstrap {
|
|||||||
context.getLifecycleManager().registerEventHandler(LifecycleEvents.TAGS.preFlatten(RegistryKey.ENCHANTMENT).newHandler((event) -> {
|
context.getLifecycleManager().registerEventHandler(LifecycleEvents.TAGS.preFlatten(RegistryKey.ENCHANTMENT).newHandler((event) -> {
|
||||||
for (EnchantioEnchant enchant : enchantioEnchants) {
|
for (EnchantioEnchant enchant : enchantioEnchants) {
|
||||||
enchant.getEnchantTagKeys().forEach(enchantmentTagKey -> {
|
enchant.getEnchantTagKeys().forEach(enchantmentTagKey -> {
|
||||||
logger.fine("Registering enchantment tag " + enchantmentTagKey.key());
|
|
||||||
event.registrar().addToTag(enchantmentTagKey, Set.of(enchant.getTagEntry()));
|
event.registrar().addToTag(enchantmentTagKey, Set.of(enchant.getTagEntry()));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,6 +74,9 @@ public class EnchantioConfig {
|
|||||||
ConfigurationSection vampirismSection = getConfigSection(enchantsSection, "vampirism");
|
ConfigurationSection vampirismSection = getConfigSection(enchantsSection, "vampirism");
|
||||||
VampirismEnchant.create(vampirismSection);
|
VampirismEnchant.create(vampirismSection);
|
||||||
|
|
||||||
|
ConfigurationSection insomniaSection = getConfigSection(cursesSection, "insomnia");
|
||||||
|
InsomniaEnchant.create(insomniaSection);
|
||||||
|
|
||||||
configuration.save(configFile);
|
configuration.save(configFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,142 @@
|
|||||||
|
package me.youhavetrouble.enchantio.enchants;
|
||||||
|
|
||||||
|
import io.papermc.paper.registry.data.EnchantmentRegistryEntry;
|
||||||
|
import io.papermc.paper.registry.keys.tags.EnchantmentTagKeys;
|
||||||
|
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.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static me.youhavetrouble.enchantio.EnchantioConfig.ENCHANTS;
|
||||||
|
|
||||||
|
@SuppressWarnings("UnstableApiUsage")
|
||||||
|
public class InsomniaEnchant implements EnchantioEnchant {
|
||||||
|
|
||||||
|
public static final Key KEY = Key.key("enchantio:insomnia_curse");
|
||||||
|
|
||||||
|
private final int anvilCost, weight;
|
||||||
|
private final EnchantmentRegistryEntry.EnchantmentCost minimumCost;
|
||||||
|
private final EnchantmentRegistryEntry.EnchantmentCost maximumCost;
|
||||||
|
private final Set<TagEntry<ItemType>> supportedItemTags;
|
||||||
|
private final Set<TagKey<Enchantment>> enchantTagKeys = new HashSet<>();
|
||||||
|
private final Set<EquipmentSlotGroup> activeSlots = new HashSet<>();
|
||||||
|
|
||||||
|
public InsomniaEnchant(
|
||||||
|
int anvilCost,
|
||||||
|
int weight,
|
||||||
|
EnchantmentRegistryEntry.EnchantmentCost minimumCost,
|
||||||
|
EnchantmentRegistryEntry.EnchantmentCost maximumCost,
|
||||||
|
boolean canGetFromEnchantingTable,
|
||||||
|
Set<TagEntry<ItemType>> supportedItemTags,
|
||||||
|
Set<EquipmentSlotGroup> activeSlots
|
||||||
|
) {
|
||||||
|
this.anvilCost = anvilCost;
|
||||||
|
this.weight = weight;
|
||||||
|
this.minimumCost = minimumCost;
|
||||||
|
this.maximumCost = maximumCost;
|
||||||
|
this.supportedItemTags = supportedItemTags;
|
||||||
|
this.activeSlots.addAll(activeSlots);
|
||||||
|
if (canGetFromEnchantingTable) {
|
||||||
|
enchantTagKeys.add(EnchantmentTagKeys.IN_ENCHANTING_TABLE);
|
||||||
|
}
|
||||||
|
enchantTagKeys.add(EnchantmentTagKeys.CURSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull Key getKey() {
|
||||||
|
return KEY;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull Component getDescription() {
|
||||||
|
return Component.translatable("enchantio.enchant.insomnia_curse", "Curse of Insomnia");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getAnvilCost() {
|
||||||
|
return anvilCost;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxLevel() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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 static InsomniaEnchant create(ConfigurationSection configurationSection) {
|
||||||
|
InsomniaEnchant insomniaEnchant = new InsomniaEnchant(
|
||||||
|
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", 30),
|
||||||
|
EnchantioConfig.getInt(configurationSection, "maximumCost.additionalPerLevel", 1)
|
||||||
|
),
|
||||||
|
EnchantioConfig.getBoolean(configurationSection, "canGetFromEnchantingTable", true),
|
||||||
|
EnchantioConfig.getTagsFromList(EnchantioConfig.getStringList(
|
||||||
|
configurationSection,
|
||||||
|
"supportedItemTags",
|
||||||
|
List.of(
|
||||||
|
"#minecraft:enchantable/armor"
|
||||||
|
)
|
||||||
|
)),
|
||||||
|
EnchantioConfig.getEquipmentSlotGroups(EnchantioConfig.getStringList(
|
||||||
|
configurationSection,
|
||||||
|
"activeSlots",
|
||||||
|
List.of(
|
||||||
|
"ARMOR"
|
||||||
|
)
|
||||||
|
))
|
||||||
|
);
|
||||||
|
|
||||||
|
if (EnchantioConfig.getBoolean(configurationSection, "enabled", true)) {
|
||||||
|
ENCHANTS.put(InsomniaEnchant.KEY, insomniaEnchant);
|
||||||
|
}
|
||||||
|
|
||||||
|
return insomniaEnchant;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package me.youhavetrouble.enchantio.listeners;
|
||||||
|
|
||||||
|
import io.papermc.paper.event.player.PlayerDeepSleepEvent;
|
||||||
|
import io.papermc.paper.registry.RegistryAccess;
|
||||||
|
import io.papermc.paper.registry.RegistryKey;
|
||||||
|
import me.youhavetrouble.enchantio.Enchantio;
|
||||||
|
import me.youhavetrouble.enchantio.enchants.InsomniaEnchant;
|
||||||
|
import org.bukkit.Registry;
|
||||||
|
import org.bukkit.enchantments.Enchantment;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.inventory.EntityEquipment;
|
||||||
|
|
||||||
|
public class InsomniaListener implements Listener {
|
||||||
|
|
||||||
|
private final Registry<Enchantment> registry = RegistryAccess.registryAccess().getRegistry(RegistryKey.ENCHANTMENT);
|
||||||
|
private final Enchantment insomnia = registry.get(InsomniaEnchant.KEY);
|
||||||
|
|
||||||
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
|
||||||
|
public void onPlayerSufferingFromInsomnia(PlayerDeepSleepEvent event) {
|
||||||
|
if (insomnia == null) return;
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
EntityEquipment damagerEquipment = player.getEquipment();
|
||||||
|
int level = Enchantio.getSumOfEnchantLevels(damagerEquipment, insomnia);
|
||||||
|
if (level == 0) return;
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user