mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2025-02-16 04:31:22 +01:00
Reimplemented MissingDependencyException
This commit is contained in:
parent
942d76f989
commit
32d8ceb775
@ -44,6 +44,7 @@ object EcoEnchants : RegistrableCategory<EcoEnchant>("enchant", "enchants") {
|
|||||||
override fun afterReload(plugin: LibreforgePlugin) {
|
override fun afterReload(plugin: LibreforgePlugin) {
|
||||||
plugin as EcoEnchantsPlugin
|
plugin as EcoEnchantsPlugin
|
||||||
|
|
||||||
|
sendPrompts(plugin)
|
||||||
registerHardcodedEnchantments(plugin)
|
registerHardcodedEnchantments(plugin)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,13 +55,17 @@ object EcoEnchants : RegistrableCategory<EcoEnchant>("enchant", "enchants") {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val enchant = LibreforgeEcoEnchant(
|
try {
|
||||||
id,
|
val enchant = LibreforgeEcoEnchant(
|
||||||
config,
|
id,
|
||||||
plugin
|
config,
|
||||||
)
|
plugin
|
||||||
|
)
|
||||||
|
|
||||||
doRegister(plugin, enchant)
|
doRegister(plugin, enchant)
|
||||||
|
} catch (e: MissingDependencyException) {
|
||||||
|
addPluginPrompt(plugin, e.plugins)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun doRegister(plugin: EcoEnchantsPlugin, enchant: EcoEnchant) {
|
private fun doRegister(plugin: EcoEnchantsPlugin, enchant: EcoEnchant) {
|
||||||
|
@ -0,0 +1,34 @@
|
|||||||
|
package com.willfp.ecoenchants.enchant
|
||||||
|
|
||||||
|
import com.willfp.eco.core.EcoPlugin
|
||||||
|
import com.willfp.ecoenchants.EcoEnchantsPlugin
|
||||||
|
|
||||||
|
class MissingDependencyException(
|
||||||
|
val plugins: Set<String>
|
||||||
|
) : Exception() {
|
||||||
|
override val message = "Missing the following plugins: ${plugins.joinToString(", ")}"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Plugin names mapped to enchants that aren't installed.
|
||||||
|
private val prompts = mutableMapOf<String, Int>()
|
||||||
|
|
||||||
|
fun addPluginPrompt(plugin: EcoEnchantsPlugin, plugins: Set<String>) {
|
||||||
|
if (!plugin.isLoaded) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for (pluginName in plugins) {
|
||||||
|
prompts[pluginName] = prompts.getOrDefault(pluginName, 0) + 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun sendPrompts(plugin: EcoPlugin) {
|
||||||
|
for ((pl, amount) in prompts) {
|
||||||
|
plugin.logger.apply {
|
||||||
|
warning("$amount enchantments were not loaded because they need $pl to be installed!")
|
||||||
|
warning("Either download $pl or delete the folder at /plugins/EcoEnchants/enchants/${pl.lowercase()} to remove this message")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
prompts.clear()
|
||||||
|
}
|
@ -1,12 +1,15 @@
|
|||||||
package com.willfp.ecoenchants.enchant.impl
|
package com.willfp.ecoenchants.enchant.impl
|
||||||
|
|
||||||
import com.willfp.eco.core.config.interfaces.Config
|
import com.willfp.eco.core.config.interfaces.Config
|
||||||
|
import com.willfp.eco.util.containsIgnoreCase
|
||||||
import com.willfp.ecoenchants.EcoEnchantsPlugin
|
import com.willfp.ecoenchants.EcoEnchantsPlugin
|
||||||
import com.willfp.ecoenchants.enchant.EcoEnchantLevel
|
import com.willfp.ecoenchants.enchant.EcoEnchantLevel
|
||||||
|
import com.willfp.ecoenchants.enchant.MissingDependencyException
|
||||||
import com.willfp.libreforge.BlankHolder.conditions
|
import com.willfp.libreforge.BlankHolder.conditions
|
||||||
import com.willfp.libreforge.BlankHolder.effects
|
import com.willfp.libreforge.BlankHolder.effects
|
||||||
import com.willfp.libreforge.SilentViolationContext
|
import com.willfp.libreforge.SilentViolationContext
|
||||||
import com.willfp.libreforge.effects.Effects
|
import com.willfp.libreforge.effects.Effects
|
||||||
|
import org.bukkit.Bukkit
|
||||||
|
|
||||||
class LibreforgeEcoEnchant(
|
class LibreforgeEcoEnchant(
|
||||||
id: String,
|
id: String,
|
||||||
@ -21,4 +24,18 @@ class LibreforgeEcoEnchant(
|
|||||||
override fun createLevel(level: Int): EcoEnchantLevel {
|
override fun createLevel(level: Int): EcoEnchantLevel {
|
||||||
return EcoEnchantLevel(this, level, effects, conditions, plugin)
|
return EcoEnchantLevel(this, level, effects, conditions, plugin)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
val missingPlugins = mutableSetOf<String>()
|
||||||
|
|
||||||
|
for (dependency in config.getStrings("dependencies")) {
|
||||||
|
if (!Bukkit.getPluginManager().plugins.map { it.name }.containsIgnoreCase(dependency)) {
|
||||||
|
missingPlugins += dependency
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (missingPlugins.isNotEmpty()) {
|
||||||
|
throw MissingDependencyException(missingPlugins)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user