Skip to content

Commit 9677e8f

Browse files
committed
Support finding subclass
1 parent bee8862 commit 9677e8f

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

  • bukkit/module/bukkit-versions/src/main/kotlin/io/github/rothes/esu/bukkit/util/version

bukkit/module/bukkit-versions/src/main/kotlin/io/github/rothes/esu/bukkit/util/version/Versioned.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ class Versioned<T, V>(
2525
val prefix = target.packageName + ".v"
2626
val find = classes
2727
.filter {
28-
!it.contains('$') // Not subclass!
29-
&& it.startsWith(prefix)
30-
&& it.substringAfterLast('.').startsWith(target.simpleName)
28+
it.startsWith(prefix)
29+
&& it.substringAfterLast('.').substringAfterLast('$').startsWith(target.simpleName)
3130
&& (type == null || it.endsWith(type))
3231
}
3332
.mapNotNull {
@@ -49,7 +48,7 @@ class Versioned<T, V>(
4948

5049
val clazz = Class.forName(find.first)
5150
if (!target.isAssignableFrom(clazz))
52-
error("Found ${clazz.canonicalName}, but it is not an instance of ${target.canonicalName}")
51+
error("Found ${clazz.name}, but it is not an instance of ${target.canonicalName}")
5352

5453
@Suppress("UNCHECKED_CAST")
5554
(clazz.kotlin.objectInstance ?: clazz.getConstructor().newInstance()) as V

0 commit comments

Comments
 (0)