@@ -11,55 +11,45 @@ import kotlin.reflect.KProperty
11
11
* otherwise, returns null
12
12
*/
13
13
public inline fun <reified T : Plugin > KotlinPlugin.softDepend (
14
- pluginName : String
14
+ pluginName : String ,
15
15
): SoftDependencyDelegate <T > = softDepend(T ::class , pluginName)
16
16
17
17
public fun <T : Plugin > KotlinPlugin.softDepend (
18
18
type : KClass <T >,
19
- pluginName : String
19
+ pluginName : String ,
20
20
): SoftDependencyDelegate <T > =
21
21
SoftDependencyDelegate (
22
22
pluginName,
23
- type
23
+ type,
24
24
)
25
25
26
26
/* *
27
27
* Delegate that returns the plugin dependency, disable the plugin if the plugin
28
28
* is not available.
29
29
*/
30
30
public inline fun <reified T : Plugin > KotlinPlugin.depend (
31
- pluginName : String
31
+ pluginName : String ,
32
32
): DependencyDelegate <T > = depend(T ::class , pluginName)
33
33
34
34
public fun <T : Plugin > KotlinPlugin.depend (
35
35
type : KClass <T >,
36
- pluginName : String
36
+ pluginName : String ,
37
37
): DependencyDelegate <T > =
38
38
DependencyDelegate (pluginName, type)
39
39
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
-
48
-
49
-
50
40
public class DependencyDelegate <T : Plugin >(
51
41
public val pluginName : String ,
52
- public val type : KClass <T >
42
+ public val type : KClass <T >,
53
43
) : ReadOnlyProperty<KotlinPlugin, T> {
54
44
55
45
private var isDisabled: Boolean = false
56
46
private var cache: T ? = null
57
47
58
48
override fun getValue (
59
49
thisRef : KotlinPlugin ,
60
- property : KProperty <* >
50
+ property : KProperty <* >,
61
51
): T {
62
- if (cache == null ) {
52
+ if (cache == null ) {
63
53
val plugin = thisRef.server.pluginManager.getPlugin(pluginName)
64
54
65
55
if (plugin != null ) {
@@ -69,7 +59,7 @@ public class DependencyDelegate<T : Plugin>(
69
59
thisRef.server.pluginManager.disablePlugin(thisRef)
70
60
error(
71
61
" Invalid plugin dependency with the name $pluginName : " +
72
- " The plugin do not match main class with ${type.qualifiedName} ."
62
+ " The plugin do not match main class with ${type.qualifiedName} ." ,
73
63
)
74
64
}
75
65
} else {
@@ -84,17 +74,17 @@ public class DependencyDelegate<T : Plugin>(
84
74
85
75
public class SoftDependencyDelegate <T : Plugin >(
86
76
public val pluginName : String ,
87
- public val type : KClass <T >
77
+ public val type : KClass <T >,
88
78
) : ReadOnlyProperty<KotlinPlugin, T?> {
89
79
90
80
private var alreadySearch: Boolean = false
91
81
private var cache: T ? = null
92
82
93
83
override fun getValue (
94
84
thisRef : KotlinPlugin ,
95
- property : KProperty <* >
85
+ property : KProperty <* >,
96
86
): T ? {
97
- if (! alreadySearch) {
87
+ if (! alreadySearch) {
98
88
val plugin = thisRef.server.pluginManager.getPlugin(pluginName) ? : return null
99
89
100
90
alreadySearch = true
@@ -105,12 +95,11 @@ public class SoftDependencyDelegate<T : Plugin>(
105
95
thisRef.server.pluginManager.disablePlugin(thisRef)
106
96
error(
107
97
" Invalid plugin dependency with the name $pluginName : " +
108
- " The plugin do not match main class with ${type.qualifiedName} ."
98
+ " The plugin do not match main class with ${type.qualifiedName} ." ,
109
99
)
110
100
}
111
101
}
112
102
113
103
return cache
114
104
}
115
105
}
116
-
0 commit comments