aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/firmament/commands
diff options
context:
space:
mode:
authornea <nea@nea.moe>2023-06-02 16:43:14 +0200
committernea <nea@nea.moe>2023-06-02 16:43:14 +0200
commitccf1d1d0e97983509b29c276caa058b8c8284a66 (patch)
tree09718e30925fdfc7758668e08a991cdbaf8e447d /src/main/kotlin/moe/nea/firmament/commands
parentadd5eb6a4a1c8228e789f90ca100fc92f12baaea (diff)
downloadFirmament-ccf1d1d0e97983509b29c276caa058b8c8284a66.tar.gz
Firmament-ccf1d1d0e97983509b29c276caa058b8c8284a66.tar.bz2
Firmament-ccf1d1d0e97983509b29c276caa058b8c8284a66.zip
Fix ex MVP++ users being shown as unranked
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/commands')
-rw-r--r--src/main/kotlin/moe/nea/firmament/commands/dsl.kt21
-rw-r--r--src/main/kotlin/moe/nea/firmament/commands/rome.kt6
2 files changed, 24 insertions, 3 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/commands/dsl.kt b/src/main/kotlin/moe/nea/firmament/commands/dsl.kt
index 155e700..90018fa 100644
--- a/src/main/kotlin/moe/nea/firmament/commands/dsl.kt
+++ b/src/main/kotlin/moe/nea/firmament/commands/dsl.kt
@@ -25,6 +25,8 @@ import com.mojang.brigadier.builder.RequiredArgumentBuilder
import com.mojang.brigadier.context.CommandContext
import com.mojang.brigadier.suggestion.SuggestionProvider
import java.lang.reflect.ParameterizedType
+import java.lang.reflect.Type
+import java.lang.reflect.TypeVariable
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource
import moe.nea.firmament.util.iterate
@@ -43,18 +45,31 @@ fun literal(
): LiteralArgumentBuilder<DefaultSource> =
LiteralArgumentBuilder.literal<DefaultSource>(name).also(block)
+
+private fun normalizeGeneric(argument: Type): Class<*> {
+ return if (argument is Class<*>) {
+ argument
+ } else if (argument is TypeVariable<*>) {
+ normalizeGeneric(argument.bounds[0])
+ } else if (argument is ParameterizedType) {
+ normalizeGeneric(argument.rawType)
+ } else {
+ Any::class.java
+ }
+}
+
data class TypeSafeArg<T : Any>(val name: String, val argument: ArgumentType<T>) {
val argClass by lazy {
argument.javaClass
.iterate<Class<in ArgumentType<T>>> {
it.superclass
}
- .map {
- it.genericSuperclass
+ .flatMap {
+ it.genericInterfaces.toList()
}
.filterIsInstance<ParameterizedType>()
.find { it.rawType == ArgumentType::class.java }!!
- .let { it.actualTypeArguments[0] as Class<*> }
+ .let { normalizeGeneric(it.actualTypeArguments[0]) }
}
@JvmName("getWithThis")
diff --git a/src/main/kotlin/moe/nea/firmament/commands/rome.kt b/src/main/kotlin/moe/nea/firmament/commands/rome.kt
index 9c47fd2..2baf076 100644
--- a/src/main/kotlin/moe/nea/firmament/commands/rome.kt
+++ b/src/main/kotlin/moe/nea/firmament/commands/rome.kt
@@ -59,6 +59,12 @@ fun firmamentCommand() = literal("firmament") {
thenExecute {
ProfileViewer.onCommand(source, MC.player!!.name.unformattedString)
}
+ thenArgument("name", string()) { name ->
+ suggestsList { MC.world?.players?.map { it.name.unformattedString } ?: listOf() }
+ thenExecute {
+ ProfileViewer.onCommand(source, get(name))
+ }
+ }
}
thenLiteral("price") {
thenArgument("item", string()) { item ->