You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -35,92 +29,26 @@ fun FeatureDI.listeners(vararg listeners: Listener) {
35
29
}
36
30
}
37
31
38
-
39
-
fun FeatureBuilder.FeatureDependenciesBuilder.plugins(varargnames:String) {
40
-
condition {
41
-
val notEnabled = names.filterNot { Plugins.isEnabled(it) }
42
-
require(notEnabled.isEmpty()) { "Plugin dependencies not found: $notEnabled" }
43
-
}
32
+
funrequirePlugins(varargnames:String) {
33
+
val notEnabled = names.filterNot { Plugins.isEnabled(it) }
34
+
require(notEnabled.isEmpty()) { "Plugin dependencies not found $notEnabled" }
44
35
}
45
36
46
-
funFeatureDI.task(job:Job) {
47
-
val scope =instance<CoroutineScope>()
37
+
funMutableDI.task(job:Job) {
38
+
val scope =get<CoroutineScope>()
48
39
scope.launch { job.join() }
49
40
}
50
41
51
-
data classDICommandContext(valmanager:FeatureManager, valfeature:Feature<*>)
52
-
53
-
context(di:DICommandContext)
54
-
inlinefun <reifiedT : Any> IdoCommandContext.get(): T= di.manager.getInstance(di.feature)?.di?.direct?.instance<T>() ?: error("Command tried to get feature config of an unloaded feature: ${di.feature.name}.")
55
-
56
-
fun FeatureBuilder.commands(block: context(DICommandContext) RootIdoCommands.() ->Unit) {
57
-
onLoad {
58
-
val context =DICommandContext(instance(), instance())
59
-
instance<Plugin>().commands {
60
-
block(context, this)
61
-
}
62
-
}
63
-
}
64
-
65
-
valMainCommandFeature= feature("Main Command") {
66
-
onLoad {
67
-
plugin.commands {
68
-
val main = get<MainCommand>()
69
-
val manager = get<FeatureManager>()
70
-
main.names.invoke {
71
-
description = main.description
72
-
permission = main.permission
73
-
main.subcommands.forEach { subcommand ->
74
-
val feature = manager.getNamed(subcommand.featureName) ?: error("Feature name not found: ${subcommand.featureName}")
75
-
val context =DICommandContext(manager, feature)
76
-
subcommand.create(context, this)
77
-
}
78
-
79
-
if (main.reloadCommandName !=null) {
80
-
main.reloadCommandName {
81
-
permission = main.reloadCommandPermission
82
-
83
-
executes {
84
-
manager.reloadAll()
85
-
}
86
-
87
-
executes.args(
88
-
"feature" to Args.string().oneOf { manager.loaded.map { it.name }.toList() }
89
-
) { featureName ->
90
-
if (manager.reload(manager.getNamed(featureName) ?: fail("Feature $featureName not found"))) {
91
-
sender.success("Reloaded feature $featureName")
92
-
} else {
93
-
sender.error("Failed to reload feature $featureName")
94
-
}
95
-
}
96
-
}
97
-
}
98
-
}
99
-
}
100
-
}
101
-
}
102
-
103
-
fun FeatureBuilder.mainCommand(block: context(DICommandContext) IdoRootCommand.() ->Unit) {
104
-
onLoad {
105
-
instance<MainCommand>().subcommand(name, block)
106
-
}
107
-
}
42
+
//fun MutableDI.commands(block: context(DICommandContext) RootIdoCommands.() -> Unit) = once {
* For more complicated config use-cases (ex. reading a directory), use [com.mineinabyss.idofront.config.ConfigBuilder] and manually inject via a context class.
0 commit comments