karelpeeters
08/07/2017, 5:27 PMdumptruckman
08/07/2017, 5:33 PMdumptruckman
08/07/2017, 5:34 PMGame
has a PlayerList
and there's no reason to have a separate unrelated PlayerListkarelpeeters
08/07/2017, 5:37 PMPlayerList
isn't simply List<Player>
? It looks like one of those fake types ☺️Ruckus
08/07/2017, 5:40 PM5 + 3
is useless unless you assign it to something.karelpeeters
08/07/2017, 5:40 PMgame.players += myPlayer
.karelpeeters
08/07/2017, 5:41 PMdumptruckman
08/07/2017, 5:45 PMMap<UUID, GamePlayer>
dumptruckman
08/07/2017, 5:45 PMdumptruckman
08/07/2017, 5:45 PMdumptruckman
08/07/2017, 5:45 PMgame.players += gamePlayer
dumptruckman
08/07/2017, 5:47 PMval newPlayerList = game.players + gamePlayer
results in a new PlayerList
object I would never be interested inwouterdoeland
08/07/2017, 6:02 PMkarelpeeters
08/07/2017, 6:03 PM+=
and stop overthinking it ☺️.dumptruckman
08/07/2017, 6:07 PMkarelpeeters
08/07/2017, 6:08 PMwouterdoeland
08/07/2017, 6:09 PMfun getParameters(command: KClass<out SimpleCommand>): List<Pair<KParameter, Argument>> {
val constructor = command.primaryConstructor ?: throw IllegalArgumentException("Command has no primary constructor")
return constructor.parameters.map { it to (it.findAnnotation<Argument>() ?: throw MissingAnnotationException("Found parameter without Argument annotation", Argument::class.qualifiedName)) }.apply {
// check if there are any non-string parameters
forEach {
if(it.second.optional && !it.first.isOptional)
throw IllegalArgumentException("Found parameter that is not optional, but their annotation says it is (add a default value to the parameter '${it.second.name}').")
if(it.first.type != String::class)
throw IllegalArgumentException("Found parameter without String type.")
}
}
}
wouterdoeland
08/07/2017, 6:09 PMwouterdoeland
08/07/2017, 6:09 PMkarelpeeters
08/07/2017, 6:10 PMwouterdoeland
08/07/2017, 6:12 PMwouterdoeland
08/07/2017, 6:12 PMkarelpeeters
08/07/2017, 6:13 PM.type
returns a Type
ans you're comparing that with a class.wouterdoeland
08/07/2017, 6:15 PMwouterdoeland
08/07/2017, 6:15 PMkarelpeeters
08/07/2017, 6:15 PM.type.jvmErasure
and compare the classes or do String::class.createType()
and compare the types.karelpeeters
08/07/2017, 6:16 PMkarelpeeters
08/07/2017, 6:16 PMwouterdoeland
08/07/2017, 6:16 PMwouterdoeland
08/07/2017, 6:17 PM