diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/EcoEnchantsPlugin.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/EcoEnchantsPlugin.kt index 817edbe6..362c750e 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/EcoEnchantsPlugin.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/EcoEnchantsPlugin.kt @@ -12,12 +12,6 @@ import com.willfp.ecoenchants.config.VanillaEnchantsYml import com.willfp.ecoenchants.display.EnchantDisplay import com.willfp.ecoenchants.enchants.EcoEnchants import com.willfp.ecoenchants.enchants.LoreConversion -import com.willfp.ecoenchants.enchants.impl.EnchantmentPermanenceCurse -import com.willfp.ecoenchants.enchants.impl.EnchantmentRapid -import com.willfp.ecoenchants.enchants.impl.EnchantmentRepairing -import com.willfp.ecoenchants.enchants.impl.EnchantmentReplenish -import com.willfp.ecoenchants.enchants.impl.EnchantmentSoulbound -import com.willfp.ecoenchants.enchants.impl.EnchantmentTelekinesis import com.willfp.ecoenchants.enchants.registerVanillaEnchants import com.willfp.ecoenchants.integrations.EnchantRegistrations import com.willfp.ecoenchants.integrations.plugins.CMIIntegration @@ -37,6 +31,8 @@ class EcoEnchantsPlugin : LibReforgePlugin() { val rarityYml = RarityYml(this) val typesYml = TypesYml(this) val vanillaEnchantsYml = VanillaEnchantsYml(this) + var isLoaded = false + private set init { instance = this @@ -48,6 +44,10 @@ class EcoEnchantsPlugin : LibReforgePlugin() { registerHolderProvider { it.heldEnchantLevels } } + override fun handleAfterLoad() { + isLoaded = true + } + override fun handleReloadAdditional() { registerVanillaEnchants(this) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/EcoEnchant.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/EcoEnchant.kt index e67eb3d5..5bb16820 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/EcoEnchant.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/EcoEnchant.kt @@ -108,6 +108,8 @@ abstract class EcoEnchant( ) init { + checkDependencies() + config.injectPlaceholders( PlayerStaticPlaceholder( "level" @@ -116,9 +118,9 @@ abstract class EcoEnchant( } ) - conditions = config.getSubsections("conditions").mapNotNull { + conditions = if (plugin.isLoaded) config.getSubsections("conditions").mapNotNull { Conditions.compile(it, "Enchantment $id") - }.toSet() + }.toSet() else emptySet() if (Bukkit.getPluginManager().getPermission("ecoenchants.fromtable.$id") == null) { val permission = Permission( @@ -155,6 +157,21 @@ abstract class EcoEnchant( } } + private fun checkDependencies() { + val missingPlugins = mutableListOf() + + for (dependency in config.getStrings("dependencies")) { + if (!Bukkit.getPluginManager().plugins.map { it.name }.containsIgnoreCase(dependency)) { + missingPlugins += dependency + } + } + + if (missingPlugins.isNotEmpty()) { + config.set("dont-register", true) // Just in case. + throw MissingDependencyException(missingPlugins) + } + } + private fun doOnInit() { onInit() } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/EcoEnchants.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/EcoEnchants.kt index b9469e9b..5a8801c9 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/EcoEnchants.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/EcoEnchants.kt @@ -100,7 +100,15 @@ object EcoEnchants { for ((id, config) in plugin.fetchConfigs("enchants")) { if (config.has("effects")) { - LibReforgeEcoEnchant(id, config, plugin) + try { + LibReforgeEcoEnchant( + id, + config, + plugin + ) + } catch (e: MissingDependencyException) { + promptPluginInstall(plugin, id, e.plugins.toMutableList()) + } } } @@ -170,7 +178,9 @@ object EcoEnchants { } /** Register the hardcoded enchantments. */ - private fun registerHardcodedEnchantments(plugin: EcoEnchantsPlugin) { + private fun registerHardcodedEnchantments( + plugin: EcoEnchantsPlugin + ) { EnchantmentTelekinesis(plugin) EnchantmentPermanenceCurse(plugin) EnchantmentRepairing(plugin) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/LibReforgeEcoEnchant.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/LibReforgeEcoEnchant.kt index ee81a940..f41ebab4 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/LibReforgeEcoEnchant.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/LibReforgeEcoEnchant.kt @@ -6,7 +6,7 @@ import com.willfp.libreforge.Holder import com.willfp.libreforge.conditions.ConfiguredCondition import com.willfp.libreforge.effects.ConfiguredEffect import com.willfp.libreforge.effects.Effects -import java.util.* +import java.util.Objects class LibReforgeEcoEnchant( id: String, @@ -20,9 +20,9 @@ class LibReforgeEcoEnchant( private val effects: Set init { - effects = config.getSubsections("effects").mapNotNull { + effects = if (plugin.isLoaded) config.getSubsections("effects").mapNotNull { Effects.compile(it, "Enchantment $id") - }.toSet() + }.toSet() else emptySet() } override fun createLevel(level: Int): EcoEnchantLevel = diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/MissingDependencyException.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/MissingDependencyException.kt new file mode 100644 index 00000000..a9bdd7d6 --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/MissingDependencyException.kt @@ -0,0 +1,35 @@ +package com.willfp.ecoenchants.enchants + +import com.willfp.ecoenchants.EcoEnchantsPlugin + +class MissingDependencyException( + val plugins: List +) : Exception() { + override val message = "Missing the following plugins: ${plugins.joinToString(", ")}" +} + +fun promptPluginInstall(plugin: EcoEnchantsPlugin, enchant: String, plugins: MutableList) { + if (!plugin.isLoaded) { + return + } + + val formatted = StringBuilder() + + when (plugins.size) { + 1 -> formatted.append(plugins.first()) + 2 -> formatted.append(plugins[0]) + .append(" and ") + .append(plugins[1]) + else -> { + val last = plugins.removeLast() + formatted.append(plugins.joinToString(", ")) + .append(", and ") + .append(last) + } + } + + plugin.logger.apply { + warning("Can't load the $enchant enchantment because you need $formatted installed") + warning("Either download $formatted or delete the folders with their names (/plugins/EcoEnchants/enchants/) to remove this message!") + } +} diff --git a/eco-core/core-plugin/src/main/resources/enchants/adrenaline.yml b/eco-core/core-plugin/src/main/resources/enchants/adrenaline.yml new file mode 100644 index 00000000..217b8ccc --- /dev/null +++ b/eco-core/core-plugin/src/main/resources/enchants/adrenaline.yml @@ -0,0 +1,27 @@ +display-name: "Adrenaline" +description: "Gain strength for &a%placeholder%&r seconds when blocking hits" +placeholder: "1 + %level% / 2" +type: normal + +targets: + - shield +conflicts: [ ] +rarity: epic +max-level: 3 + +tradeable: true +discoverable: true +enchantable: true + +effects: + - id: potion_effect + args: + effect: increase_damage + level: 2 + duration: "20 + 10 * %level%" + apply-to-player: true + cooldown: 10 + triggers: + - shield_block + +conditions: [ ] diff --git a/eco-core/core-plugin/src/main/resources/enchants/caffeinated.yml b/eco-core/core-plugin/src/main/resources/enchants/caffeinated.yml new file mode 100644 index 00000000..179ecbf3 --- /dev/null +++ b/eco-core/core-plugin/src/main/resources/enchants/caffeinated.yml @@ -0,0 +1,23 @@ +display-name: "Caffeinated" +description: "Gives a &a%placeholder%%&r bonus to attack speed while sprinting" +placeholder: "5 * %level%" +type: normal + +targets: + - sword +conflicts: [ ] +rarity: rare +max-level: 3 + +tradeable: true +discoverable: true +enchantable: true + +effects: + - id: attack_speed_multiplier + args: + multiplier: "1 + %level% * 0.05" + triggers: [ ] + +conditions: + - id: is_sprinting diff --git a/eco-core/core-plugin/src/main/resources/enchants/contagion.yml b/eco-core/core-plugin/src/main/resources/enchants/contagion.yml new file mode 100644 index 00000000..97104922 --- /dev/null +++ b/eco-core/core-plugin/src/main/resources/enchants/contagion.yml @@ -0,0 +1,33 @@ +display-name: "Contagion" +description: "Gives a &a%placeholder%%&r chance to spawn a cloud of poison around where your trident lands" +placeholder: "5 * %level%" +type: special + +targets: + - trident +conflicts: [ ] +rarity: legendary +max-level: 2 + +tradeable: true +discoverable: true +enchantable: true + +effects: + - id: spawn_potion_cloud + args: + effect: poison + level: 1 + duration: 60 + triggers: + - projectile_hit + + - id: play_sound + args: + sound: entity_splash_potion_break + pitch: 0.7 + volume: 1 + triggers: + - projectile_hit + +conditions: [ ] diff --git a/eco-core/core-plugin/src/main/resources/enchants/ecoskills/stimulating.yml b/eco-core/core-plugin/src/main/resources/enchants/ecoskills/stimulating.yml new file mode 100644 index 00000000..e355a9c7 --- /dev/null +++ b/eco-core/core-plugin/src/main/resources/enchants/ecoskills/stimulating.yml @@ -0,0 +1,44 @@ +display-name: "Stimulating" +description: "Gives a &a%bonus%%&r to all stats for &a%seconds%%&r seconds" +placeholders: + bonus: "10 * %level%" + seconds: "3 * %level%" +type: spell + +targets: + - sword +conflicts: [ ] +rarity: legendary +max-level: 2 + +tradeable: true +discoverable: true +enchantable: true + +effects: + - effects: + - id: add_holder + args: + effects: + - id: multiply_all_stats + args: + multiplier: "1 + 0.1 * %level%" + conditions: [ ] + duration: "3 * %level% * 20" + + - id: play_sound + args: + sound: entity_allay_death + pitch: 1.2 + volume: 1 + + args: + cooldown: 180 + send_cooldown_message: true + triggers: + - alt_click + +conditions: [ ] + +dependencies: + - EcoSkills \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/resources/enchants/ecoskills/vicious.yml b/eco-core/core-plugin/src/main/resources/enchants/ecoskills/vicious.yml new file mode 100644 index 00000000..44888a21 --- /dev/null +++ b/eco-core/core-plugin/src/main/resources/enchants/ecoskills/vicious.yml @@ -0,0 +1,27 @@ +display-name: "Vicious" +description: "Gives &a+%placeholder%&r %ecoskills_ferocity_name%" +placeholder: "5 + 5 * %level%" +type: spell + +targets: + - sword +conflicts: [ ] +rarity: epic +max-level: 3 + +tradeable: true +discoverable: true +enchantable: true + +effects: + - id: add_stat + args: + stat: ferocity + amount: "5 + 5 * %level%" + triggers: + - alt_click + +conditions: [ ] + +dependencies: + - EcoSkills \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/resources/enchants/escape.yml b/eco-core/core-plugin/src/main/resources/enchants/escape.yml new file mode 100644 index 00000000..79b46d7a --- /dev/null +++ b/eco-core/core-plugin/src/main/resources/enchants/escape.yml @@ -0,0 +1,27 @@ +display-name: "Escape" +description: "Gain a short burst of speed &a%placeholder%%&r after taking damage" +placeholder: "%level%" +type: normal + +targets: + - boots +conflicts: + - streamlining +rarity: epic +max-level: 2 + +tradeable: true +discoverable: true +enchantable: true + +effects: + - id: potion_effect + args: + effect: speed + level: "%level%" + duration: 30 + apply_to_player: true + triggers: + - take_entity_damage + +conditions: [ ] diff --git a/eco-core/core-plugin/src/main/resources/enchants/getaway.yml b/eco-core/core-plugin/src/main/resources/enchants/getaway.yml new file mode 100644 index 00000000..8a7b326d --- /dev/null +++ b/eco-core/core-plugin/src/main/resources/enchants/getaway.yml @@ -0,0 +1,25 @@ +display-name: "Getaway" +description: "Gain a &a%placeholder%%&r bonus to movement speed below &a20%&r health" +placeholder: "%level%" +type: normal + +targets: + - boots +conflicts: [ ] +rarity: rare +max-level: 2 + +tradeable: true +discoverable: true +enchantable: true + +effects: + - id: movement_speed_multiplier + args: + multiplier: "1 + 0.1 * %level%" + triggers: [ ] + +conditions: + - id: below_health_percent + args: + percent: 20 diff --git a/eco-core/core-plugin/src/main/resources/enchants/haunting.yml b/eco-core/core-plugin/src/main/resources/enchants/haunting.yml new file mode 100644 index 00000000..3b325bbe --- /dev/null +++ b/eco-core/core-plugin/src/main/resources/enchants/haunting.yml @@ -0,0 +1,25 @@ +display-name: "Haunting" +description: "Dying spawns a harming cloud for &a%placeholder%&r seconds" +placeholder: "1 + %level%" +type: normal + +targets: + - helmet +conflicts: [ ] +rarity: epic +max-level: 2 + +tradeable: true +discoverable: true +enchantable: true + +effects: + - id: spawn_potion_cloud + args: + effect: harm + level: 1 + duration: "20 + %level% * 20" + triggers: + - death + +conditions: [ ] diff --git a/eco-core/core-plugin/src/main/resources/enchants/ninja.yml b/eco-core/core-plugin/src/main/resources/enchants/ninja.yml new file mode 100644 index 00000000..9bf1114f --- /dev/null +++ b/eco-core/core-plugin/src/main/resources/enchants/ninja.yml @@ -0,0 +1,26 @@ +display-name: "Ninja" +description: "Deal &a+%placeholder%&r damage while sneaking" +placeholder: "0.5 + %level% * 0.5" +type: normal + +targets: + - sword +conflicts: [ ] +rarity: rare +max-level: 5 + +tradeable: true +discoverable: true +enchantable: true + +effects: + - id: add_damage + args: + damage: "0.5 + %level% * 0.5" + triggers: + - melee_attack + +conditions: + - id: is_sneaking + args: + is_sneaking: true diff --git a/eco-core/core-plugin/src/main/resources/enchants/posion_ivy.yml b/eco-core/core-plugin/src/main/resources/enchants/posion_ivy.yml new file mode 100644 index 00000000..80b80a22 --- /dev/null +++ b/eco-core/core-plugin/src/main/resources/enchants/posion_ivy.yml @@ -0,0 +1,30 @@ +display-name: "Poison Ivy" +description: "Poisons attackers for &a%seconds%&r seconds for each heart of damage dealt, up to &a%limit%&r seconds" +placeholders: + seconds: "0.5 * %level%" + limit: "4 + %level%" +type: normal + +targets: + - leggings +conflicts: + - thorns +rarity: epic +max-level: 2 + +tradeable: true +discoverable: true +enchantable: true + +effects: + - id: potion_effect + args: + effect: poison + level: 1 + duration: "min(10 * %level% * %v% / 2, 80 + %level% * 20 * %v% / 2)" + apply_to_player: false + + triggers: + - take_entity_damage + +conditions: [ ] diff --git a/eco-core/core-plugin/src/main/resources/enchants/rebounding.yml b/eco-core/core-plugin/src/main/resources/enchants/rebounding.yml new file mode 100644 index 00000000..6f059b38 --- /dev/null +++ b/eco-core/core-plugin/src/main/resources/enchants/rebounding.yml @@ -0,0 +1,23 @@ +display-name: "Rebounding" +description: "Rebounds &a%placeholder%%&r of incoming damage back at your attacker" +placeholder: "20 + %level% * 10" +type: normal + +targets: + - shield +conflicts: [ ] +rarity: epic +max-level: 3 + +tradeable: true +discoverable: true +enchantable: true + +effects: + - id: damage_victim + args: + damage: "%v% * (0.2 + %level% * 0.1)" + triggers: + - shield_block + +conditions: [ ] diff --git a/eco-core/core-plugin/src/main/resources/enchants/shura.yml b/eco-core/core-plugin/src/main/resources/enchants/shura.yml new file mode 100644 index 00000000..213627f5 --- /dev/null +++ b/eco-core/core-plugin/src/main/resources/enchants/shura.yml @@ -0,0 +1,26 @@ +display-name: "Shura" +description: "Gives a &a%placeholder%x&r bonus to critical damage when under half health" +placeholder: "1 + 0.25 * %level%" +type: normal + +targets: + - axe +conflicts: [ ] +rarity: rare +max-level: 2 + +tradeable: true +discoverable: true +enchantable: true + +effects: + - id: crit_multiplier + args: + multiplier: "1 + 0.25 * %level%" + triggers: + - melee_attack + +conditions: + - id: below_health_percent + args: + percent: 51 diff --git a/eco-core/core-plugin/src/main/resources/enchants/warp_drive.yml b/eco-core/core-plugin/src/main/resources/enchants/warp_drive.yml new file mode 100644 index 00000000..86b80523 --- /dev/null +++ b/eco-core/core-plugin/src/main/resources/enchants/warp_drive.yml @@ -0,0 +1,24 @@ +display-name: "Warp Drive" +description: "Hitting your opponent with an arrow teleports you to them" +placeholder: "%level%" +type: special + +targets: + - bow +conflicts: [ ] +rarity: veryspecial +max-level: 1 + +tradeable: true +discoverable: true +enchantable: true + +effects: + - id: teleport + triggers: + - bow_attack + +conditions: [ ] + +mutators: + - id: location_to_victim \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/resources/enchants/wyvern.yml b/eco-core/core-plugin/src/main/resources/enchants/wyvern.yml new file mode 100644 index 00000000..357a15e8 --- /dev/null +++ b/eco-core/core-plugin/src/main/resources/enchants/wyvern.yml @@ -0,0 +1,23 @@ +display-name: "Wyvern" +description: "Gives a &a%placeholder%%&r bonus to melee damage" +placeholder: "10 * %level%" +type: normal + +targets: + - elytra +conflicts: [ ] +rarity: epic +max-level: 2 + +tradeable: true +discoverable: true +enchantable: true + +effects: + - id: damage_multiplier + args: + multiplier: "1 + (0.15 * %level%)" + triggers: + - melee_attack + +conditions: [ ]